Use variables of Data Type float to contain all numerical values (1) Open a user
ID: 640590 • Letter: U
Question
Use variables of Data Type float to contain all numerical values (1) Open a user specified (user enters in the name) input file. Verify that the file opened successfully. If it did not open successfully, output an error message and terminate. -See th Opening Input/Output Files section on page 3 for the code to perform the check on the success of opening a file (2) If the input file is successfully opened, prompt for and open a user specified output file. Verify that the output file opened successfully. If it did not open successfully, output an error message and terminate. Use the filename "Bad/file" to cause the open function to fail for t output file. (3) For steps 1 and 2 echo print out the name of the file entered by the user (4) Read in the title line from the input file and write this line to the output file (5) Write the column headings to the output file (see the sample solution output) (6) For the first person, read in their first name, last name and four test scores. (check the project (7) Find the average of the four test scores and add this average to an overall sunm 6 input file information on page 3) (8) Write the information for the first person to the output file. Output the first 9 characters of the last name, the first 10 characters of the first name and the test average of the person (9) Repeat steps 6. 7 and 8 for the second and third person information in the input file (10) (11) (12) Calculate the overall average of the exams for all three people Output the overall average information line followed by the overall average value Output of the program shall match that of the sample solution DOLLExplanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
string name;
float grade1, grade2, grade3, grade4, avg, sumAvg = 0.0;
for (int i = 0; i < 3; i++)
{
cout << "Please enter name: ";
getline (cin, name);
cout << endl;
cout << "Please enter first grade: " << endl;
cin >> grade1;
cout << "Please enter second grade: " << endl;
cin >> grade2;
cout << "Please enter third grade: " << endl;
cin >> grade3;
cout << "Please enter forth grade: " << endl;
cin >> grade4;
avg = (grade1 + grade2 + grade3 + grade4) / 4;
cout << "The average grade for " << name << " is " << fixed << setprecision(2) << avg << endl;
sumAvg = sumAvg + avg;
}
cout << "Overall Average: " << fixed << setprecision(2) << (sumAvg / 3);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.