Question

answer in c++ Using the table below, complete the C++ code to write the function prototype...

answer in c++

  1. Using the table below, complete the C++ code to write the function prototype statement, and the void function header.

The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for the calcQuotient function. In addition, write a statement that invokes the calcQuotient function, passing it the n1, n2 and quotient variables.

Function Prototype:

Function Call:

int main()

{

double n1 = 10;

double n2 = 5;

double quotient = 0;

calcQuotient(n1, n2, quotient);

cout << "Quotient: " << quotient << endl;

return 0;

}//end of main function

Function Header:

__________________________________________

{

answer = num1 / num2;

}

  1. A program’s main function declares three double variables named sales, taxRate, and salesTax. The main function contains the following statement: calcSalesTax(sales, taxRate, salesTax);. The calcSalesTax function is responsible for calculating the sales tax based on the sales and tax rate passed to it. Its function header looks like this: void CalcSalesTax(double sold, double rate, double tax).

Correct the function prototype and the function header.

Function Prototype

CalcSalesTax(double sold, double rate, double tax);

CORRECTION:

Function Call

calcSalesTax(sales, taxRate, salesTax);

Function Header

CalcSalesTax(double sold, double rate, double tax)

CORRECTION:

  1. Using the table below, complete the C++ code to create a void function that receives four int variables: the first two by value and the last two by reference. Name the formal parameters n1, n2, sum, and diff. The function should calculate the sum of the two variables passed by value and then store the result of the first variable passed by reference. It also should calculate the difference between the two variables passed by value and then store the result in the second variable passed by reference. When calculating the difference, subtract the contents of the N2 variable from the contents of the n1 variable. Name the function calcSumAndDiff. Also write an appropriate function prototype for the calcSumAndDiff function. In addition, write a statement that invokes the calcSumAndDiff function, passing it the num1, num2, numSum, and numDiff variables.

I recommend you test out the code to check that all is working properly.

Function Prototype

Main() with Function Call

int main()

{

int num1 = 10;

int num2 = 5;

int numSum = 0.0;

int numDiff = 0.0;

__________________________________________

cout << "Sum: " << numSum << endl;

cout << "Difference: " << numDiff << endl;

}

Function Definition

__________________________________________

