Question

In: Computer Science

Write a program that will calculate numerical and letter grades for a student and output a...

  1. Write a program that will calculate numerical and letter grades for a student and output a report:
  2. The information will be in the provided data file studentGrades.txt. The data file consists of several rows of data containing a student name and information for 3 types of assignments:
  3. First Name, Last Name, number of homework grades, values for homework grades, percentage of total grade, number of program grades, values for program grades, percental of total grade, number of ex-am grades, values for ex-am grades, percentage of ex-am grades. For example, the first row of the data file contains the following:

Sherlock Holmes 3 100 100 100 0.15 3 75 80 90 0.40 3 60 70 70 0.45

The student, Sherlock Holmes, has three homework grades, each with a value of 100. Homework is 15% of total grade. He has three program grades with values of 75, 80, 90. Program is 40% of grade. He has three exa-ms grades of 60, 70, 70. Exa-ms are 45% of grade.

  1. Request the name of the input file from the user. Do not “hard-code” the file name in the program. Check to ensure the input file opens. If it does not open, display an appropriate message to the user and exit the program.
  2. Using a looping construct, read until end of file. Do not hard code the number of rows in the loop. The file must be read using an outer loop and three inner/nested loops to read all the data properly. The first number will aid in determining the NUMBER of grades to read. Do NOT assume there will be only 3 values in each category. Code for a variable number of values in each category.
  3. The maximum points for each assignment, homework and ex am are 100. The maximum points for each may be calculated by multiplying the number of assignments in the group by 100. Calculate final grade using the following formula:

((total HOMEWORK Points earned/maximum HOMEWORK points) * percent of total grade) + (total PROGRAM Points earned/maximum PROGRAM points) * percent of total grade) + (total EX-AM Points earned/maximum EX-AM points) * percent of total grade)) * 100

  1. Use the final numerical grade to look up corresponding letter grade as follows:

90 - 100 = A

80 - 89 = B

70 - 79 = C

60 - 69 = D

< 60 = F

  1. Use the final letter grade to look up a "witty" comment of your choice, using a SWITCH statement. A statement must be output for each letter grade above. For example:

A = "Most excellent work”

B = "IMHO You Passed"

etc.

  1. Request an output file name from the user. Do not “hard-code” the file name in the program. Check to ensure the output file opens. If it does not open, display an appropriate message to the user and exit the program.
  2. For each student, output the following to the console (screen) and the output file in a neat, readable format. Output each input line on one output line. Use manipulators to output values in readable columns:

Student Name, Total Points (numerical grade): NN. Letter Grade: X. Depending on letter grade, The witty comment.

  1. Include the following documentation. Points will be deducted if you do not include the following documentation:

The name of your C++ file

Your name

Some kind of date, either the due date or the date you finished

The type of input

The type of output

A brief description of the algorithm/program

Watch for 1-off errors; truncated grade values; infinite loops

Turn in file code *.cpp; README file; input file (even though provided) and ALL output files. You DO NOT need to submit the executable (*.exe). You MAY zip all the files and submit if you choose. You MUST include all the files indicated or points will be deducted.

README must contain instructions for location of input/output files

STUDENT .TXT

Sherlock Holmes 3 100 100 100 0.15 3 75 80 90 0.40 3 60 70 70 0.45
Constant Success 4 100 88 100 92 0.15 3 75 80 90 0.40 2 100 89 0.45
Happy Grant 3 79 82 77 0.15 3 80 82 93 0.40 3 86 90 76 0.45
Reach Further 3 100 99 98 0.15 3 98 97 93 0.40 3 88 90 99 0.45

Solutions

Expert Solution

