In C++
In C++
C++ code:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
//to store first and last name
string fName, lName;
char letter;
int hg, lg, ega;
float finalGrade;
cout<<"Enter first name, last name, homework grade (out of 20), lab garde (out of 50), ";
cout<<"\nexam grade average and letter indicating Audit, Passfail or Grade\n\n";
//input in one line
cin>>fName>>lName>>hg>>lg>>ega>>letter;
//calculate final garde that is 10% homework, 20% lab, 70% exam
finalGrade = 0.1*hg + 0.2*lg + 0.7*ega;
cout<<endl;
//output in 7 columns
cout<<(char)toupper(fName.at(0))<<"\t"<<lName<<"\t "<<hg<<"\t"<<lg<<"\t"<<ega<<"\t"<<round(finalGrade);
//check if letter indicates pass
if(letter == 'p' || letter == 'P') {
cout<<"\tPass";
}
//check if letter indicates fail
else if( letter == 'f' || letter == 'F') {
cout<<"\tFail";
}
//check if letter indicates audit
else if( letter == 'a' || letter == 'A') {
cout<<"\tNot gradeable";
}
//otherwise grade
else {
cout<<"\tGrade";
}
return 0;
}
Step by step
Solved in 2 steps with 2 images