Predict the Output
7. What is the output of the following programs?
A) #include <iostream>
using namespace std;
int function(int);
int main()
{
int x = 10;
cout << function(x) << endl;
return 0;
}
int function(int num)
{
if (num <= 0)
return 0;
else
return function(num - 1) + num;
}
B) #include <iostream>
using namespace std;
void function(int);
int main()
{
int x = 10;
function(x);
return 0;
}
void function(int num)
{
if (num > 0)
{
for (int x = 0; x < num; x++)
cout << '*';
cout<< endl;
function(num - 1);
}
}
C) #include <cstdlib>
#include <string>
#include <iostream>
using namespace std:
void function(string str, int pos);
int main(int argc, char** argv)
{
string names = "Adam and Eve";
function(names, 0);
return 0;
}
void function (string str. int pos)
{
if (pos < str. length())
{
function(str, pos+1);
cout << str[pos]:
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 14 Solutions
STARTING OUT WITH C++ MPL
Additional Engineering Textbook Solutions
Artificial Intelligence: A Modern Approach
C Programming Language
Concepts of Programming Languages (11th Edition)
Database Concepts (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- Why do you need to include function prototypes in a program that contains user-defined functions? (5)arrow_forward#include using namespace std; || function declaration int max(int num1, int num2); int main () { // local variable declaration: int a = 100; int b = 200; int ret; I| calling a function to get max value. ret = max(a, b); cout num2) result = num1; else result = num2; return result; }arrow_forwardC PROGRAM Reverse + Random Formula In the code editor, there's already an initial code that contains the function declaration of the function, computeReverseNumber(int n) and an empty main() function. For this problem, you are task to implement the computeReverseNumber function. This function will take in an integer n as its parameter. This will get the reverse of the passed integer and will then compute and return the value: result = (original_number + reverse_of_the_number) / 3 In the main() function, ask the user to input the value of n, call the function computeReverseNumber and pass the inputted value of n, and print the result in the main() with two (2) decimal places. SAMPLE: Input n: 20 Output: 7.33 Input n: 123 Output: 148.00arrow_forward
- Use the code provided to you to do the following: 1) Write code that implements the function withdrawal. 2) Deposit 1000 into checking account. 3) Deposit 500 into saving account. 4) Withdraw 100 from checking account. 5) Get balance for both checking and saving account and display the amounts. #include <iostream> usingnamespace std; class BankAccount{ private: float balance; public: BankAccount(); void Deposit(float); void WithDrawal(float); float getbalance(); };arrow_forwardExplanation: Default arguments should always be declared at the rightmost side of the parameter list but the above function has a normal variable at the rightmost side which is a syntax error, therefore the function gives an error. 1. #include int fun(int=0, int = 0); int main() { cout << fun(5); return 0; } int fun(int x, int y) { return (x+y); } а) -5 b) 0 c) 10 d) 5 2. int main() { int a=10; int b,c; b =a++; c = a; cout<arrow_forwardC++arrow_forwardC++ pleasearrow_forwardQues tion 1 The following program converts and print the Fahrenheit equivalents of all Celsius temperatures from 0 to 100 degrees, and the Celsius equivalents of all Fahrenheit temperatures from 32 to 212 degrees. Implement the integer functions as declared in the program: #include int celcius( int fTemp ); // function prototype int fahrenheit( int eTemp ); // function prototype int main() { int i, / loop counter Il display table of Fahrenheit equivalents of Celsius temperature printf "Fahrenheit equivalents of Celcius temperatures:In"); printf( "Celciust\tFahrenhe itln"); II display Fahrenheit equivalents of Celsius 0 to 100 for( i = 0; i<= 100; i+H) { printft "%d\t\W%d\n", i, fahrenheit( i ) ); II display table of Celsius equivalents of Fahrenheit temperature printf( "\nCelcius equivalents of Fahrenheit temperatures:\n"); printf( "FahrenheituCelcius\n"); Il display Celsius equivalents of Fahrenheit 32 to 212 for( i = 32; i<= 212; i+) { printf "%d\t\w%d\n", i, celcius( i ) ); return…arrow_forwardC programing Given the function below, what would the function call question3(10, 101) return? int question3(int a, int b) {if (a == 0) return b;if (b == 0) return a;return question3(10*a+b%10, b/10);}arrow_forwardC++ Functions provide a means to modularize applications Write a function called "Calculate" takes two double arguments returns a double result For example, the following is a function that takes a single "double" argument and returns a "double" result double squareArea(double side){ double lArea; lArea = side * side; return lArea;}arrow_forwardC++arrow_forwardClasswork Requirements: Developa program in C++ that: Reads as many test scores as the user wants from the keyboard (assuming at most 50scores). Test scores should be whole numbers. You must validate user input; only positive numbers are valid. Prints the scores in original order sorted from high to low the highest score the lowest score the average of the scores Implement the following functions using the given function prototypes: void displayArray(int array[], int size)- Displays the content of the array void selectionSort(int array[], int size)- sorts the array using the selection sort algorithm in descending Hint: refer to example 8-5 in the textbook. int findMax(int array[], int size)- finds and returns the highest element of the array int findMin(int array[], int size)- finds and returns the lowest element of the array double findAvg(int array[], int size)- finds and returns the average of the elements of the arrayarrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning