QUESTION 2: (40) Suppose we want to compile a student academic report for a high
ID: 3741939 • Letter: Q
Question
QUESTION 2: (40)
Suppose we want to compile a student academic report for a high school learner in grade 12 (matric).
A matric learner is enrolled for 6 study units (subjects), namely: English, Mathematics, Life Orientation, History, Computer literacy, Geography. The learner has to pass at least four subjects, including English, to complete grade 12. The subject pass mark is 50%.
Write a program that prompts the learner to key in their marks for each subject. The program should include the following functions:
A function studentDetails, that prompts the learner to key in their personal details
name,surname, and schoolName. (3)
A function getMarks, that prompts the learner to key in a mark for each of the six subjects, and validate the marks. Do not accept marks lower than 0 or higher than 100. (3)
A function calcAverageYearMark, to calculate and display the average of the 6 Subjects. This function should be called just once by main, and should be passed the 6 Subject marks. (6)
A function minMax, to find and return the lowest and the highest of the 6 subject marks
passed to it as the subject with the lowest mark; (6)
A function passOrFail, to determine whether the student has passed or failed grade 12. (9)
A function awardDistinction to determine which of the subjects have received distinctions. A subject receives a distinction if the mark is 75% and above. Also a student has
passed with distinction if the average mark is 75% and above. (3)
A function codeSymbol, to convert each mark to a symbol (A, B, C, D, E, F) and a code
(7,6,5,4,3,2,1). The symbol and code should be printed next to the mark in the student report.
The same should be calculated and displayed for the average mark. (6)
A function to Display the student report. (4)
Use the table below to determine the student symbol and code attained.
CODE
SYMBOL
MARK
7
A
80 - 100%
6
B
70 - 79%
5
C
60 - 69%
4
D
50 - 59%
3
E
40 - 49%
2
F
30 - 39%
1
FF
0 - 29%
Execute your program using the following data:
John Africa (Kings College)
Mary Smith
(Green valley High)
Thuli Booi
(Gauteng girls )
English
50%
48%
82%
Mathematics
76%
80%
66%
Life Orientation
40%
75%
62%
History
62%
70%
76%
Computer literacy
56%
86%
86%
Art
38%
72%
78%
You have to submit the program code and output.
Sample run:
Please key in your name:
John Africa
Please key in the name of your school:
Kings College
Key in your mark for English:
50
Key in your mark for Mathematics:
76
Key in your mark for Life Orientation:
40
Key in your mark for History:
62
Key in your mark for Computer literacy:
56
Key in your mark for Art:
38
***********************************************
**** STUDENT ACADEMIC RECORD
This program inputs the learner marks of matric level subjects and prints the student final report.
***********************************************
****
Name: John Africa School: Kings College
Subject Mark
Symbol Code
English 50%
D 4
Mathematics 76%
B 6
Life Orientation 40%
E 3
History 62%
C 5
Computer literacy 56%
D 4
Art 38%
F 2
Average Year Mark: 53.67 with Symbol D and code 4
Outcome: Passed
The highest mark was 76%
The lowest mark was 38%
***************************************************
CODE
SYMBOL
MARK
7
A
80 - 100%
6
B
70 - 79%
5
C
60 - 69%
4
D
50 - 59%
3
E
40 - 49%
2
F
30 - 39%
1
FF
0 - 29%
Explanation / Answer
#include<iostream>
using namespace std;
class student
{
int eng,math,life,history,comp,art; //These variables are for 6 subjects' marks
string name,surname,school; //for storing name, surname and school name
public:
void studentDetails(); //getting student details
void getMarks(); // getting subject marks
void average(); //calculating average
void result(); //deducing pass or fail
void minmax(); //calculating maximum and minimum
void distinction(); //finding distinction in which subjects
pair<int,string> codeSymbol(int); //finding symbol and code
void display(); //displaying results
};
void student::studentDetails()
{
cout<<"Please key in your name: ";
cin>>name>>surname;
cout<<"Please key in the name of your school: ";
cin.get(); // used to take the new line character after name
getline(cin,school); //using getline as school name includes spaces
}
void student::getMarks()
{
cout<<"Key in your mark for English: ";
cin>>eng;
cout<<"Key in your mark for Mathematics: ";
cin>>math;
cout<<"Key in your mark for Life Orientation: ";
cin>>life;
cout<<"Key in your mark for History: ";
cin>>history;
cout<<"Key in your mark for Computer literacy: ";
cin>>comp;
cout<<"Key in your mark for Art: ";
cin>>art;
}
void student::average()
{
float avg;
avg=(float)(eng+math+life+history+comp+art)/6;
cout<<avg;
}
void student::result()
{
int flag=1; // to count no of subjects student has cleared
if(eng>=50) // clearing English test is compulsory
{
if(math>=50)
flag++;
if(life>=50)
flag++;
if(history>=50)
flag++;
if(comp>=50)
flag++;
if(art>=50)
flag++;
}
if(flag>=4) //if pass in more than 3 subjects,then pass
cout<<"Passed";
else
cout<<"Failed";
if((eng+math+life+history+comp+art)/6 >= 75) //checking if passed with distinction
cout<<" with distinction";
}
void student::minmax()
{
int m1=100,m2=0; //m1 stores minimum and m2 stores maximum
m1=min(m1,min(eng,math));
m1=min(m1,min(life,history));
m1=min(m1,min(comp,art));
m2=max(m2,max(eng,math));
m2=max(m2,max(life,history));
m2=max(m2,max(comp,art));
cout<<" The highest mark was "<<m2<<"% ";
cout<<" The lowest mark was "<<m1<<"% ";
}
void student::distinction()
{
cout<<" Distinction Subjects: ";
int flag=0;
if(eng>=75)
{
cout<<"English ";
flag++;
}
if(math>=75)
{
cout<<"Mathematics ";
flag++;
}
if(life>=75)
{
cout<<"Life Orientation ";
flag++;
}
if(history>=75)
{
cout<<"History ";
flag++;
}
if(comp>=75)
{
cout<<"Computer ";
flag++;
}
if(art>=75)
{
cout<<"Art ";
flag++;
}
if(flag==0)
cout<<"None";
}
pair<int,string> student::codeSymbol(int a)
{
pair<int,string> p; //for returning both symbol and code
if(a<30)
{
p.first=1; p.second="FF";
}
else if(a<40)
{
p.first=2; p.second="F";
}
else if(a<50)
{
p.first=3; p.second="E";
}
else if(a<60)
{
p.first=4; p.second="D";
}
else if(a<70)
{
p.first=5; p.second="C";
}
else if(a<80)
{
p.first=6; p.second="B";
}
else {
p.first=7; p.second="A";
}
return p;
}
void student::display()
{
cout<<" Name: "<<name<<" "<<surname;
cout<<" School: "<<school<<endl<<endl;
pair<int,string> p=codeSymbol(eng);
cout<<"English "<<eng<<" ";
cout<<p.second<<" "<<p.first<<endl;
cout<<"Mathematics "<<math<<" ";
p=codeSymbol(math);
cout<<p.second<<" "<<p.first<<endl;
cout<<"Life orientation "<<life<<" ";
p=codeSymbol(life);
cout<<p.second<<" "<<p.first<<endl;
cout<<"History "<<history<<" ";
p=codeSymbol(history);
cout<<p.second<<" "<<p.first<<endl;
cout<<"Computer "<<comp<<" ";
p=codeSymbol(comp);
cout<<p.second<<" "<<p.first<<endl;
cout<<"Art "<<art<<" ";
p=codeSymbol(art);
cout<<p.second<<" "<<p.first<<endl;
cout<<" Average Year Mark: ";
average();
p=codeSymbol((eng+math+life+history+art+comp)/6);
cout<<" with Symbol "<<p.second<<" and code "<<p.first<<endl;
distinction();
cout<<endl;
cout<<" Outcome: ";
result();
cout<<endl;
minmax();
}
int main()
{
student s;
s.studentDetails();
s.getMarks();
s.display();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.