When two or more functions have the same name how does the


1. Write a program that reads in an integer from the keyboard and displays its value doubled, using two functions that you write. The reading function should be int and the displaying function should be void.

2. How does the use of inline speed up the execution of a program? What is the disadvantage of using inline?

3. What is the output produced by the following program? Explain.

#include
using namespace std;
void testfunc(int x, int y = 10) {
cout << x + y;
}
int main () {
testfunc(3);
return 0;
}

4. What is the output of the following program? Explain.

#include
using namespace std;
void f(int i, int &j) {
i = 5;
j = j + i;
cout << "f: i = " << i << endl;
cout << "f: j = " << j << endl;
}
int main () {
int i = 15;
int j = 30;
f(i, j);
cout << " main: i = " << i << endl;
cout << " main: j = " << j << endl;
}

5. Write a program that reads in two integers from the keyboard and displays their sum. The reading function should read in both integers at the same time. Both the reading and displaying functions should be separate void functions.

6. What is the output of the following program? Explain.

#include
using namespace std;
float someNum = 3.0;
int main () {
int someNum = 2;
cout << someNum << endl;
cout << ::someNum << endl;
return 0;
}

7. When two or more functions have the same name, how does the compiler determine which one to use for a particular function call?

8. Write a void function called swap that takes two integer parameters and swaps their contents. Write another swap function that takes two double arguments. Write a short main function that calls both swap functions and demonstrates that the contents have been swapped. Cout statements should only appear in function main.

9. Why do we have both debug and release builds?

10. What is the difference between step over, and step into?

11. Find and describe the errors in the following program. Use the debugger.

//this program computes how much money will
//accumulate after so many years of investing
#include
using namespace std;
double Balance = 0.0;
double Interest;
double YearlyCont;
int NumYears;
//this function computes one year of investment
double newBalance(double balance);
int main () {
cout << "How much money will you deposit"
<< "each year?" << endl;
cin >> YearlyCont;
cout << "What interest rate will you get"
<<"(enter 5% as .05)?" << endl;
cin >> Interest;
cout << "How many years will you invest?"
<< endl;
cin >> NumYears;
for(int i = 1; i <= NumYears; i++);
Balance = newBalance(Balance);
cout << "Money at end of investment: "
<< Balance << endl;
return 0;
}
double newBalance(double balance) {
//add in this year's deposit
balance = balance + YearlyCont;
//add in this year's interest
balance = (Interest + 1.0) * Balance;
return balance;
}

Solution Preview :

Prepared by a verified Expert
Programming Languages: When two or more functions have the same name how does the
Reference No:- TGS01256892

Now Priced at $20 (50% Discount)

Recommended (90%)

Rated (4.3/5)