Write a C++ program that reads data from a data file called “temp.dat”. The data file contains a maximum of 31 daily integer temperature values for a city. Your program should continue displaying the following menu until the user selects exit (option No. 6).

Head of the data
Tail of the data
Calculate average
Calculate standard deviation
Count days
Exit

Your program should use arrays to store the data and should have at least the following user defined functions:

Head_data: Print the first M elements of the data. The positive integer M is provided by the user and passed to the function as an argument together with the data array and its number of elements. Note that if M is greater than the number of elements in the file, Head_data function will print all elements.    
Tail_data: Print the last M elements of the data. The positive integer M is provided by the user and passed to the function as an argument together with the data array and its number of elements Note that if M is greater than the number of elements in the file, Tail_data function will print all elements.   
Average_temp: Calculates and returns the average temperature of the records. It takes as arguments the data array and its number of elements (see EQ 1).
Std_dev: Calculates and returns the standard deviation of the temperatures records. It takes as arguments the data array and its number of elements ( see EQ 2).
Count_days:  In addition to the data array and its number of elements, it takes two additional parameters (lower_temp & higher_temp) and returns the number of days where temperature was recorded between the two values (inclusive).

Equations you might need:

μ=1/N ∑_(i=1)^N▒x_i

σ=√(1/N ∑_(i=1)^N▒(x_i-μ)^2 )

Your program should display an error message if wrong option is entered. The output of your program should look like the sample runs shown in Figure 1 – Figure 8.

Note: You are required to submit your algorithm for this assignment.

Recommended Answers

All 2 Replies

Do your homework, if you encounter any difficulty, post your code and we all be glad to help you out.
The difficulty : "Help, don't know where to start!" does not count.

void Head_data (int[]);
void Tail_data (int[]);
int Average_temp (int[],float&);
int Std_dev(int[],float&);
void Count_days (int[],int&);

are the prototyps correct???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.