Question
c++ Rewrite Chapter 5 Programming Assignment(provided at bottom of the page) so that it utilizes functions. You will need at least 4 functions that are
c++
Rewrite Chapter 5 Programming Assignment(provided at bottom of the page) so that it utilizes functions. You will need at least 4 functions that are called by main: menu, summation, factorial, and exponential.
The functions operate as follows:
int menu() displays the menu and prompts for the user's choice and returns that choice.
void summation() prompts the user for their integer and then does the summation and the displays the result. It is passed nothing and returns nothing.
void factorial() is same as summation
void exponential is same as summation - make sure to use for loops to do the calculations and not pow or exp.
Each function should have it's own header block. It should state the name of the function, the purpose of the function and what it is passed or what it returns. These header blocks are created using comment lines within your code.
Rule #1: Absolutely no global variables. Variables used only inside of a function should be declared locally to that function. For example, if you have a counter variable down in Summation, then declare it locally to Summation. OR, if main() needs to know what choice the user made from the menu, then the function menu() returns that value. No global variables under any circumstances.
Same input validation requirements as when you submitted for Chapter 5.
Pseudocode for the main function might look like this: (I underlined a few side comments for you - but they are not part of the p-code.)
main()
int choice;
do
choice = displayMenu (this function will return the user's choice)
switch on choice
case 1
call function to handle summation
case 2
call function to handle factorial
case 3
call function to handle exponential
case 4
output goodbye statement
default
handle incorrect choice (ie, choice not 1-4)
end switch
while (choice not equal to 4)
end main
--------pseudocode for displaymenu function
int function displayMenu()
int userChoice //this userChoice is local to displayMenu function
output the menu
input the userChoice
return userChoice //here userChoice is being returned to main()
-------pseudocode for function summation
void function summation() //this function is passed nothing and returns nothing
declare total and maxNumber
initialize total
prompt for maxNumber
input maxNumber
while (maxNumber
output error message
input maxNumber
end while
for (counter = 1; counter
total = total + counter
end for loop
ouptut total, maxNumber...
return
------------
You need to supply the rest of the pseudocode when you submit your assignment.
#include "stdafx.h" #include
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