Вы находитесь на странице: 1из 9

Consider the following snippet of C code, then answer the questions that follows showing how the value

of delta changes as the code gets executed.


Consider each question independently.
intinput
1.How many times can the user num;3 before the loop exits?
int delta = 10;
2.How many times can the user input 4 before the loop exits
do {
3.What value(s) the user need to input to display the value for delta?
num = GetInt();
switch (num)
{
case 3: delta++;
1. How many times can the user input 3 before the loop exits? case 4: delta --;
delta = 10 case 8: delta = delta +5; continue;
default: delta = delta + num;
1st time input: 3 delta = 11, 10, 15
}
2nd time input:3 delta = 16, 15, 20 cout<<delta;
The user can input 3 twice }while (delta < 20);

2. How many times can the user input 4 before the loop exits
delta = 10
1st time input: 4 delta = 9, 14
2nd time input: 4 delta = 13, 18
3rd time input: 4 delta = 17, 22
The user can input 4 three times

3. What value(s) the user need to input to display the value for delta?
Any number except 3, 4, and 8
j < 4 + j == 5 * i >= k for i = 10, j = 3, and k = 20

3 <4 + 3 == 5 * 10 >= 20

3 <4 + 3 == 50 >= 20

3 < 7 == 50 >= 20

T == T —> T
Which of the following operators takes only integer operands?
a) +
b) *
c) /
d) %

If p is a Boolean variable, which of the following logical expressions always has the value FALSE?
a) p && p
b) p || p
c) p && !p
d) p || !p
e) b and d above
What the following code fragment prints
for (int i = ; i < 5; i++)
if (i == 3) continue;
else printf (“%d ”, i);

Answer: 1 2 4
Which of the following statements about C++ main function is False?

a)Every program must have a function named main.

b)Program execution begins with the first executable statement in the main function.

c)The main function must call (invoke) at least one other function.

d)The word int in the function heading means that the main function returns an integer

value (to the operating system)


Rewrite the following program after removing the syntactical errors (if any). Underline each correction.
#include <iostream.h>
struct Pixels
{
int Color,Style;}
void ShowPoint(Pixels P)
{
cout<<P.Color,P.Style<<endl;}
void main()
{
Pixels Point1=(5,3);
ShowPoint(Point1);
Pixels Point2=Point1;
Color.Point1+=2;
ShowPoint(Point2);
}
#include<stdio.h>
A number is special if it is divisible by  int main()
{
15. A number is big if it is greater than int big, special;
int num;
999. Write a program that reads in   do{cout <<"Enter your number: ";
cin >>num;
if (num == 0) break;
integer values and decides which of if (num % 15)
special = 0;
them are scary or special or both. The else special = 1;
if (num > 999)
program prints an appropriate message big = 1;
else big = 0;
to the user and terminates when the if (special && big)
cout<<“The number is big and
user inputs a 0. Declare two variables special”;
else if (big)
called special, and, big, weird using an cout<<“The number is big only”;
else if (special)
appropriate data type and make suitable cout<<“The number is special”;
else
assignments to these variables as a cout<<“The number is neither big nor
special”;
number is tested. }while (1);
return 0;
Write the equivalent Boolean Expression for the following Logic Circuit

VU’

Вам также может понравиться