- #1
Lord Dark
- 121
- 0
Homework Statement
Hi everyone ,, I've got the following assignment and it's very hard for me ,, I couldn't understand half of it ,, that's if it's not all -_-
The assignment is :
Consider a set of sensors installed at different locations of pipe carrying crude oil. These sensors periodically (say every 10 minutes) measures the pressure inside the pipe and record that value in a text file. Your task is to write a menu driven C++ program that will allow the user to process the data files generated by these sensors. Example of sensor data files are shown in Figure 1. The program should provide the user with the following options:
1. Read sensor data.
2. Find maximum pressure of a given sensor
3. Find average pressure of a given sensor
4. Find percentage of readings of a given sensor that are above the overall average
5. Find overall maximum reading and its sensor number.
6. Find overall average pressure
7. Write a summary to a text file
8. Exit the program
Please note the following:
• The maximum number of sensors is 10 and each sensor file can contain at most 100 readings.
• You are not allowed to declare any global variables. Constants however can be global.
• Only one array (data array) of double values should be used to store data from all sensor files. Another array (sensors array) of integers should be used to store the sensor number for each corresponding reading. Figure 2 shows both arrays after reading data from three input files.
Your program should use the following functions:
• menu (. . . ): this function displays the above menu and returns the user choice.
• readSensorData (. . . ): this function receives both arrays, a sensor number and the array size. It should then read the data from an input file whose name is provided by the user to the data array. The sensors array should also be modified to reflect the changes (as illustrated in Figure 2). The function should also check the file, display an error message if it could not open it and return false. Otherwise, it returns true. The function should also return the new array size through the size parameter.
• findMaxIndex ( . . . ): this function receives both data and sensors arrays, a sensor number and the array size. It returns the index of the maximum pressure reading for the given sensor number.
• findAverage ( . . . ): this function receives both data and sensors arrays, a sensor number and the array size. It returns the average pressure for the given sensor number.
FindPercentage ( . . . ): this function receives both data and sensors arrays, a sensor number and the array size and returns the percentage of the pressure values from the given sensor that are above the overall average pressure.
• findOverallAverage ( . . .): this function receives the data array and the array size. It then returns the overall average of all pressure readings in the data array.
• findOverallMaxIndex ( . . .): this function receives the data array and the array size. It then returns the index of the maximum pressure value in the data array.
• generateReport (. . . ): this function receives both data and sensors arrays and the array size and prints a summary report to an output file whom name is provided by the user. The function also displays a message on the screen indicating that the file has been written correctly or otherwise there have been an error while writing. Figure 3 shows a sample summary report.
Homework Equations
The Attempt at a Solution
OK ,, am at the first step which is making a read function ,, but my problem is that when I let it read a sensor text more than once it tell me to press any key to continue but I want it to continue until the user enters 10 sensors ... and the other problem is when the user press other than numbers the program goes up and down (due to while thing) and I don't know how to fix it ,, help please
I need a code for while so when I press a word like (w) it won't repeat by at self at infinity
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std ;
const int s_max = 100 ;
const int r_max = 100 ;
int menu(int choose) ;
void readSensorData(double r[],int s[],int &snum,int &count) ;
int main ()
{
static int snum(1) ;
double r[r_max] ;
int s[s_max] ;
int read(0), choice(0),c(0),count(0);
do {
choice = menu(c) ;
if ( choice < 0 && choice > 8)
choice = menu(c) ;
else
{
switch (choice)
{
case 1:
readSensorData(r,s,snum,count) ;
break;
case 8:
return 0 ;
}
} (while (what should I write here ??))
}
Attachments
Last edited: