Question: Write a C++ program that does the following: (a) Ask for a file name from which data will be read, giving the option to enter

Write a C++ program that does the following:

(a) Ask for a file name from which data will be read, giving the option to enter def to use a default value;

(b) Test the value entered to see if def was entered. If so, use M2-P2- data2Read.dat as the default filename;

(c) Count the number of lines in the data file; if you are unable to get it, use 100 from here on;

(d) Read the provided data file one line at a time, and process the data on each line according to the value of w as follows: if w is add, calculate x + y if w is sub, calculate x y if w is mult, calculate x y if w is div, calculate x/y if by any chance you are unable to read the file, set values for w, x and y and make sure to include the if statements that will perform the correct operation;

(e) Print the result for each line in a file, one value per line;

(f) (5 points) in addition, for the first 10 lines of data, print to screen the operation performed; for example, if line 4 was mult 4.0 1.5, print line 4: 4.0*1.5=6.0

File has 487 lines. First few are: mult 4.25 4.56 div 7.64 1.01 div 6.51 2.46 mult 8.90 6.16 mult 7.40 8.53 sub 3.05 7.15 sub 9.51 6.16 sub 5.79 1.60 add 5.30 8.87 sub 8.09 1.65 mult 6.32 3.29 div 9.74 8.52 div 1.46 7.37 div 7.40 2.23 mult 5.94 3.05 sub 4.55 8.39 div 3.41 7.13 add 1.95 6.58 div 9.70 5.41 sub 2.80 5.04 add 1.44 4.16 add 9.58 9.71 sub 7.21 0.60 sub 9.36 2.40 div 4.95 6.71 sub 7.95 6.34 add 6.75 3.34 sub 3.70 3.06

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!