Description: This program is going to allow you to calculate your grade for the
ID: 3699411 • Letter: D
Question
Description: This program is going to allow you to calculate your grade for the class. In your program, you will ask for the user name (it should be able to include spaces). You will then ask for grades for homework assignments and have the user enter -1 when they have entered all of the grades. Next, you will ask the user for programming grades and again have them enter -1 when all are entered. You will ask for the quiz grades or -1 to end. You will ask for the exam grades or -1 to end. You will read the values into an array so that you can pass them to a function (the function is defined below). Consider: Do you need more than one array?Explanation / Answer
#include<iostream>
#include<string>
#include<vector>
#include<cstring>
#include<cctype>
#include<cstdio>
using namespace std;
int main()
{
string name;
cout << "Enter your name: ";
getline(cin, name);
int grade;
vector<int> homeWorkGrade,programmingGrades, quizGrade,examGrade;
while (true)
{
cin >> grade;
if (grade == -1)
break;
else
homeWorkGrade.push_back(grade);
}
while (true)
{
cin >> grade;
if (grade == -1)
break;
else
programmingGrades.push_back(grade);
}
while (true)
{
cin >> grade;
if (grade == -1)
break;
else
quizGrade.push_back(grade);
}
while (true)
{
cin >> grade;
if (grade == -1)
break;
else
examGrade.push_back(grade);
}
int i = 0;
while (name[i])
{
char c = name[i];
putchar(toupper(c));
i++;
}
double percentange = calculateGradePercentage(homeWorkGrade,programmingGrades,quizGrade,examGrade);
char GrageMark;
if (percentange >= 93 && percentange <= 100) {
GrageMark = 'A';
}
else if (percentange >= 90 && percentange <= 92.9) {
GrageMark = 'A-';
}
else if (percentange >= 85 && percentange <= 89.9) {
GrageMark = 'B+';
}
else if (percentange >= 82 && percentange <= 84.9) {
GrageMark = 'B';
}
else if (percentange >= 80 && percentange <= 81.9) {
GrageMark = 'B-';
}
else if (percentange >= 76 && percentange <= 79.9) {
GrageMark = 'C+';
}
else if (percentange >= 72 && percentange <= 75.9) {
GrageMark = 'C';
}
else if (percentange >= 69.5 && percentange <= 71.9) {
GrageMark = 'C-';
}
else if (percentange >= 68 && percentange <= 69.5) {
GrageMark = 'D+';
}
else if (percentange >= 65 && percentange <= 67.9) {
GrageMark = 'D';
}
else if (percentange >= 60 && percentange <= 64.9) {
GrageMark = 'D-';
}
else{
GrageMark = 'F';
}
cout << "OverAll score: " << percentange << " Grade: " << GrageMark;
return 0;
}
double calculateGradePercentage(vector<int> homeWorkGrade, vector<int> programmingGrades, vector<int> quizGrade, vector<int> examGrade)
{
double OverAllScore = 0;
int homeWorkGradeSum = 0;
for (int i = 0; i < homeWorkGrade.size(); i++) {
homeWorkGradeSum += homeWorkGrade[i];
}
homeWorkGradeSum /= homeWorkGrade.size();
homeWorkGradeSum *= 10;
OverAllScore += homeWorkGradeSum;
int programGradeSum = 0;
for (int i = 0; i < programmingGrades.size(); i++) {
programGradeSum += programmingGrades[i];
}
programGradeSum /= programmingGrades.size();
if (homeWorkGrade.size() == 0)
programGradeSum *= 50;
else
programGradeSum *= 40;
OverAllScore += programGradeSum;
int quizGradeSum = 0;
for (int i = 0; i < quizGrade.size(); i++) {
quizGradeSum += quizGrade[i];
}
quizGradeSum /= quizGrade.size();
quizGradeSum *= 10;
OverAllScore += quizGradeSum;
int examGradeSum = 0;
for (int i = 0; i < examGrade.size(); i++) {
examGradeSum += examGrade[i];
}
examGradeSum /= quizGrade.size();
examGradeSum *= 40;
OverAllScore += examGradeSum;
return OverAllScore;
}
Please let me know for any error. or issue.