Question
Use only the C programming language PROBLEM: The user of your program will use it to do some elementary floating point calculations for an unknown
Use only the C programming language
PROBLEM:
The user of your program will use it to do some elementary floating point calculations for an unknown number of simple data sets. Each data set consists of a list of floating point values, but the number of values to be entered will be specified by the user, so you do not know in advance how many values there will be in each data set. Additionally, you do not know in advance how many data sets the user will enter. Therefore, you cannot use a static array to store any of these values.
First, you should prompt the user to enter the number of data sets. The user will enter an integer greater than or equal to 1 to indicate the number of data sets. (NOTE: Make a point to test your program to ensure entering just 1 data set works.)
You should then prompt the user to enter the number of floating point values in each data set (which the user will enter as an integer greater than 0), followed by the floating point values themselves on the same line (newline will follow the last floating point value on the line). You can assume that the user will enter the input in this format, so you do not need to check to make sure that the format of the input meets this description, and you do not need to reject input which is not properly formatted. You can also assume that the users input is correct. That is, that the number of data sets entered is actually the number of data sets in the input and that the integer entered first to indicate the number of values for each data set is actually the number of floating point values that follows on the same input line. Your program needs to read the user input and store the floating point values in each data set in a dynamically allocated array of the appropriate size. If you do not completely understand this description jump to the bottom of this file and check out the example data. (NOTE: Make a point to test your program to ensure that entering just 1 floating point value on a line works. e.g. there is only one float value in the dataset and all of the functions described below calculate correctly.)
After getting the values in each data set, your program should repeatedly do the following two things:
1.Print the following prompt:
Enter the number of the data set on which you wish to do calculations:
The user will enter an integer value, followed by newline, in response to this prompt (the user will enter 1 for the first data set, 2 for the second, etc.), then based on the value entered, your program must be able to access the values in the appropriate data set in the dynamically allocated storage which you have created. Then do what is described immediately below.
2. Your program should then prompt the user to choose one of the following options for a calculation based on the data set chosen by the user (ask the user to enter one of the six numbers, followed by enter):
1) Find the minimum value.
2) Find the maximum value.
3) Calculate the sum of all the values.
4) Calculate the average of all the values.
5) Print the values in the data set.
6) Exit the program.
After the user selects one of the six options, your program should perform the necessary calculation or print the specified data or terminate the program. The program should output the result with an appropriate message, for example:
The maximum value in data set 4 is: 567.37
The results for options 1, 2, 3, and 4 should be printed out as floating point values with 2 digits of precision, and the result for option 5 should be to output the values in the data set in the order in which they were input, with two digits of precision for each value, and with any two values separated by a tab (\t).
After your program outputs the result of the operation, it should prompt the user again to select one of the data sets, and then one of the six options until the user selects option 6 to exit the program.
CONSTRAINTS:
-You cannot use statically declared arrays for this lab, as explained above.
-Your code should work correctly for ANY NUMBER of input data sets (including just 1), and for any number of values in each data set (including just 1 and up to the limits of available memory, of course), and these numbers are not known in advance.
-You will need to use pointers to do all of the calculations (options 1 to 5). You will not be able to access any of the allocated storage space using indexes, as is usually done for a conventional array, but only by using pointers and pointer arithmetic. Use a separate function to do each type of calculation (some of these functions might call other ones for example, option 4 might call option 3).
-Use a separate function to do each type of calculation (some of these functions might call other ones for example, option 4 might call option 3).
- Use a function to get the input from the user about the number of data sets, to get the number of values in each data set, and to read in the values in the data set; you can use the same function to get all three items or you can create a separate function for each of the 3. Use a separate function to get the user's choice of the calculation to perform. Use a different function for each of the 5 options. Be sure to document what each function does.
-Even though you will have several functions, all code must be in a single file named lab2.c
-Your program should be able to work whether it receives input from the command line (e.g.keyboard) or via redirected (stdin) input from a file. Note: Since input from a file is being accomplished via redirection of stdin from the command line, no changes to your code should be necessary. Testing it both ways would be a great way to verify this.
Use only C programming language.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started