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...

  • 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...

  • 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;        ...

  • 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...

  • May i ask for help with this c++ problem? this is the code i have for assignment 4 question 2: #...

    may i ask for help with this c++ problem? this is the code i have for assignment 4 question 2: #include<iostream> #include<string> #include<sstream> #include<stack> using namespace std; int main() { string inputStr; stack <int> numberStack; cout<<"Enter your expression::"; getline(cin,inputStr); int len=inputStr.length(); stringstream inputStream(inputStr); string word; int val,num1,num2; while (inputStream >> word) { //cout << word << endl; if(word[0] != '+'&& word[0] != '-' && word[0] != '*') { val=stoi(word); numberStack.push(val); // cout<<"Val:"<<val<<endl; } else if(word[0]=='+') { num1=numberStack.top(); numberStack.pop(); num2=numberStack.top(); numberStack.pop();...

  • In C please Write a function so that the main() code below can be replaced by...

    In C please Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original maino: int main(void) { double milesPerHour, double minutes Traveled; double hours Traveled; double miles Traveled; scanf("%f", &milesPerHour); scanf("%lf", &minutes Traveled); hours Traveled = minutes Traveled / 60.0; miles Traveled = hours Traveled * milesPerHour; printf("Miles: %1f\n", miles Traveled); return 0; 1 #include <stdio.h> 3/* Your solution goes here */ 1 test passed 4 All tests passed...

  • Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The...

    Need help problem 9-13 C++ Homework please help 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 maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...

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
ADVERTISEMENT