In: Computer Science
A system is set up to take raw grading information from the console and calculate a consolidated grade. The information comes in as a single line with last name, first name, homework grade ( a total out of 20 ), lab grade ( a total out of 50 ), exam grade average, and a letter ( upper or lower ) indicating Audit, Passfail, or Grade.
Sample input: Mary(first name) Poppins(last name) g(indication) 17(homework grade) 28(lab grade) 87(exam grade)
A program should be written that takes the input data and calculates a consolidated grade based upon 10% Homework, 20 % Lab , and 70% Exams. The output should be formatted with no decimals.
first initial last name - final grade
for a pass/fail student output should indicate only Pass or Fail . For an audit output should say not gradeable.
Using C++
Below is the code for the above problem:
#include <iostream>
using namespace std;
//main method to start the program
int main()
{
string firstName;
string lastName;
char ch;
float homegrade;
float labgrade;
float examGrade;
cout<<"enter the info"<<endl;
cin>>firstName;
cin>>lastName;
cin>>ch;
cin>>homegrade;
cin>>labgrade;
cin>>examGrade;
//find total marks
int total = ((homegrade/30)*10 + (labgrade/50)*20 +
(examGrade/100)*70);
//if user wants grade
if(ch == 'G')
{
cout<<firstName<<" "<<lastName<<"
"<<total;
}
//if user wants pass or fail
else if(ch == 'P')
{
if(total > 33) //above 33% are passed. Take according to your
rules.
{
cout<<firstName<<" "<<lastName<<"
"<<"Pass";
}
else
{
cout<<firstName<<" "<<lastName<<"
"<<"Fail";
}
}
//if user wants audit
else if(ch == 'A')
{
cout<<"Not gradeable";
}
return 0;
}
OUTPUT: