Starting from:
$10

$4

Homework 1 Solution

The purpose of Homework 1 is brushing up C++ skills and warming up for future programming assignments. The program has the following functionality:




Once it starts, it asks the user to type the input file name (a txt file). The print out information must be:



Please input the filename:




The program uses the file name to open the file. The file has a number of lines. Each line has two numbers separated by a comma. Therefore, there are actually two columns of numbers. For example:



312312, 56877 2267, 3698 3, 3478 87907, 768




The program processes the input data to calculate the average value of all numbers in the first column and the largest value of all numbers in the second column. The print out should be



The average value of all numbers in the first column: XXX.XXXX




The largest value of all numbers in the second column: XXXXX




The total number of rows in the file is: XXXX




The invalid numbers are: XXX, XXX, XXX, …




Requirements:




[will be 0 if it does not compile or crash] The homework must be done in C++. Although you can use any IDE to do the homework, your code must work under Code::Blocks since the grader will use it to grade your homework.



[5%] The Following identification information must be included at the beginning of your cpp file.



//Name: XXXXXXX




//Email: XXXX@csueastbay.edu




[5%] The output average value should retain 4 decimal digits.



[10%] The program must use cin and cout to deal with command line input and output.



[10%] The program must ask user to input again without crashing if users input invalid file names.



[10%] The program must use arrays to solve the problem.



[30%] Students must implement loops by themselves to calculate the average and to find the largest value, invalid numbers, and number of rows.



[30%] There are invalid numbers (like 1P24…) in the input data file, make sure those numbers will be recognized and abandoned by your program without crashing.

More products