Question

In: Computer Science

Write a program to compute numeric grades for a course. The course records are in a...

Write a program to compute numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format:


Each line contains a student’s last name, then one space, followed by the student’s first name, then one space, then ten or fewer quiz scores.


(If there are fewer than ten scores, that means the student missed one or more quizzes.) The quiz scores are whole numbers and are separated by one space. Your program will take its input from this file and send its output to a second file. The data in the output file will be the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student’s quiz scores. The average score is the sum of the quiz scores divided by 10. This amounts to giving the student a 0 for any missed quiz.


The output file will contain a line (or lines) at the beginning of the file explaining the output. Use formatting instructions to make the layout neat and easy to read.


After placing the desired output in an output file, your program will close all files and then copy the contents of the output file to the input file so that the net effect is to change the contents of the input file.


Use at least two functions that have file streams as all of some of their arguments.

Hint: Check out putback member function. See topic in Files menu.

SAMPLE OUTPUT


Input file:

test_ line_ 10 20 30 40 50 60 70

Price Betty 40 50 60 70 60 50 30 60 90

Goodman John 60 70 80 90 100 90

Smith Charles 70 80 90 60 70 60 80 90 90 90

Spangenberg Ward 70 70 80 90 70 80 90 80 70 60

Output file:

Last Name, First Name, up to 10 quiz scores. last entry is the average.

test_ line_ 10 20 30 40 50 60 70 28.00

Price Betty 40 50 60 70 60 50 30 60 90 51.00

Goodman John 60 70 80 90 100 90 49.00

Smith Charles 70 80 90 60 70 60 80 90 90 90 78.00

Spangenberg Ward 70 70 80 90 70 80 90 80 70 60 76.00


Point Distribution:
-50 Does not compile
-5 Warnings
-5 No description multiple line comments (name, date, etc)
-5 No single line comments (logic, input, output, etc)
-20 Does not use at least 2 programmer defined functions with stream passing.
-10 Does not copy output file to input file
-10 Does not format output


can you please send the answer to my emil [email protected]

thank you

C++

C++

Solutions

Expert Solution

Code:

Code as text:

#include <iostream>

#include <fstream>

#include <sstream>

#include <iomanip>

using namespace std;

int main() {

// open the files

ifstream infile("input.txt");

ofstream outfile("output.txt");

string line;

// read each line from file and process it

while (getline(infile, line)) {

istringstream data(line);

string lname, fname;

int score;

// read names

data >> lname >> fname;

outfile << lname << " " << fname << " ";

double average = 0;

// read scores

while (data >> score) {

outfile << score << " ";

average += score;

}

// calculate average

average = average / 10;

outfile << fixed << setprecision(2) << average << "\n";

}

// close files

infile.close();

outfile.close();

// reopen files to write back to input file

infile.open("output.txt");

outfile.open("input.txt");

while(getline(infile, line)) {

outfile << line << endl;

}

// close files

infile.close();

outfile.close();

return 0;

}

Sample run:

Input.txt

Output.txt

Changed input.txt:


Related Solutions

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...
Write a program in Python jupyter notebook for following: Part1: Course grade calculation: Course grades for...
Write a program in Python jupyter notebook for following: Part1: Course grade calculation: Course grades for CIS 1100 are calculated based on two assignments, a midterm exam, and a final exam. Here are the weights of these. Assignments 25% Midterm exam 35% Final exam 40% Ask the user for the scores they received for the two assignments, midterm exam, and the final exam. Then calculate and display their total weighted score they received for the course. Based on the weighted...
In a certain large college course, past records show that grades of A, B, C, D,...
In a certain large college course, past records show that grades of A, B, C, D, and F (which are the only grades assigned) are equally likely. If one student is chosen at random, what is: (a) Pr(C) (b) Pr(A or B) (c) Pr(a grade better than D) (d) Pr(A, B, C, D, or F) (e) Pr(B and D) (f) Pr(E) If two students who do not know one another take the course described above, what are the following probabilities:...
Write a program that prompts the user to enter a person’s date of birth in numeric...
Write a program that prompts the user to enter a person’s date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Follow similar conventions for the invalid values of month and year. (Note that your program...
Write a Python program that asks the user to enter a student's name and 8 numeric...
Write a Python program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name will be a local variable. The program should display a letter grade for each score, and the average test score, along with the student's name. Write the following functions in the program: calc_average - this function should accept 8 test scores as arguments and return the average of the scores per student determine_grade -...
PYTHON Write a program that asks the user to enter a student's name and 8 numeric...
PYTHON Write a program that asks the user to enter a student's name and 8 numeric assignment scores (out of 100 for each assignment). The program should output the student's name, a letter grade for each assignment score, and a cumulative average for all the assignments. Please note, there are 12 students in the class so your program will need to be able to either accept data for 12 students or loop 12 times in order to process all the...
Write a program and ask a user to enter a numeric value between 0 - 99....
Write a program and ask a user to enter a numeric value between 0 - 99. Your program will spell out the numbers into words. You must use at least three switch cases in addition to multiple if statements. Each missing switch statement will reduce your grade for this problem by 20%. Note: The total number of if statements and switch cases should not exceed 28. Additional if/case statement will further reduce your grade by 5%. in c++ please
Write a python program that asks the user to enter a student's name and 6 numeric...
Write a python program that asks the user to enter a student's name and 6 numeric tests scores (out of 100 for each test). The name will be a global variable. Create functions to calculate a letter grade for the student and calculate the average of the test scores for the student. The program should display a letter grade for each score, and the average test score, along with the student's name. Assume 6 students in the class. Functions in...
Write program that prompts the user to enter a person's date of birth in numeric form...
Write program that prompts the user to enter a person's date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Similar conventions for the invalid values of month and year. (Note that your program must handle...
Write a PYTHON program that asks the user to enter a student's name and 8 numeric...
Write a PYTHON program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name will be a local variable. The program should display a letter grade for each score, and the average test score, along with the student's name. Write the following functions in the program: calc_average - this function should accept 8 test scores as arguments and return the average of the scores per student. determine_grade -...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT