Question: For questions that ask you to write code just write enough to answer the question. You do not need to write an entire program. Q1-
For questions that ask you to write code just write enough to answer the question. You do not need to write an entire program.
Q1- What is the output of the following code segments?
a)
for (int n=1 ; n != 10; n= n + 2) cout << n <<"\t";
b) int sum =0; for (int i=0; i<=12; i++) {
if (i%3 != 0) {
cout <
sum += i; }
} cout <<"sum = " << sum;
c) int n=5;
while (n>0) {
for (int i=0; i<5; i++) if (i%2 == 1)
cout <
n= n-2; }
d) int n = 11; while (n >0) {
n = n 2 if ( n == 5)
continue; cout < } e) Write a code segment that displays all the odd numbers from10 through 50 four on each line. Q2- Write a function definition for a function called is_vowel that takes an argument of type char. The function returns true if the argument is a vowel, and false otherwise. Q3- What is the output of the following code segment (Note that the function is_vowel is defined above)? char letter =B; int num; while (! is_vowel(letter)) { num = static_cast } Q4- Write a function definition for a function called sumOfPowers that takes an argument of type int (n). The function returns the sum of all the powers of 3s staring from 1 through n. (For example, if n is equal to 5, it returns the sum of 31+32+33+34+35). Q5- Write a void function called sumOfEven that takes two arguments of type int. The function finds the sum of all the even numbers between 1 and the value of the first argument, and returns the sum through the second argument. Q6- Write a code segment that reads a whole number from the keyboard, calls the function sumOfEven defined above to compute the sum of all the even numbers between 1 and the value inputted at the keyboard, and then displays the sum. Q7- Write a code segment that asks the user for an input file name, and allows the user to re-enter the file name if the file doesnt exists. Q8- What output will be produced when the following lines are executed? (Be precise!) cout.width (5); cout << + << 2 < Q9- Read a phrase from the keyboard and display how many spaces are in the phrase. Q10- Write a code segment that prompts for and reads in two whole numbers from the keyboard and writes both numbers and their sum into an output file called Q10.txt. The program should write to the end of Q10.txt if the file already exists.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
