Sentinel, signal, flag or dummy

Question: Write four different C++ statements that each add 1 to integer variable x

x =+ 1; x += 1; ++x; x++;

Question: In one statement, assign the sum of the current value of x and y to z and

postincrement the value of x

z = x++ + y;

Question: Determine whether the value of the variable count is greater than 10. If it is,

print "Count is greater than 10."

if (count > 10) cout << "Count is greater than 10" << endl;Question: Predecrement the variable x by 1, then subtract it from the variable total

total -= --x;

Question: Calculate the remainder after q is divided by divisor and assign the result to q.

Write this statement two different ways

q %= divisor;

q = q % divisor;

Question: Declare variables sum and x to be of type int

int sum, x;

Question: Set variable x to 1

x=1;

Question: Set variable sum to 0

sum=0;

Question: Add variable x to variable sum and assign the result to variable sum

sum+=x;

Question: Print "The sum is: " followed by the value of variable sum

cout << "The sum is: " << sum << end1;

Question: State the values of the variable after the calculation is performed. Assume that,

when a statement begins executing, all variables have the integer value 5:

product *= x++;

product = 25, x = 6;

Question: State the values of the variable after the calculation is performed. Assume that,

when a statement begins executing, all variables have the integer value 5:

quotient /= ++x;

quotient = 0, x = 6;

Question: Write single C++ statements that input integer variable x with cin and >>

cin>>x;

Question: Write single C++ statements that input integer variable y with cin and >>. cin >> y;

Question: Write single C++ statements that postincrement variable i by 1

i++;

Question: Write single C++ statements that determine whether i is less than or equal to y

if (i<=y)

Question: Write single C++ statements that output integer variable power with cout and

<<

cout << power << endl;

Question: Identify and correct the errors in the following code:

while (c <= 5)

{

product *= c;

c++;

while (c <= 5)

{

product *= c;

c++;

}

Question: Identify and correct the errors in the following code:

if (gender == 1)

cout << "Woman" << endl;

else;

cout << "Man" << endl;

if (gender == 1)

cout << "Woman" << endl;

else cout << "Man" << endl;

Question: Identify and correct the errors in the following code:

cin << value;

cin >> value;

Question: What is wrong with the following while repetition statement?

while (z >= 0)

sum += z;

The value of the variable z is never changed in the while statement. Therefore, if the loop

continuation condition (z >= 0) is initially true, an infinite loop is created. To prevent the


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: