Question
1. How do I fix the following code to print the mark per subject with it's corresponding symbol and code on separate lines? 2. How
1. How do I fix the following code to print the mark per subject with it's corresponding symbol and code on separate lines?
2. How do i fix the code to print distinction details per subject?
3. How do I create a function to display the output data?
4. How can I neaten / shorten the code?
#include
using namespace std;
void studentDetails(string & nameP, string & surnameP, string & schoolNameP)
{
cout << "Enter name: ";
cin >> nameP;
cout << "Enter surname: ";
cin >> surnameP;
cout << "Enter the name of the school: ";
cin >> schoolNameP;
}
void getMarks(float & engP, float & mathP, float & life_orientP, float & histP, float & comp_litP, float & artP)
{
cout << "Enter your mark for English: ";
cin >> engP;
if (engP < 0 || engP > 100)
do
{
cout << "Value cannot be less than 0 or greater than 100. Enter again: ";
cin >> engP;
} while (engP < 0 || engP > 100);
cout << "Enter your mark for Mathematics: ";
cin >> mathP;
if (mathP < 0 || mathP > 100)
do
{
cout << "Value cannot be less than 0 or greater than 100. Enter again: ";
cin >> mathP;
} while (mathP < 0 || mathP > 100);
cout << "Enter your mark for Life Orientation: ";
cin >> life_orientP;
if (life_orientP < 0 || life_orientP > 100)
do
{
cout << "Value cannot be less than 0 or greater than 100. Enter again: ";
cin >> life_orientP;
} while (life_orientP < 0 || life_orientP > 100);
cout << "Enter your mark for History: ";
cin >> histP;
if (histP < 0 || histP > 100)
do
{
cout << "Value cannot be less than 0 or greater than 100. Enter again: ";
cin >> histP;
} while (histP < 0 || histP > 100);
cout << "Enter your mark for Computer Literacy: ";
cin >> comp_litP;
if (comp_litP < 0 || comp_litP > 100)
do
{
cout << "Value cannot be less than 0 or greater than 100. Enter again: ";
cin >> comp_litP;
} while (comp_litP < 0 || comp_litP > 100);
cout << "Enter your mark for Art: ";
cin >> artP;
if (artP < 0 || artP > 100)
do
{
cout << "Value cannot be less than 0 or greater than 100. Enter again: ";
cin >> artP;
} while (artP < 0 || artP > 100);
}
float calcAverageYearMark(float engP, float mathP, float life_orientP, float histP, float comp_litP, float artP)
{
return (engP + mathP + life_orientP + histP + comp_litP + artP) / 6;
}
float minMax(float & engP, float & mathP, float & life_orientP, float & histP, float & comp_litP, float & artP, float & minimumP, float & maximumP)
{
float min1 = min(engP, mathP);
float max1 = max(engP,mathP);
float min2 = min(min1, life_orientP);
float max2 = max(max1, life_orientP);
float min3 = min(min2, histP);
float max3 = max(max2, histP);
float min4 = min(min3, comp_litP);
float max4 = max(max3, comp_litP);
float min5 = min(min4, artP);
float max5 = max(max4, artP);
minimumP = min5;
maximumP = max5;
}
void passOrFail(float & engP, float & mathP, float & life_orientP, float & histP, float & comp_litP, float & artP, string & outcomeP)
{
if (engP < 50)
{
outcomeP = "Failed";
}
else if (engP >= 50 && mathP >= 50 && life_orientP >= 50 && comp_litP >= 50)
{
outcomeP = "Passed";
}
else if (engP >= 50 && mathP >= 50 && life_orientP >= 50 && histP >= 50)
{
outcomeP = "Passed";
}
else if (engP >= 50 && mathP >= 50 && comp_litP >= 50 && histP >= 50)
{
outcomeP = "Passed";
}
else if (engP >= 50 && mathP >= 50 && life_orientP >= 50 && artP >= 50)
{
outcomeP = "Passed";
}
else if (engP >= 50 && mathP >= 50 && comp_litP >= 50 && artP >= 50)
{
outcomeP = "Passed";
}
else if (engP >= 50 && mathP >= 50 && histP >= 50 && artP >= 50)
{
outcomeP = "Passed";
}
else if (engP >= 50 && life_orientP >= 50 && comp_litP >= 50 && histP >= 50)
{
outcomeP = "Passed";
}
else if (engP >= 50 && life_orientP >= 50 && comp_litP >= 50 && artP >= 50)
{
outcomeP = "Passed";
}
else if (engP >= 50 && life_orientP >= 50 && histP >= 50 && artP >= 50)
{
outcomeP = "Passed";
}
else if (engP >= 50 && comp_litP >= 50 && histP >= 50 && artP >= 50)
{
outcomeP = "Passed";
}
else
{
outcomeP = "Failed";
}
return;
}
void awardDistinction(float & engP, float & mathP, float & life_orientP, float & histP, float & comp_litP, float & artP)
{
if ((engP + mathP + life_orientP + histP + comp_litP + artP) / 6 >= 75)
{
cout << "Passed with distinction" << endl;
}
else if (engP >= 75)
{
cout << "Subject distinction = English" << endl;
}
else if (mathP >= 75)
{
cout << "Subject distinction = Mathematics" << endl;
}
else if (life_orientP >= 75)
{
cout << "Subject distinction = Life Orientation" << endl;
}
else if (histP >= 75)
{
cout << "Subject distinction = History" << endl;
}
else if (comp_litP >= 75)
{
cout << "Subject distinction = Computer Literacy" << endl;
}
else if (artP >= 75)
{
cout << "Subject distinction = Art" << endl;
}
return;
}
void codeSymbol(float & engP, float & mathP, float & life_orientP, float & histP, float & comp_litP, float & artP, float & averageP, string & symbolP, int & codeP)
{
averageP = (engP + mathP + life_orientP + histP + comp_litP + artP) / 6;
if (engP >= 0 && engP <= 29 || mathP >= 0 && mathP <= 29 || life_orientP >= 0 && life_orientP <= 29 ||
histP >= 0 && histP <= 29 || comp_litP >= 0 && comp_litP <= 29 || artP >= 0 && artP <= 29 || averageP >= 0 && averageP <= 29)
{
symbolP = "FF";
codeP = 1;
cout << engP << '\t' << symbolP << '\t' << codeP << endl;
}
else if (engP >= 30 && engP <= 39 || mathP >= 30 && mathP <= 39 || life_orientP >= 30 && life_orientP <= 39 ||
histP >= 30 && histP <= 39 || comp_litP >= 30 && comp_litP <= 39 || artP >= 30 && artP <= 39 || averageP >= 30 && averageP <= 39)
{
symbolP = "F";
codeP = 2;
}
else if (engP >= 40 && engP <= 49 || mathP >= 40 && mathP <= 49 || life_orientP >= 40 && life_orientP <= 49 ||
histP >= 40 && histP <= 49 || comp_litP >= 40 && comp_litP <= 49 || artP >= 40 && artP <= 49 || averageP >= 40 && averageP <= 49)
{
symbolP = "E";
codeP = 3;
}
else if (engP >= 50 && engP <= 59 || mathP >= 50 && mathP <= 59 || life_orientP >= 50 && life_orientP <= 59 ||
histP >= 50 && histP <= 59 || comp_litP >= 50 && comp_litP <= 59 || artP >= 50 && artP <= 59 || averageP >= 50 && averageP <= 59)
{
symbolP = "D";
codeP = 4;
}
else if (engP >= 60 && engP <= 69 || mathP >= 60 && mathP <= 69 || life_orientP >= 60 && life_orientP <= 69 ||
histP >= 60 && histP <= 69 || comp_litP >= 60 && comp_litP <= 69 || artP >= 60 && artP <= 69 || averageP >= 60 && averageP <= 69)
{
symbolP = "C";
codeP = 5;
}
else if (engP >= 70 && engP <= 79 || mathP >= 70 && mathP <= 79 || life_orientP >= 70 && life_orientP <= 79 ||
histP >= 70 && histP <= 79 || comp_litP >= 70 && comp_litP <= 79 || artP >= 70 && artP <= 79 || averageP >= 70 && averageP <= 79)
{
symbolP = "B";
codeP = 6;
}
else if (engP >= 80 && engP <= 100 || mathP >= 80 && mathP <= 100 || life_orientP >= 80 && life_orientP <= 100 ||
histP >= 80 && histP <= 100 || comp_litP >= 80 && comp_litP <= 100 || artP >= 80 && artP <= 100 || averageP >= 80 && averageP <= 100)
{
symbolP = "A";
codeP = 7;
}
return;
}
int main( )
{
string name, surname, schoolName, outcome;
float eng, math, life_orient, hist, comp_lit, art, average;
float maximum = 1;
float minimum = 0;
int code;
string symbol;
string english = "English";
string mathematics = "Mathematics";
string life_orientation = "Life Orientation";
string history = "History";
string computer_literacy = "Computer Literacy";
string art1 = "Art";
studentDetails(name, surname, schoolName);
getMarks(eng, math, life_orient, hist, comp_lit, art);
average = calcAverageYearMark(eng, math, life_orient, hist, comp_lit, art);
minMax(eng, math, life_orient, hist, comp_lit, art, minimum, maximum);
passOrFail(eng, math, life_orient, hist, comp_lit, art, outcome);
awardDistinction(eng, math, life_orient, hist, comp_lit, art);
codeSymbol(eng, math, life_orient, hist, comp_lit, art, symbol, code);
cout << "***************************************************************************************************" << endl;
cout << "**************************************STUDENT ACADEMIC REPORT**************************************" << endl;
cout << "This program inputs the learner marks of matric level subjects and prints the students final report" << endl;
cout << "Name: " << name << " " << surname << " School: " << schoolName << endl;
cout << "Subject\tMark\tSymbol\tCode" << endl;
cout << english << '\t' << eng << '\t' << symbol << '\t' << code << endl;
cout << mathematics << '\t' << math << '\t' << symbol << '\t' << code << endl;
cout << "Average year mark: " << average << " with Symbol " << symbol << " and Code " << code << endl;
cout << "Outcome: " << outcome << endl;
cout << "The highest mark was " << maximum << "%" << endl;
cout << "The lowest mark was " << minimum << "%" << endl;
cout << "***************************************************************************************************" << endl;
return 0;
}
Step by Step Solution
3.47 Rating (157 Votes )
There are 3 Steps involved in it
Step: 1
1Printing mark per subject with its corresponding symbol and code Create variables to hold marks symbols and codes for each subject Create two functions getSymbol and getCode to generate symbol and co...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started