Iteration # | low | high | low < high | output |
1 | 1 | 20 | true | 1 20 |
2 | 2 | 19 | true | 2 19 |
3 | 3 | 18 | true | 3 8 |
4 | 4 | 17 | true | 4 17 |
5 | 5 | 16 | true | 5 16 |
6 | 6 | 15 | true | 6 15 |
7 | 7 | 14 | true | 7 14 |
8 | 8 | 13 | true | 8 13 |
9 | 9 | 12 | true | 9 12 |
10 | 10 | 11 | true | 10 11 |
11 | 11 | 10 | false |
4. Perform a hand trace by producing a table of values for each of the variables...
a) Hand-trace the following program and determine and write down what is the output of the code. b) Run the code and compare the program output to your hand-traced result obtained from part (a). #include <iostream> #include <iomanip> using namespace std; void f(); int x = 5; int main() { cout << "x = " << x << endl; int x = 6; cout << "x = " << x << endl; { int...
What does the following program print? I // Exercise 3.12 Solution: ex03_12.cpp // What does this program print? #include <iostream> using namespace std; 3 4 7 int main() { int y; // declare y int x = 1; // initialize x int total = 0; // initialize total while ( 10 ) // loop 10 times y = X* X; // perform calculation cout << y << endl; // output result total += y; // add y to total ++x;...
I have to type and explain in class each code in every detail filled with // commentary. Explains how does work in every codes. 1) What does the below print #include <iostream> using namespace std ; int main() { int var1 = 20 ; int var2 = 30 ; int* ptr1 ; int* ptr2 ; int* temp ; ptr1 = &var1 ; ptr2 = &var2 ; cout << *ptr1 << endl ;...
How many Iterations will this while loop perform? int ico), j(10); cout << "i = " << i << endl; cout << "j = " << j << endl; while (i > j) { cout << "j-" « j << endl; j += 2; cout << "i = " << i << endl; } cout << "i = << i << endl; cout << "j = " << j << endl; 5 6 C 8 10 Infinite times Does the...
Question 19 4 pts Using the program below, please complete the program by adding 2 functions as follow: 1. A function named getAverage that calculates and returns the Average. 2. A function named getMaximum that returns the maximum of the three numbers. Make sure to use the proper data types for all variables and functions. #include <iostream> using namespace std; //function getAverage //function getMaximum int main(int argc, char** argv) { int x, y, z; cout << "Enter three whole numbers:...
The C++ code below will compile but has a variety of runtime issues. Identify a runtime issue with the program and describe how you might fix the problem. #include <iostream> #include <vector> using namespace std; //------------------------------------------------------------------------------ int main() { vector<double> temps; // temperatures double temp = 0; double sum = 0; double high_temp = 0; double low_temp = 0; while (cin >> temp) // read and put into temps temps.push_back(temp); for (int i = 0; i < temps.size(); ++i) {...
This program illustrates dynamic variables #include <iostream> using namespace std; int main () { int *p1; p1 = new int; // Variables created using the new operator are called dynamic variables cout << "Enter an integer \n"; cin >> *p1; *p1 = *p1 + 7; cout << << "Your input + 7 = " << *p1 << endl; delete p1; // Delete the dynamic variable p1 and return the memory occupied by p1 to...
C++ Type in the above program . Before running the program, change each of the question marks to the numbers 1 through 5 indicating the order in which that line will be executed. Run the program and check your numbers. Fix and rerun if necessary. Submit the program and the output. #include <iostream> using namespace std; //prototypes void DemonstrateProc1(); void DemonstrateProc2(int num); int main() { cout << "?. Execution starts with main. " << endl; DemonstrateProc1(); cout << "?....
Modify the program below by replacing the function prototype "void getScore(int& score);" with "int getScore();" You need to modify other part of program according to this change. //This program reads a course score and prints the //associated course grade #include <iostream> using namespace std; void getScore (int& score); void printGrade (int score); int main () int courseScore; cout << "Line 1 Based on the course score, n" <<"this program computes the" <"course grade." << endl; getScore (courseScore); printGrade (courseScore); return...
1. What is wrong with the following C++ program? #include <iostream> int main() { a = 4; b = 6; cout << a << "+" << b << "=" << a+b; return 0; 2. What is wrong with the following C++ program? What was its intended output? #include <iostream> using namespace std; int main() { cout << "What is larger? e pi or pi e?" << endl; double ans1 = exp(pi); double ans2 = pi exp(1.); cout << "epi is...