Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ - Using pass by reference parameters and function overloading Part 1 - Write a function that will swap two integers values using pass-by-reference (i.e.

C++ - Using pass by reference parameters and function overloading

Part 1 - Write a function that will swap two integers values using pass-by-reference (i.e. alias) parameters. Write a driver program to test your function. Your function will have two parameters...if you code them as "pass by value," on return to "main," they will not be switched, but instead will retain their original values...thus the importance of pass-by-reference.

Part 2 - Write a function with the following prototype...notice parameters "one" and "two" are pass-by-value:

bool compute(int one, int two, int & sum, int & product, int & quotient);

compute sum to be one plus two, compute product to be one times two,

compute quotient to be one divided by two provided that two is not 0.

If the quotient can be computed (i.e. two is not 0) "compute" will return true, otherwise it will return false.

Main will output the returned sum, product and quotient.

Part 3 - Overload the sum functions by using a different set of parameters for the four sum functions prototypes below... (notice we do not use reference parameters...only value parameters): int sum(int, int);

int sum(int,int,int);

int sum(int,int,int,int);

int sum(int,int,int,int,int);

Each of the four sum functions should return the sum of all of it's int parameters.

You can write your code so that each of the last 3 sum functions calls the one listed before it. For example, inside the function with 4 parameters will be the call to the function with 3 parameters and likewise for the remaining two functions.

Part 4 - (Use box.cpp) This part does not use reference parameters, only value parameters, but does use "overloaded" displayBox functions...the four prototypes are as follows:

void displayBox ( int length );

void displayBox ( int length, char fillChar );

void displayBox ( int width, int height );

void displayBox ( int width, int height, char FillChar );

The 3-argument function will use nested for loops for its logic. The other overloaded functions do not use any logic other than a calling statement to the 2 argument function or the 3 argument function.

The 2-arguments functions will call the 3-argument function and the 1-argument function will call the 2-argument function.

Use input data of 5 ? 15 4 $

Calling displayBox(5) will display

xxxxx

x x

x x

x x

xxxxx

Calling displayBox(5,7, a ) will display

xxxxx

xaaax

xaaax

xaaax

xaaax

xaaax

xxxxx

Part 5 - Write a function that has two parameters - an integer that is a test score and a second parameter that is the letter grade. Use the standard grading scale for A, B, C, D, F.

If the score is above 100 or below 0, a grade will not be assigned and a return value of false will be returned. If the score is within range, a return value of true will be returned and the letter grade will be returned.

The prototype for the function is: bool figureGrade(int, char &);

Write "main" to test the function you have written...main will output the letter grade which the function calculated and returned to main via the parameter letterGrade.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions

Question

Can MGA establish that Mattel stole its trade secrets?

Answered: 1 week ago

Question

How should the profits be shared between her and her cousin?

Answered: 1 week ago

Question

=+ (b) Show that the reverse implication holds if 22 is countable.

Answered: 1 week ago

Question

Define induction and what are its objectives ?

Answered: 1 week ago

Question

Discuss the techniques of job analysis.

Answered: 1 week ago

Question

How do we do subnetting in IPv6?Explain with a suitable example.

Answered: 1 week ago

Question

Explain the guideline for job description.

Answered: 1 week ago

Question

What is job description ? State the uses of job description.

Answered: 1 week ago