{

sum = n1 + n2;

diff = n1 - n2;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

question:1

code:

#include <iostream>
using namespace std;
void calQuotient(double num1, double num2,double &answer); //functoin protype
int main()
{
double n1=10;
double n2=5;
double quotient=0;
calQuotient(n1,n2,quotient);
cout<<"Quotient: "<<quotient<<endl;
return 0;
}
void calQuotient(double num1, double num2,double &answer) //function defination
{
answer=num1/num2;
}

OUTPUT:

Quotient: 2

screenshot:

Question :2

code:

#include <iostream>
using namespace std;
void calSalesTax(double sold,double rate,double tax); //function prototype
int main()
{
double sales,taxRate,salesTax;
calSalesTax(sales,taxRate,salesTax);
return 0;
}
void calSalesTax(double sold,double rate,double tax) //function defination
{
  
}

screenshot:

Question 3:

code

#include <iostream>
using namespace std;
void calSumAndDiff(int n1,int n2,int &sum,int &diff); //function prorotype
int main()
{
int num1=10;
int num2=5;
int numSum=0.0;
int numDiff=0.0;
calSumAndDiff(num1,num2,numSum,numDiff);
cout<<"Sum:"<<numSum<<endl;
cout<<"Difference:"<<numDiff<<endl;
return 0;
}
void calSumAndDiff(int n1,int n2,int &sum,int &diff) //function defination
{
sum=n1+n2;
diff=n1-n2;
}

OUTPUT;

Sum:15
Difference:5


screenshot:

Add a comment
Know the answer?
Add Answer to:
answer in c++ Using the table below, complete the C++ code to write the function prototype...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab 6.6 – Using Value and Reference Parameters Below is a copy of the source code....

    Lab 6.6 – Using Value and Reference Parameters Below is a copy of the source code. 1 // Lab 6 swapNums.cpp -- Using Value and Reference Parameters 2 // This program uses a function to swap the values in two variables . 3 // PUT YOUR NAME HERE. 4 #include <iostream> 5 using namespace std; 6 7 // Function prototype 8 void swapNums(int, int); 9 10 /***** main *****/ 11 int main() 12 { 13 int num1 = 5, 14...

  • Create a program with the main function and one additional function. The additional function asks for...

    Create a program with the main function and one additional function. The additional function asks for input from the user and returns the output back to the main function for display. This is for c++ and here is my code, could you guys please tell me what I am missing from the instructions. Thank you #include <iostream> using namespace std; int sum (int, int); int main() {     int n1, n2, total;               cout << "Enter two numbers...

  • Fix this code so only the function prototype comes before main. #include <iostream> using namespace std;...

    Fix this code so only the function prototype comes before main. #include <iostream> using namespace std; bool isMultiple(int num1, int num2) { return num1 % num2 == 0; } int main() { char ch = 'Y'; int num1, num2; while(ch =='Y') // While ch is equal to Y { cout << "Enter two numbers(largest first): "; cin >> num1; // Getting 1st number cin >> num2; // Getting 2nd number if(isMultiple(num1, num2)) cout << num2 << " " << "IS...

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • need help on this! Just write the function prototype for the following finctions while also using...

    need help on this! Just write the function prototype for the following finctions while also using the variables below to help write the prototype! thanks!! WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in main(). I 1.) showMenu 2.) getChoice 3.) calcResult 4.) showResult 5.) getlato 6.) showName 7.) calcSquare 8.) is Positive int main() USE THESE VARIABLES, when needed, to function...

  • C++ I am using visual studio for it. Make a copy of the Rational class you...

    C++ I am using visual studio for it. Make a copy of the Rational class you created in the previous Lab. Modify the class. Replace all your mathematical, input, and output functions with overloaded operators. Overload the following 12 operators: + - * / < > = = ! = <= >= >> << In order to test your class in your main function, prompt the user for a numerator and a denominator for your first object. Repeat the prompt...

  • 81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5...

    81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5 );                    int BoxVolume(int length = {1}, int width = {1}, int height = {1});                                                     T__   F__                                                                     82. The following function is implemented to swap in memory the          argument-values passed to it:         void swap(int a, int b)                   {           int temp;             temp = a;             a = b;             b = temp;        ...

  • c++ 1) Write a header file that contains the prototype for a function that takes two...

    c++ 1) Write a header file that contains the prototype for a function that takes two value parameters (both floats) and returns a single character output. The function name is “charIn”. We do not care what the function does at this point. (8) 2)   Fix the Errors of the C++ program: a.   #include <cmath> b.   Void main(){cout<< “Math test”<<endl;//start math test c.   Int i=10 int j=3 k=i%3 cout << “test of mod<<k<<endl d.   Float d=0 float f=e/d cout << “div...

  • Using a programming language of your choice, write a complete and fully functional program that uses...

    Using a programming language of your choice, write a complete and fully functional program that uses reference and pointer types to swap two integer numbers. The two numbers are read in separately by the program’s user. Use a proper prompt for each number read in. a. Use one function that uses formal parameter reference type to swap the two numbers b. Use another function that uses formal parameter pointer type to swap the two numbers. c. In the main or...

  • 6. (Short answer) The C++ code below is very close to working, but, as written, won't...

    6. (Short answer) The C++ code below is very close to working, but, as written, won't compile. When trying to compile, the compiler generates a number of errors similar to "cout' was not declared in this scope." Respond to the prompts below about the code.(20 points, 5 points each) #include <iostream> void FindMax(int a, int b, int& max) { if (a > b) max = a; else { max = b; } int main() { int num1 = 0; int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT