CSC100AA and CIS162AB
Files Program 1 – Famous Computer Scientists
1. Review the presentation Intro to Using Files in C++ and Section 5.12 in your textbook.
Download the text file called scores.txt . Save it inside your Project folder. It contains the following data:
Grace Hopper 81.5 90.0 65.5 79.9 93.2
Alan Kay 75.5 81.5 70 90 98.2
John Backus 99.0 74 100 87.7 99.9
Sergey Brin 62 100 88.5 79.7 97.3
Dennis Ritchie 97 98 100 100 99.9
Brian Kernighan 100 99 100 89 99
2. Create a new program called FamousCS.cpp. (Our Files Activities will be helpful). The basic structure is:
#include statements – there will be several
using namespace std;
int main()
{
//declare variables needed
//define file stream object
//open the file scores.txt
if (successfully opened file)
{
// using a while loop read in and display the data
// close the data file
}
else
{
cout << “Error opening file.” << endl;
}//end of else
return 0;
}
3. (5 pts) This program will:
□ Open a file called scores.txt . Check if there are any errors opening the file.
□ Assuming no file opening errors, use a while loop to:
□ read the data line by line . You will need several variables to read each value into. (hint: fName, lName, exam1,
exam2, exam3 …..)
□ calculate the average exam score for each student
□ using cout, display the exam average to 2 decimal places for each computer scientist. (i.e. 83.12)
□ close the file
4. (5 pts) Add the following to your program:
□ add another famous computer scientist (your choice) and their
exam data to scores.txt.
□ count how many students are in the scores.txt file and display a
message to your screen. Example output shown here
□ In addition to displaying the results to your screen, write the same
information to an output file called CSExamReport.txt. Example file
contents shown on back.
5. Who are the people listed in the scores.txt file anyway?
using cout, display their name and what their “claim to fame” is. You will have to research this.
Example output with extra credit on back.
Computer Scientist Exam Report
Grace Hopper has an exam average of 82.02
Alan Kay has an exam average of 83.04
John Backus has an exam average of 92.12
Sergey Brin has an exam average of 85.50
Dennis Ritchie has an exam average of 98.99
Brian Kernighan has an exam average of 97.40 ?????? has an exam average of ????
There were 7 student records in the file.
All files are closed and report is written. Goodbye
Last Completed Projects
topic title | academic level | Writer | delivered |
---|