Laboratory #10 Solution






-Please submit only C++ source files (*.cpp) through the Blackboard Vista. -Please put your name, project description, and date on the top of your file as a comment. -PLEASE WORK ALONE. If cheating is found, you will get ZERO.


  1. (Lastname_Lab10_p1.cpp, 20 points)


Amaya A 10031 9.82 12/18/13
Cecilia W 10067 9.14 6/9/13
Karida B 10083 8.79 5/18/12
Janney P 10095 10.57 9/28/12


Write a C++ program to read the employee.txt file and produce a duplicate copy of the file named employee.bak. Accept the names of the original and duplicate files as user input. (You can provide a default duplicate file name for users.)


  1. (Lastname_Lab10_p2.cpp, 20 points)

Write a program that opens a file and display the contents of the file with associated


line numbers. That is, the program should print the number 1 before displaying the first line, and then print the number 2 before displaying the second line, and so on for each line in the file.


  1. (Lastname_Lab10_p3.cpp, 20 points)

Create a text file containing the following: car numbers, miles driven, and gallons of


gas used in each car (do not include the headings):


Car Number Miles Driven Gallons Used
21 260 21
61 121 7
72 625 39
89 1411 89
93 233 15


Write a program that reads the data in the file and displays the car number, miles driven, gallons used and the miles per gallon for each car. The output should also contain the total miles drive, total gallons used, and average miles per gallon for all the cars. These totals should be displayed at the end of the output report.


  1. 4. (Lastname_Lab10_p4.cpp, 20 points)


Write a program that accepts lines of text from the keyboard and writes each line to a file named text.dat until an empty line is entered. An empty line is a line with no text that is created by pressing the Enter (or Return) key.


  1. (Lastname_Lab10_p5.cpp, 20 points)



Write a program that skips leading whitespace characters in each line of the provided data file verse.txt. Save the results in a new file.


  1. (OPTIONAL, Lastname_Lab10_p6.cpp, 20 points)


Write a program that removes the blank lines in verse.txt and saves the results in a new file. (You can combine p5 and p6 to get a new file without leading whitespaces and blank lines.)

error: Content is protected !!