Functions / Text Input / Calculations / Text Output

I'm in my first C++ class and just got an assignment. One thing I have major trouble understanding is how to use a function to read text and how to use a function or print text.

I'm going to hammer on this tomorrow, but there assignments are fun. Thought I'd share the project with you gents, & see if you have any input as well.

I'll hammer on this, post my progress, check responses, then repeat.

INSTRUCTIONS:

For this project you will write a program to compute the arithmetic mean (average), median, and mode for the values read in from TopicFin.txt. The program results will be written to TopicFout.txt.

The mode of a list of values is the score that occurs most often. The median is the value in the middle of the list. If there are an odd number of values in the list, then the median value can be determined by selecting the value at last / 2 where last is the last index that has a value in the array. If the list has an even number of values, then the median is the average of the value at last / 2 and last / 2 + 1. Using the list at the bottom of page 469 in the text, the median is the average of the values at index 2 (5 / 2) and index 3 (5 / 2 + 1)  5 + 7 / 2 = 6. So 6 is the median value of the list. Notice that 6 is not actually a value in the list.

The program will have a vector and an array. The vector will contain the values read in from the file. The array will contain those values in sorted order. You can assume that there will be no more than 1300 values. However, your program must handle files values less than 1300. You can assume that a file will have values and that these will be valid values.

At a minimum your program must have the following functions:
• readInput – This function reads the values in the file into the vector. It returns the sum of the values in the file. This is used by main to calculate the average. If the file cannot be found, the function should return a value of 0 for the total. This will prompt main to end the program. main will display an error message in this case.
• copy - A function to copy the vector data into the array.
• sort – This function is a void function which sorts the values. The sorted values are stored in the array. When the function ends, main should have the array with the sorted values and the vector with the values in their original order. Feel free to base your function on one of the text's sort functions.
• calculateMode – This is a void function which determines the mode of the array and how many times that value is in the list. This function requires that the list be sorted, therefore it uses the array not the vector.
• writeToFile – This void function writes the values in the list to the output file. There should be two of these functions, one for the array and one for the vector. That is, this function is overloaded.
Topic archived. No new replies allowed.