Write a C++ program that does the following: Your main function will display a menu with the following options: 1- Calculate average 2- Calculate minimum 3- Calculate maximum 4- Write data to a file 5- Read data from a file 6- exit You will need to implement the above menu using the switch selection structure. You need to validate that the user enters a valid value (an integer between 1 – 6). The logic will keep looping non-stop till the user enter “6” which means the program will exit When the user enters “1” (calculate average), you need to call a function called calcAverage that returns nothing and accept no parameter. When the user enters “2” (calculate minimum), you need to call a function called calcMinimum that returns an integer and accept no parameter. Then the main function will print the value returned from that function When the user enters “3” (calculate maximum), you need to call a function called calcMaximum that returns nothing and accept no parameter. When the user enters “4” (write data to a file), you need to prompt the user for the file name. Then you need to call a function called writeFile that returns nothing and accept one parameter which is the file name you just got from the user. When the user enters “5” (read data from a file), you need to call a function called readFile that returns nothing and accept no parameter. calcAverage function: This is function that returns no value and accept no parameters. This function will do the following: Ask the user to enter how many integers to enter. This has to be a positive integer and you need to validate that Write a “for” loop to accept this many integers and write the needed logic to calculate the average of these numbers and print that out Then the function will return back to the main function calcMinmum function: This is function that returns an integer and accept no parameters. This function will do the following: Use the while loop to implement the below logic Allow the user to enter integers (you need to at least enter one integer) The logic will keep ask the user to enter values until the user enter -99 which means he does not need to enters any more numbers This -99 should not be considered when you calculate the minimum number The function will return the minimum value back to the main function to be displayed there calcMaximum function: This is function will not return any value and accept no parameters. This function will do the following: Use the do … while loop to implement the below logic Allow the user to enter integers (you need to at least enter one integer) The logic will keep ask the user to enter values until the user enter 99 which means he does not need to enters any more numbers This 99 should not be considered when you calculate the maximum number The function will display the maximum value found The function will return back to the main function writeFile function: This function will accept one string parameter from the main function and will return nothing back. This function will do the following: Try to open a file for write. The name of the file is the string passed to the function Use any looping structure to accept strings from users and use any stopping criterion of your choice Write these strings to the file one string per line Close the file Return back to the main function readFile function: This function will accept no parameters from the main function and will return nothing back. This function will do the following: Accept a string from the user for the file name to be open and run. You need to validate that such file exists to be open or prompt the user to enter a valid name. You can use the file you created in the writeFile function above. Read and display the values from the file. You can assume that you will have a string per line in that file Close the file Return back to the main function
Write a C++ program that does the following:
- Your main function will display a menu with the following options:
- 1- Calculate average
- 2- Calculate minimum
- 3- Calculate maximum
- 4- Write data to a file
- 5- Read data from a file
- 6- exit
- You will need to implement the above menu using the switch selection structure. You need to validate that the user enters a valid value (an integer between 1 – 6).
- The logic will keep looping non-stop till the user enter “6” which means the program will exit
- When the user enters “1” (calculate average), you need to call a function called calcAverage that returns nothing and accept no parameter.
- When the user enters “2” (calculate minimum), you need to call a function called calcMinimum that returns an integer and accept no parameter. Then the main function will print the value returned from that function
- When the user enters “3” (calculate maximum), you need to call a function called calcMaximum that returns nothing and accept no parameter.
- When the user enters “4” (write data to a file), you need to prompt the user for the file name. Then you need to call a function called writeFile that returns nothing and accept one parameter which is the file name you just got from the user.
- When the user enters “5” (read data from a file), you need to call a function called readFile that returns nothing and accept no parameter.
calcAverage function:
This is function that returns no value and accept no parameters. This function will do the following:
- Ask the user to enter how many integers to enter. This has to be a positive integer and you need to validate that
- Write a “for” loop to accept this many integers and write the needed logic to calculate the average of these numbers and print that out
- Then the function will return back to the main function
calcMinmum function:
This is function that returns an integer and accept no parameters. This function will do the following:
- Use the while loop to implement the below logic
- Allow the user to enter integers (you need to at least enter one integer)
- The logic will keep ask the user to enter values until the user enter -99 which means he does not need to enters any more numbers
- This -99 should not be considered when you calculate the minimum number
- The function will return the minimum value back to the main function to be displayed there
calcMaximum function:
This is function will not return any value and accept no parameters. This function will do the following:
- Use the do … while loop to implement the below logic
- Allow the user to enter integers (you need to at least enter one integer)
- The logic will keep ask the user to enter values until the user enter 99 which means he does not need to enters any more numbers
- This 99 should not be considered when you calculate the maximum number
- The function will display the maximum value found
- The function will return back to the main function
writeFile function:
This function will accept one string parameter from the main function and will return nothing back. This function will do the following:
- Try to open a file for write. The name of the file is the string passed to the function
- Use any looping structure to accept strings from users and use any stopping criterion of your choice
- Write these strings to the file one string per line
- Close the file
- Return back to the main function
readFile function:
This function will accept no parameters from the main function and will return nothing back. This function will do the following:
- Accept a string from the user for the file name to be open and run. You need to validate that such file exists to be open or prompt the user to enter a valid name. You can use the file you created in the writeFile function above.
- Read and display the values from the file. You can assume that you will have a string per line in that file
- Close the file
- Return back to the main function
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 8 images