1. (TCO 4) What is the output from the following loop? int sum = 0; for ( int i
ID: 3627657 • Letter: 1
Question
1.(TCO 4) What is the output from the following loop?
int sum = 0;
for ( int i = 1; i % 2 != 0; i++)
{
sum += i;
i++;
}
cout << sum << endl; (Points : 5)
2. (TCO 3) A program has a char variable response that has been assigned a value. Write a switch statement that outputs "Yes" if the variable contains lower or upper case 'y', "No" if it contains lower or upper case 'n', or "Invalid Input" for any other value. (Points : 10)
3. (TCO 3) Write a short program that gets three integer values from the user and outputs the largest number. Make sure you include everything you need, and declare all the variables you need. (Points : 10)
4. (TCO 3) Write a complete C++ console mode program (#includes, etc., but no prologue) to ask the user to enter the radius (any positive real number) of a circle. Your program should display the area of a circle with that radius, and the volume of a sphere with that radius. (area = PI * radius2 and volume = PI * 4/3 * radius3 ). The result should be displayed with accuracy to 3 decimal digits (ie. 1.234). Make sure you include all the header files needed to support the operations you use.
a. Use appropriate data types.
b. Make the value of PI (3.14159) a constant in your program.
c. Valid input is any positive real number and zero. If the user input is negative, your program should print an error message and not try to compute any results.
d. Be sure to display explanatory text to make the input and output clear to the user. (Points : 15)
5. (TCO 4) Create a C++ program that uses a do-while-loop to display the multiples of 5 (5, 10, 15, 20…) from 75 to 190, including 75 and 190. The numbers should be displayed one per line. (Points : 15)
6. (TCO 4) Write a complete C++ program that meets the following criteria:
a. Use a do-while loop. Explicitly ask the user if they have more data to enter. Use their answer to decide when the loop is done.
b. The purpose of the loop is to calculate and display the amount of interest for one year given an initial deposit and an interest rate. (interest = deposit * rate)
c. The output from the loop should explain what values are being displayed and display the interest with 2 digits after the decimal point.
d. The loop must ask the user to input the values for the initial deposit and the interest rate. Both values should be treated as real numbers.
e. If either input value is negative, your program should output a message indicating that the input values must be positive numbers. The interest amount should not be displayed in this case.
f. Declare all needed variables using appropriate data types. Initialize as needed. (Points : 15)
Explanation / Answer
please rate - thanks
sorry questions 3-6 are complete programs, making it a violation of CRAMSTER rules
1.
(TCO 4) What is the output from the following loop?
int sum = 0;
for ( int i = 1; i % 2 != 0; i++)
{
sum += i;
i++;
}
cout << sum << endl; (Points : 5)
nothing it is infinite since i will always be odd when tested
2. (TCO 3) A program has a char variable response that has been assigned a value. Write a switch statement that outputs "Yes" if the variable contains lower or upper case 'y', "No" if it contains lower or upper case 'n', or "Invalid Input" for any other value. (Points : 10)
char var;
cin>>var;
switch(var)
{case 'y':
case 'Y': cout<<"yes ";
break;
case 'n':
case 'N': cout<<"No ";
break;
default: cout<<"Invalid input ";
break;
}
3. (TCO 3) Write a short program that gets three integer values from the user and outputs the largest number. Make sure you include everything you need, and declare all the variables you need. (Points : 10)
4. (TCO 3) Write a complete C++ console mode program (#includes, etc., but no prologue) to ask the user to enter the radius (any positive real number) of a circle. Your program should display the area of a circle with that radius, and the volume of a sphere with that radius. (area = PI * radius2 and volume = PI * 4/3 * radius3 ). The result should be displayed with accuracy to 3 decimal digits (ie. 1.234). Make sure you include all the header files needed to support the operations you use.
a. Use appropriate data types.
b. Make the value of PI (3.14159) a constant in your program.
c. Valid input is any positive real number and zero. If the user input is negative, your program should print an error message and not try to compute any results.
d. Be sure to display explanatory text to make the input and output clear to the user. (Points : 15)
5. (TCO 4) Create a C++ program that uses a do-while-loop to display the multiples of 5 (5, 10, 15, 20…) from 75 to 190, including 75 and 190. The numbers should be displayed one per line. (Points : 15)
6. (TCO 4) Write a complete C++ program that meets the following criteria:
a. Use a do-while loop. Explicitly ask the user if they have more data to enter. Use their answer to decide when the loop is done.
b. The purpose of the loop is to calculate and display the amount of interest for one year given an initial deposit and an interest rate. (interest = deposit * rate)
c. The output from the loop should explain what values are being displayed and display the interest with 2 digits after the decimal point.
d. The loop must ask the user to input the values for the initial deposit and the interest rate. Both values should be treated as real numbers.
e. If either input value is negative, your program should output a message indicating that the input values must be positive numbers. The interest amount should not be displayed in this case.
f. Declare all needed variables using appropriate data types. Initialize as needed. (Points : 15)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.