// C++ program to read student grades from input file and calculate and output the numerical and letter grade to console and output file
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()
{
string in_filename, out_filename;
ifstream fin;
ofstream fout;

// read input filename
cout<<"Enter the input filename: ";
cin>>in_filename;
fin.open(in_filename); // open input file

// check if input file opened successfully
if(fin.fail())
{
cout<<"Unable to open input file: "<<in_filename<<". Exiting application"<<endl;
return 1;
}

// read output filename
cout<<"Enter the output filename: ";
cin>>out_filename;
fout.open(out_filename); // create and open output file

// check if output file opened successfully
if(fout.fail())
{
cout<<"Unable to open output file: "<<out_filename<<". Exiting application"<<endl;
return 1;
}

string fName, lName;
int numHW, numProgram, numExam;
double totalHW = 0, totalProgram = 0, totalExam = 0;
double weightHw, weightProgram, weightExam;
double grade;
double avgGrade;
char letterGrade;
string comment;

// loop to read till the end of input file
while(!fin.eof())
{
// reset total grades for homework, program and totalExam to 0
totalHW = totalProgram = totalExam = 0;

// read first name and last name and number of homework grades
fin>>fName>>lName>>numHW;

// loop to homework grades and calculate total homework grades
for(int i=0;i<numHW;i++)
{
fin>>grade;
totalHW += grade;
}

// read the homework percent and number of program grades
fin>>weightHw>>numProgram;

// loop to program grades and calculate total program grades
for(int i=0;i<numProgram;i++)
{
fin>>grade;
totalProgram += grade;
}

// read the program percent and number of exam_grades
fin>>weightProgram>>numExam;

// loop to _exam grades and calculate totalExam grades
for(int i=0;i<numExam;i++)
{
fin>>grade;
totalExam += grade;
}

fin>>weightExam; // read the examPercent

// calculate the average grade
avgGrade = (((totalHW/(100*numHW))*weightHw) + ((totalProgram/(100*numProgram))*weightProgram) + ((totalExam/(numExam*100))*weightExam))*100;

// based on average grade determine letter grade and comment
if(avgGrade >= 90){
letterGrade = 'A';
comment = "Most excellent work";
}
else if(avgGrade >= 80){
letterGrade = 'B';
comment = "IMHO You Passed";
}
else if(avgGrade >= 70){
letterGrade = 'C';
comment = "Work hard";
}
else if(avgGrade >= 60){
letterGrade = 'D';
comment = "Just passed";
}
else{
letterGrade = 'F';
comment = "Failed";
}

// output the result to console and output file
cout<<fixed<<setprecision(2);
fout<<fixed<<setprecision(2);
cout<<endl<<fName<<" "<<lName<<" Total Points (numerical grade): "<<avgGrade<<" Letter Grade: "<<letterGrade<<" "<<comment;
fout<<fName<<" "<<lName<<" Total Points (numerical grade): "<<avgGrade<<" Letter Grade: "<<letterGrade<<" "<<comment<<endl;
}

cout<<endl;
// close the input and output files
fin.close();
fout.close();


return 0;
}

//end of program

Output:

Input file: studentGrades.txt

Console:

Output file:


Related Solutions

Write a program that will calculate numerical and letter grades for a student and output a...
Write a program that will calculate numerical and letter grades for a student and output a report: The information will be in the provided data file studentGrades.txt. The data file consists of several rows of data containing a student name and information for 3 types of assignments: First Name, Last Name, number of homework grades, values for homework grades, percentage of total grade, number of program grades, values for program grades, percental of total grade, number of ex-am grades, values...
Write a program that translates a letter grade into a number grade. Letter grades are A,...
Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1 and 0. There is no F+ or F-. A “+” increases the numeric value by 0.3, a “–“ decreases it by 0.3. However, an A+ has value 4.0.4 pts Enter a Letter grade: B- The numeric value is 2.7 Your code with comments A screenshot...
Grade:ABCDF Probability:0.10.30.40.10.1 To calculate student grade point averages, grades are expressed in a numerical scale with...
Grade:ABCDF Probability:0.10.30.40.10.1 To calculate student grade point averages, grades are expressed in a numerical scale with A = 4, B = 3, and so on down to F = 0. Find the expected value. This is the average grade in this course. Explain how to simulate choosing students at random and recording their grades. Simulate 50 students and find the mean of their 50 grades. Compare this estimate of the expected value with the exact expected value from part (a)....
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
use C++ Write a program to calculate the frequency of every letter in an input string...
use C++ Write a program to calculate the frequency of every letter in an input string s. Your program should be able to input a string. Calculate the frequency of each element in the string and store the results Your program should be able to print each letter and its respective frequency. Identify the letter with the highest frequency in your message. Your message should be constructed from at least 50 letters. Example of Output: letters frequency a 10 b...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
Write a program to calculate fees that must be paid by a student at a State...
Write a program to calculate fees that must be paid by a student at a State university using the following values: Each semester unit $90.00 Regular room charge per semester $200.00 Air conditioned room $250.00 Food charge for the semester $400.00 Matriculation fee (all students) $30.00 Diploma fee (if graduating student) $35.00 Input student ID number (one integer containing four digits), the type of room (regular or air conditioned), units, and whether or not the student is graduating. Output an...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT