Question

1. What is the output of the following code fragment? (All variables are of type int.)...

1. What is the output of the following code fragment? (All variables are of type int.)
limit = 8;
cout << 'H';
for (loopCount = 10; loopCount <= limit; loopCount++)
cout << 'E';
cout << "LP");

2. What is the output of the following code fragment if the input value is 4? (Be careful here.)
int num;
int alpha = 10;
cin >> num;
switch (num)
{
case 3 : alpha++;
case 4 : alpha = alpha + 2;
case 8 : alpha = alpha + 3;
default : alpha = alpha + 4;
}
cout << alpha << endl;

3. What is the output of the following code fragment? (All variables are of type int.)
n = 2;
for (loopCount = 1; loopCount <= 3; loopCount++)

while (n <= 4)

n = 2 * n;

cout << n << endl;

4. Which of the following is not an assertion?

a. a function postcondition

b. both a and b

c. a switch label

d. a function precondition

5. What is the output of the following code fragment? (loopCount is of type int.)
for (loopCount = 1; loopCount > 3; loopCount++)
cout << loopCount << ' ';
cout << "Done" << endl;

6. True or False? (), ++, and – represent three operators that have the highest grouped precedence and ==, +=, -=, ∗=, and / represent three operators that have the lowest grouped precedence?

7. True or False? The code segment
cout << "Do you wish to continue? ";
cin >> response;
while (response != 'Y' && response != 'N')
{
cout << "Do you wish to continue? ";
cin >> response;
}
is equivalent to the following code segment.
do
{
cout << "Do you wish to continue? ";
cin >> response;
} while (response != 'Y' && response != 'N');

8. True or False? The statement
switch (n)
{
case 8 : alpha++; break;
case 3 : beta++; break;
default: gamma++; break;
}
is equivalent to the following statement.
if (n == 8)
alpha++;
else if (n == 3)
beta++;
else
gamma++;

9. What is the value of sum after execution of the following For loop?
sum = 0;
for (count = 1; count <= 21; count++)
sum = sum + count;

10. True or False? The increment and decrement operators (++ and --) operate only on variables, not on constants or arbitrary expressions

Homework Answers

Answer #1

1)Output: HLP

Explanation:

If for loop has no curly braces({ }), then the output will be HLP

2)Output: 19

Explanation:

if input (num) is 4, then switch with case 4 will be executed and alpha value will be 10(initial alpha value)+2=12.

Then since case 4 has no break point,control goes to next statement(case 8)

Now alpha = alpha + 3 = 12 + 3 = 15; Since case 8 has also now break point, default statement will also be executed.

Now alpha = alpha + 4= 15 + 4 = 19.

3)Output:

4

8

4)Answer: c)a switch label

5)Done

Explanation:

Because loopCount = 1 is not greater than 3. So loop will never executed.

6)True

7)True

8)True.

Explanation;

Both switch case and if-else statements are logically correct.

9)Answer:  231

Value of sum after execution of the For loop is 231.

10) True

Explanation:

int speed = 25;

speed++; // speed will be incremented by 1

but it does not work for constants. Example 25++ is compile time error.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1.    Given the following segment of code: (If there is nothing output, write None.) int x;...
1.    Given the following segment of code: (If there is nothing output, write None.) int x; int y; cin >> x; cin >> y; while (x > y) {     x -= 3;     cout << x << " "; } cout << endl;        a.    What are the output and final values of x and y when the input is 10 for x and 0 for y? [2, 2, 2]               Output                                                                                                                                                                                                    x = ______________                                                                                                                                                                                                   ...
Write a C++ program to run a menu-driven program with the following choices: Compute the factorial...
Write a C++ program to run a menu-driven program with the following choices: Compute the factorial of a number Compute the alternating factorial of a number Quit #include <iostream> using namespace std; void getValidUserInputPosNumGT0 (int *a) { int num; cout << "Enter in a positive number greater than 0... "; cin >> *a; } long double factorial (int num) { int fact = 1; while (num > 1) { fact *= num; num--; } return fact; } long double AlternatingFactorial...
my code has several functions; delete and backward functions are not working, rewrite the code for...
my code has several functions; delete and backward functions are not working, rewrite the code for both functions and check them in the main: #include<iostream> #include<cassert> using namespace std; struct nodeType {    int info;    nodeType *link; }; class linkedList { public:    void initializeList();    bool isEmptyList();    void print();    int length();    void destroyList();    void insertFirst(int newItem);    void insertLast(int newItem);    int front();    linkedList();    void copyList(const linkedList otherList);    void insertNewValue(int value);...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int fib(int n) { int temp; if (n <= 0)    return 0; else if (n <= 2)    return 1; else {    temp = fib(n – 1);    return temp + fib(n-2); } } int main() {    int num;    cout << "Which fibonacci number? ";    cin >> num;    cout << fib(num) << endl;    return 0; } You must...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...
What will be the output of the following code? #include <iostream> using namespace std; int main()...
What will be the output of the following code? #include <iostream> using namespace std; int main() {    char *s = "hello";    char *p = s;    cout << *(p+3) << " " << s[1] << endl; }
in C# What Will Be The Output Of The Following Code Snippet:? using System; namespace ProgrammingExercise...
in C# What Will Be The Output Of The Following Code Snippet:? using System; namespace ProgrammingExercise { class FindOutput   { static void Main(string[] args)   { int i; int div = 8, num = 32; for (i = 0; i <= 10; i++) { if ((num / div * 3)== 6) { Console.WriteLine( i + " "); continue; } else if (i != 5) Console.Write(i + " "); else break;   }   Console.ReadLine();   } } }
What is the output of the following function and function call? void calculateCost(int count, float& subTotal,...
What is the output of the following function and function call? void calculateCost(int count, float& subTotal, float taxCost); float tax = 0.0, subtotal = 0.0; calculateCost(15, subtotal,tax); cout << "The cost for 15 items is " << subtotal       << ", and the tax for " << subtotal << " is " << tax << endl; //end of fragment void calculateCost(int count, float& subTotal, float taxCost) {       if ( count < 10)       {                   subTotal = count *...