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

Online Grade Report CS 1428 Due: Tuesday 2/23/16 at 10:00pm 75 points Input: You

ID: 3669796 • Letter: O

Question

Online Grade Report

CS 1428

Due: Tuesday 2/23/16 at 10:00pm

75 points

Input: You will use a file with the name "score_info.txt" (without the quotes) as an input file to this program. The file will have the following format:

First_Name (a string)Last_Name (a string)number of exams (an integer)score for first exam (an integer)score for second exam (an integer)etc.

Processing: You will be calculating the average for the exam grades and a grade of A, C or F. The cutoffs of these grades are 89.5 and 70.0. A grade of A or C is passing.

Output: You will be creating an output file that is a web page (in HTML) that can be read by a web browser. For example, if the input file looked like this:

Sam

Jones

2

90

85

The output would look like this.

Grade Report for

Sam Jones

Exam 1 - 90

Exam 2 - 85

Average - 87.50

Grade - C

Sam Jones - Passed

If the average is less than 70.0, you should print out "Failing".

Notes:

You must do this program by yourself. As always, you can discuss the assignment, but don't share any C++ code.

If you want to see what the HTML looks like for a web page, right click on the sample file and choose "View Source." This should give you a good idea of what you need to create. We will also discuss this in class.

We will use several functions in this program. I will give you the headers and you will write the functions. We will also review these in class.

Starting program to revise (make sure you name the file according to the instructions below).

Your source program file must be named   prog04_xxxxxx.cpp

where xxxxxx is your Texas State id number (your netID)

the input file MUST be named "score_info.txt" (no qoutes)

the output file should be named "prog04_output_xxxxxx.html" (no quotes)

Appropriate values should be stored in constant variables.

Be sure to follow the documentation standards for the course.Each variable must be declared on a separate line with a brief comment following the declaration

Use meaningful variable names

BEGINNING CODE :

Explanation / Answer


#include <iostream>
#include <fstream>

using namespace std;

/****************
function - printWebStart

parameters - the output file stream, the title of the web page
returns - nothing

prints the HTML for the beginning of a web page to the output file
****************/

void printWebStart(ofstream &oFile, string pageTitle)
{
   oFile <<pageTitle<< endl;
oFile << "<body>" << endl;
oFile << "<html>" << endl;
}

/****************
function - printWebEnd

parameters - the output file stream
returns - nothing

prints the HTML for the end of a web page to the output file
****************/

void printWebEnd(ofstream &oFile)
{
oFile << "</body>" << endl;
oFile << "</html>" << endl;
}

/****************
function - calcAverage

parameters - the total of the exams (int), the number of exams (int)
returns - the average of the exams (double)

Returns the average of the exam scores when passed in the total and the number of exams
****************/

double calcAverage(int total, int numExams)
{
return (double)numExams/total;
}

/****************
function - processData

parameters - the output file stream
returns - nothing

Reads in the data and prints the report in HTML to the output file
****************/
void processData(ofstream &oFile)
{
ifstream inFile;
inFile.open("score_info.txt");

string firstName;
   string lastName;
   int n;
   int marks;
   int total = 0;
   double average;
   string message;
   inFile>>firstName;
   inFile>>lastName;
   oFile<<firstName<<" "<<lastName<<endl;
   inFile>>n;
   for(int i=1; i<=n; i++){
       inFile>>marks;
       total = total+marks;
       oFile<<"Exam "<<i<<" - "<<marks<<endl;
       }
   average = calcAverage(n,total);
   oFile<<"Average - "<<average<<endl;
   char grade;
   if(average >=89.5){
       grade = 'A';
       message = "Passed";
   }
   else if(average >=70){
       grade = 'C';
       message = "Passed";
   }
   else{
       grade = 'F';
       message = "Failed";
   }
   oFile<<"Grade - "<<grade<<endl;
   oFile<<firstName<<" "<<lastName<<"-"<<message<<endl;
  
}

/**************************************************************************************/

int main()
{
ofstream outFile;
outFile.open("put_your_info_here.html");

printWebStart(outFile, "Grade Report");

processData(outFile);

printWebEnd(outFile);

outFile.close();

//take this line out after you get the program to run
cout << "Hello World!" << endl;

return 0;
}