Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//Include this header file, while using visual studio. #include \"stdafx.h\" //I

ID: 3879807 • Letter: #

Question

//Include this header file, while using visual studio.

#include "stdafx.h"

//Include the required header file.

#include <iostream>

#include <string>

//Use the standard naming convention.

using namespace std;

//Define the structure to store the student's information.

struct Student

{

     //Declare the required variables.

     double quiz_score_1;

     double quiz_score_2;

     double mid_term_score;

     double finalexam_score;

     double avgOfScores;

     char finalGrade;

};

//Declare the required functions.

double inputScores(string, int);

char computeFinalGrade(double);

//Start the execution of main() method.

int main()

{

     //Declare a structure variable to store the student's

     //details.

     Student stu;

     //Prompt the user to enter the scores for all the

     //quizes, mid-exams, and final exams.

     cout << "Enter the scores of the student: ";

     //Call the function inputScores() to get the scores

     //for the quizez, mid-exams, and final exam.

     stu.quiz_score_1 = inputScores("quiz 1", 10);

     stu.quiz_score_2 = inputScores("quiz 2", 10);

     stu.mid_term_score = inputScores("mid term exam",

          100);

     stu.finalexam_score = inputScores("final exam", 100);

     //Display the details of the student's scores and

     //grade.

     cout << " ----Student Final Report---- ";

     cout << "Score for the quiz 1: " << stu.quiz_score_1

          << endl;

     cout << "Score for the quiz 2: " << stu.quiz_score_2

          << endl;

     cout << "Score for the mid term exam: " <<

          stu.mid_term_score << endl;

     cout << "Score for the final exam: " <<

          stu.finalexam_score << endl;

     //Calculate the average of the scores in percentage.

     //The weightage of final exam, mid term exam, and both

     //quizes is 50 %, 25 %, and 25 %respectively.

     stu.avgOfScores = (stu.quiz_score_1 +

          stu.quiz_score_2) / 20 * 100 * .25 +

          stu.mid_term_score*.25 + stu.finalexam_score*.5;

     //Call the function computeFinalGrade() to get the

     //final grade corresponding to the average of scores.

     stu.finalGrade = computeFinalGrade(stu.avgOfScores);

     //Display the average of scores of all examinations in

     //percentage and final grade of teh student.

     cout << "The average percentage of the scores of the";

     cout << " student is: " << stu.avgOfScores << endl;

     cout << "The final grade of the student is: " <<

          stu.finalGrade << endl;

     //Use this command while using visual studio.

     system("pause");

     return 0;

}

//Define the method computeFinalGrade().

char computeFinalGrade(double avgScore)

{

     //Declare the required variable.

     char grade;

     //If the average score is more than or equal to 90,

     //then the final grade will be A.

     if (avgScore >= 90)

          grade = 'A';

     //If the average score is more than or equal to 80 and

     //less than 90, then the final grade will be B.

     else if (avgScore < 90 && avgScore >= 80)

          grade = 'B';

     //If the average score is more than or equal to 70 and

     //less than 80, then the final grade will be C.

     else if (avgScore < 80 && avgScore >= 70)

          grade = 'C';

     //If the average score is more than or equal to 60 and

     //less than 70, then the final grade will be D.

     else if (avgScore < 70 && avgScore >= 60)

          grade = 'D';

     //If the average score is less than 60, then the final

     //grade will be F.

     else if (avgScore < 90)

          grade = 'F';

     //Return the final grade.

     return grade;

}

//Define the function inputScores().

double inputScores(string exams, int max_marks)

{

     //Declare the required variables.

     int marks;

     //Prompt the user to enter the score for an exam.

     cout << "Enter the score for " << exams << ": ";

     cin >> marks;

     //Check if the score is in a valid range.

     while (marks < 0 || marks > max_marks)

     {

          //Display an appropriate message and prompt the

          //user again for the score.

          cout << "Please enter the valid score between 0";

          cout << " and " << max_marks << " ";

          cout << "Enter the score for " << exams << ": ";

          cin >> marks;

     }

     //Return the score of the student.

     return marks;

}

Please use the information given and Please write this code in c++!!

Explanation / Answer

I verified the code.

Sample input:

8 7 90 85

Sample output:

Enter the scores of the student:
Enter the score for quiz 1: Enter the score for quiz 2: Enter the score for mid term exam: Enter the score for final exam:
----Student Final Report----
Score for the quiz 1: 8
Score for the quiz 2: 7
Score for the mid term exam: 90
Score for the final exam: 85
The average percentage of the scores of the student is: 83.75
The final grade of the student is: B

Your code is working fine. If you need further help, please add comment as I spent sometime on this.

#include "stdafx.h"
#include <iostream>
#include <string>

//Use the standard naming convention.
using namespace std;

//Define the structure to store the student's information.
struct Student
{
//Declare the required variables.
double quiz_score_1;
double quiz_score_2;
double mid_term_score;
double finalexam_score;
double avgOfScores;
char finalGrade;
};
//Declare the required functions.
double inputScores(string, int);
char computeFinalGrade(double);

//Start the execution of main() method.
int main()
{
//Declare a structure variable to store the student's details.
Student stu;

//Prompt the user to enter the scores for all the
//quizes, mid-exams, and final exams.
cout << "Enter the scores of the student: ";

//Call the function inputScores() to get the scores
//for the quizez, mid-exams, and final exam.
stu.quiz_score_1 = inputScores("quiz 1", 10);
stu.quiz_score_2 = inputScores("quiz 2", 10);
stu.mid_term_score = inputScores("mid term exam", 100);
stu.finalexam_score = inputScores("final exam", 100);

//Display the details of the student's scores and grade.
cout << " ----Student Final Report---- ";
cout << "Score for the quiz 1: " << stu.quiz_score_1
<< endl;
cout << "Score for the quiz 2: " << stu.quiz_score_2
<< endl;
cout << "Score for the mid term exam: " <<
stu.mid_term_score << endl;
cout << "Score for the final exam: " <<
stu.finalexam_score << endl;

//Calculate the average of the scores in percentage. The weightage of final exam, mid term exam, and both quizes is 50 %, 25 %, and 25 %respectively.
stu.avgOfScores = (stu.quiz_score_1 +
stu.quiz_score_2) / 20 * 100 * .25 +
stu.mid_term_score*.25 + stu.finalexam_score*.5;

//Call the function computeFinalGrade() to get the
//final grade corresponding to the average of scores.
stu.finalGrade = computeFinalGrade(stu.avgOfScores);

//Display the average of scores of all examinations in
//percentage and final grade of teh student.
cout << "The average percentage of the scores of the";
cout << " student is: " << stu.avgOfScores << endl;
cout << "The final grade of the student is: " <<
stu.finalGrade << endl;
//Use this command while using visual studio.
system("pause");
return 0;
}

//Define the method computeFinalGrade().
char computeFinalGrade(double avgScore)
{
//Declare the required variable.
char grade;

//If the average score is more than or equal to 90,
//then the final grade will be A.
if (avgScore >= 90)
grade = 'A';

//If the average score is more than or equal to 80 and
//less than 90, then the final grade will be B.
else if (avgScore < 90 && avgScore >= 80)
grade = 'B';

//If the average score is more than or equal to 70 and
//less than 80, then the final grade will be C.
else if (avgScore < 80 && avgScore >= 70)
grade = 'C';

//If the average score is more than or equal to 60 and
//less than 70, then the final grade will be D.
else if (avgScore < 70 && avgScore >= 60)
grade = 'D';

//If the average score is less than 60, then the final
//grade will be F.
else if (avgScore < 90)
grade = 'F';

//Return the final grade.
return grade;
}

//Define the function inputScores().
double inputScores(string exams, int max_marks)
{
//Declare the required variables.
int marks;

//Prompt the user to enter the score for an exam.
cout << "Enter the score for " << exams << ": ";
cin >> marks;

//Check if the score is in a valid range.
while (marks < 0 || marks > max_marks)
{
//Display an appropriate message and prompt the
//user again for the score.
cout << "Please enter the valid score between 0";
cout << " and " << max_marks << " ";
  
cout << "Enter the score for " << exams << ": ";
cin >> marks;
}
//Return the score of the student.
return marks;
}