Question

Write a C++ program which consists of several functions besides the main() function. 1)   The main()...

Write a C++ program which consists of several functions besides the main() function.

1)   The main() function, which shall ask for input from the user (ProcessCommand() does this) to compute the following: SumProductDifference and Power. There should be a well designed user interface.
2)   A void function called SumProductDifference(int, int, int&, int&, int&), that computes the sum, product, and difference of it two input arguments, and passes the sum, product, and difference by-reference.
3)   A value-returning function called Power(int a, int b) that computes a raised to the b power. Design and implement your own power function using an iterative control structure, or even recursion. Do not simply write a wrapper around the C++ function called pow().
4)   There should be a user loop and a menu so that the user can select either SumProductDifference, Power, or Quit. Then ProcessCommand() should ask the user for two values to compute SumProductDifference or Power. ProcessCommand() should then also output the answer.

Homework Answers

Answer #1

#include <iostream>
using namespace std;
void SumProductDifference(int x,int y,int &sum,int &product,int &diff)
{
sum=x+y;
product=x*y;
diff=x-y;
}
int power(int a,int b)
{
int r=1;
for(int i=1;i<=b;i++)
r=r*a;
  
return r;
}
void ProcessCommand(int &x,int &y)
{
cout<<"Enter two numbers :";
cin>>x>>y;
}
int main()
{
int x,y,sum,product,diff;
ProcessCommand(x,y);
SumProductDifference(x,y,sum,product,diff);
cout<<"Sum = "<<sum<<"\nProduct= "<<product<<"\nDifference ="<<diff;
cout<<"\nPower of "<<x<<"to "<<y<<" is :"<<power(x,y);

return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write the functions which are called in the main function given. YOU MAY ASSUME THAT THE...
Write the functions which are called in the main function given. YOU MAY ASSUME THAT THE USER ENTERS A VALID INTEGER. printDouble should accept one value and should print the value of that number times 2. printEndMessage should not accept any values and should print a message indicating that the program has finished. def main(): num1 = int(input("Please enter your number ")) printDouble(num1) printEndMessage() main()
c++ please 1. Write and test the function maximum that is passed an array of n...
c++ please 1. Write and test the function maximum that is passed an array of n pointers to integers and returns the maximum value among the n integers. The function must use the traveling pointer notation to traverse the array. you have to ask the user for the size of the array and ask the user to input the values in the main. The function has the following prototype. int maximum ( int *p [ ], int n);
Write a C++ program to compute the value of x * (x + 1) + y...
Write a C++ program to compute the value of x * (x + 1) + y * y + z * (z - 1) where x, y, and z are 3 floating point numbers entered by the user. Requirements: • You should have a function get3numbers() that asks the user to enter 3 numbers. • You should have a function computeExp() that computes the value of the expression. • Your main function should call the above 2 functions and get...
Write in C++ a function int sumofdigits( int n ) which computes and returns the sum...
Write in C++ a function int sumofdigits( int n ) which computes and returns the sum of the digits of n. Use the following main function to test your code: int main() { int n, sn; cout << "Enter q to quit or an integer: "; while ( cin >> n ) { sn = sumofdigits(n); cout << "sumofdigits( " << n << " ) = " << sn; cout << "\nEnter q to quit or an integer: "; }...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to N. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from -1 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float). The main function should be responsible for all inputs and outputs. Your...
Programming in C language (not C++) Write a main function with a function call to a...
Programming in C language (not C++) Write a main function with a function call to a function called Calculation which has two integer arguments/ parameters. The function returns a character. Declare and initialize the necessary data variables and assign balues needed to make it executable and to prevent loss of information. //input 2 integer values //returns the characterequivalent of the higher of the two integer values char Calculation(int, int);
PYTHON: Write a function called keepShouting. This function does not need any input parameters. The function...
PYTHON: Write a function called keepShouting. This function does not need any input parameters. The function should simply repeat whatever the user enters but in all capitals! The function should ask the user to enter a phrase. The phrase then should be capitalized and printed to the screen. If the user just hits return (which will produce the empty string) then the program should stop. Hint: Use a while loop and string methods # keepShouting() """ The function call should...
1) Write a function in C that takes in a single integer parameter and returns an...
1) Write a function in C that takes in a single integer parameter and returns an array of factors. The function signature should be : int* get_factors(int number) To make things a little easier, assume that the input (number) will never have more than 100 factors. The returned array should be null-terminated. 2) Write a main() function that asks a user for a number, calls the function above, then prints the results.
A) write a program the computes nx and store the result into y You can use...
A) write a program the computes nx and store the result into y You can use y = Math.pow( Mantissa, exponent) Requirements: Besides main() your program must have one method with two parameters, one double and one int n and x are positive numbers read from the keyboard if the user makes an entry that does not meet this criteria, the user must be given to opportunity retry the entry the user must be able to quit prior to entering...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT