Answer to Question #326065 in C++ for Prince

Question #326065

Write a C++ program for a lecturer to convert all his (5 students) student marks to 

a percentage. Enter the total mark of the test, and then enter for each student his 

student number, and the mark obtained by the student. Display the student number, 

percentage, and status indicating whether the student passed (50% or more) or failed 

the test.

Include the following function and sub procedures (as shown in the table below):

LectureApp

NO METHOD NAME DESCRIPTION MARK

1 main This function prompts for the total and 

also invokes the required procedures to 

display the results.

7

2 getData This sub procedure prompts for the 

student number and mark obtained by the 

student from the end-user.

4

3 determinePercentage This function returns the mark obtained in

percentage.

4

4 determineStatus This function returns true if the student 

passed or false, otherwise.

6

5 printOutput This sub procedure displays the output as 

shown in the sample output.

4


1
Expert's answer
2022-04-08T16:06:02-0400
#include <iostream>
#include <iomanip>
using namespace std;


void getData(int& number, int& mark);
int determinePercentage(int mark, int total);
bool determineStatus(int percentage);
void printOutput(int student_numbers[], int percentage[], bool pass[]);


int main()
{
    int total;
    int student_numbers[5];
    int percentage[5];
    bool pass[5];
    cout << "Enter the total mark of the test: ";
    cin >> total;
    
    for (int i=0; i<5; i++) {
        int mark;
        getData(student_numbers[i], mark);
        percentage[i] = determinePercentage(mark, total);
        pass[i] = determineStatus(percentage[i]);
    }
    printOutput(student_numbers, percentage, pass);


    return 0;
}


void getData(int& number, int& mark)
{
    cout << "Enter a student number: ";
    cin >> number;


    cout << "Enter the student mark: ";
    cin >> mark;
}


int determinePercentage(int mark, int total) 
{
    return (mark * 100) / total;
}


bool determineStatus(int percentage) 
{
    return percentage >= 50;
}


void printOutput(int student_numbers[], int percentage[], bool pass[]) 
{
    cout << "number  percenage   pass" << endl;
    for (int i=0; i<5; i++) {
        cout << setw(6) << student_numbers[i] 
             << setw(10) << percentage[i] << "%   "
             << (pass[i] ? "pass" : "fail") << endl;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS