Question

In: Computer Science

You are to write a program that grades students (Maybe I will use it on you)....

You are to write a program that grades students (Maybe I will use it on you). Your program must open and read in "input.txt" (an example of which is below). It will contain the students name and their test scores. You are to calculate the students final grade in the course. Take the average of their test scores and output their average to a file with the below format. For the output.txt ensure that the formatting is in the block style shown below. Test scores should always be shown to the second decimal place. input txt: (Meryl Streep 100 105 98.5 99.5 106)

output txt : (Meryl StreepTest scores:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Average score: .......................101.80Test score 1: ........................100.00Test score 2: ........................105.00Test score 3: .........................98.50Test score 4: .........................99.50Test score 5: ........................106.00~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Input fields: <First Name> <Last Name> <Score on Test 1> <Score on Test 2> <Score on Test 3> <Score on Test 4> <Score on Test 5>


c++

Solutions

Expert Solution

Please use below code. In case of any query, do comment:

#include <iostream>

#include<iomanip> //used for setw and setprecesion

#include <fstream> //used for file handling

using namespace std;

int main()

{

    //file stream handle for input file

    ifstream inputFile;

    //file stram handle for output file

    ofstream outputFile;

    //variable to read first name and last name

    string firstname, lastname;

    //for reading scores

    float score1, score2, score3,score4,score5;

    //average score to calculate

    float averageScore =0.0;

   

    //open the input and output files

    inputFile.open("input.txt");

    outputFile.open("output.txt");

   

    //read the input file line by line till end of file

    while(!inputFile.eof())

    {

        //read the variable from inout file

        inputFile >> firstname >> lastname >> score1 >> score2 >> score3 >> score4 >> score5;

       

        //calculate the average Score

        averageScore = (score1 + score2 + score3 + score4 + score5)/5;

       

        //output the expected formatted output to the output file

        outputFile << "(" <<firstname << " " << lastname << " Test Scores: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Average Score:";

        //std::Fixed to set the fixed width of the output and setprecison(2) is used to display two decimal places in the scores

        outputFile <<"......................." << std::fixed << std::setprecision(2) << averageScore;

        outputFile <<" Test score 1: ........................" << std::fixed <<std::setprecision(2) << score1;

        outputFile <<" Test score 2: ........................" << std::fixed <<std::setprecision(2) << score2;

        outputFile <<" Test score 3: ........................" << std::fixed <<std::setprecision(2) << score3;

        outputFile <<" Test score 4: ........................" << std::fixed <<std::setprecision(2) << score4;

        outputFile <<" Test score 5: ........................" << std::fixed <<std::setprecision(2) << score5;

        outputFile <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~)" <<endl;

    }

   

    //close both the files

    outputFile.close();

    inputFile.close();

    return 0;

}

================================================================================

Screen shot of the code for your reference:

Input:

Content of the input file is :

Meryl Steep 100 105 98.5 99.5 106

Bob Jones 99 106 108 101.5 102

Steve White 100 102 105 109 97.5

Output:

Content of the out put file is as below:

(Meryl Steep Test Scores: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Average Score:.......................101.80 Test score 1: ........................100.00 Test score 2: ........................105.00 Test score 3: ........................98.50 Test score 4: ........................99.50 Test score 5: ........................106.00~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~)

(Bob Jones Test Scores: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Average Score:.......................103.30 Test score 1: ........................99.00 Test score 2: ........................106.00 Test score 3: ........................108.00 Test score 4: ........................101.50 Test score 5: ........................102.00~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~)

(Steve White Test Scores: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Average Score:.......................102.70 Test score 1: ........................100.00 Test score 2: ........................102.00 Test score 3: ........................105.00 Test score 4: ........................109.00 Test score 5: ........................97.50~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~)

Please rate answer. Thanks


Related Solutions

Instructions: Write a program to calculate students’ average test scores and their grades. You may assume...
Instructions: Write a program to calculate students’ average test scores and their grades. You may assume the following input data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63...
Directions: Write a program to calculate students’ average test scores and their grades. You may assume...
Directions: Write a program to calculate students’ average test scores and their grades. You may assume the following input data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63...
In java Q2. Write a program that reads grades of type double of eight students that...
In java Q2. Write a program that reads grades of type double of eight students that the user provides. The grades lie between 0 and 10. These grades should be written to a binary file and read from it. The program outputs the highest and lowest grades achieved by students on the screen. The file contains nothing but numbers of type double written to the file with writeDouble.
Write a C++ program that reads a students name followed by 7 numeric grades from a...
Write a C++ program that reads a students name followed by 7 numeric grades from a file.  Compute the average grade after dropping the  lowest grade.   Assign letter grades via this scale .Please show steps in the comments . A 90 – 100 B 80  --89 C 70 –79 D 60 -69 F 0  - 59 Input format: Sam 100 90 87 23 12 67 95 Mary 30 20 90 90 90 90 88 Mark 80 90 80 80 90 87 100 End of file...
Topics Loops while Statement Description Write a program that computes the letter grades of students in...
Topics Loops while Statement Description Write a program that computes the letter grades of students in a class from knowing their scores in a test. A student test score varies from 0 to 100. For a student, the program first asks the student’s name and the student’s test score. Then, it displays the student name, the test score and the letter grade. It repeats this process for each student. The user indicates the end of student data by entering two...
Write a java code snippet that allows a teacher to track her students’ grades. Use a...
Write a java code snippet that allows a teacher to track her students’ grades. Use a loop to prompt the user for each student’s name and the grade they received. Add these values to two separate parallel ArrayLists. Use a sentinel to stop. Output a table listing each of the student’s names in one column and their associated grades in the second column.
The driver’s license office DMV has asked you to write a program that grades the written...
The driver’s license office DMV has asked you to write a program that grades the written portion of the driver’s license questions. The questions has 20 multiple-choice questions. Here are the correct answers: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 B D A A A C B C D A D C C D D B A B C D Your program should store these correct answers...
I have heard students say in the past "I hope this teacher grades on a curve."...
I have heard students say in the past "I hope this teacher grades on a curve." What do they mean by this? Is it beneficial to you or not?
Write a program in python to read from a file the names and grades of a...
Write a program in python to read from a file the names and grades of a class of students to calculate the class average, the maximum, and the minimum grades. The program should then write the names and grades on a new file identifying the students who passed and the students who failed. The program should consist of the following functions: a) Develop a getGrades() function that reads data from a file and stores it and returns it as a...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT