2. Question 4
Consider the following program segment, assume that temp is integer.
cout<<“The water is a ”;
if (temp>=212)
cout<<“gas.”<<endl;
else if(temp>32)
cout<<liquid.”<<endl;
else
cout<<“solid.”<<endl;
a) Write the output if the input data is: (i) 31 (ii)33 (iii)213
b) Rewrite the nested if structure so that a sequence of independent if-
then statements are used
3. Question 4
Consider the following program segment, assume that temp is integer.
cout<<“The water is a ”;
if (temp>=212)
cout<<“gas.”<<endl;
else if(temp>32)
cout<<liquid.”<<endl;
else
cout<<“solid.”<<endl;
a) Write the output if the input data is: (i) 31 (ii)33 (iii)213
b) Rewrite the nested if structure so that a sequence of independent if-
then statements are used
4. Question 4
Consider the following program segment, assume that temp is integer.
cout<<“The water is a ”;
if (temp>=212)
cout<<“gas.”<<endl;
else if(temp>32)
cout<<liquid.”<<endl;
else
cout<<“solid.”<<endl;
a) Write the output if the input data is: (i) 31 (ii)33 (iii)213
b) Rewrite the nested if structure so that a sequence of independent if-
then statements are used
5. Question 7
Consider the following program segment, assume that x, y, and z are integers.
cin>>x>>y>>z;
if ((x%y==0)||(y<z)&&(x+2>z))
if((x+y>z)&&(z==9))
{
y=x+z-1;
x=z%y;
z=(x+y)/3;
}
else
{
x=z/y;
z=x+y+3;
y=(y+z)%x;
}
else
{
x=(y+z+2)/2;
y=x*y;
z=y/x;
}
cout<<“x=”<<x<<“ y=”<<y<<“ z=“”<<z<<endl;
Write the output if the input data is:
(a) 6 4 9
(b) 6 2 9
(c) 8 2 9
x y z
6 4 9
7 28 4
x y Z
6 4 9
x y Z
6 4 9
7
x y Z
6 4 9
7 28
x y Z
6 4 9
7 28 4
6. Question 7
Consider the following program segment, assume that x, y, and z are integers.
cin>>x>>y>>z;
if ((x%y==0)||(y<z)&&(x+2>z))
if((x+y>z)&&(z==9))
{
y=x+z-1;
x=z%y;
z=(x+y)/3;
}
else
{
x=z/y;
z=x+y+3;
y=(y+z)%x;
}
else
{
x=(y+z+2)/2;
y=x*y;
z=y/x;
}
cout<<“x=”<<x<<“ y=”<<y<<“ z=“”<<z<<endl;
Write the output if the input data is:
(a) 6 4 9
(b) 6 2 9
(c) 8 2 9
x y z
6 2 9
4 9 2
x y Z
6 2 9
x y Z
6 2 9
4
x y Z
6 2 9
4 9
x y Z
6 2 9
4 3 9
7. Question 7
Consider the following program segment, assume that x, y, and z are integers.
cin>>x>>y>>z;
if ((x%y==0)||(y<z)&&(x+2>z))
if((x+y>z)&&(z==9))
{
y=x+z-1;
x=z%y;
z=(x+y)/3;
}
else
{
x=z/y;
z=x+y+3;
y=(y+z)%x;
}
else
{
x=(y+z+2)/2;
y=x*y;
z=y/x;
}
cout<<“x=”<<x<<“ y=”<<y<<“ z=“”<<z<<endl;
Write the output if the input data is:
(a) 6 4 9
(b) 6 2 9
(c) 8 2 9
x y z
8 2 9
7 28 4
x y Z
8 2 9
x y Z
8 2 9
16
x y Z
8 2 9
9 16
x y Z
8 2 9
9 16 8
8. Question 9
Consider the following program segment
cin>>score;
if(score<50)
cout<<“Failling”;
if(score<60)
cout<<“Bellow average”;
if(score<70)
cout<<“Average”;
if(score<80)
cout<<“Above average”;
if(score<90)
cout<<“Very good”;
if(score<100)
cout<<“Excellent”;
a) Write the output if the input data is 65. Is this
output correct? Why?
b) Rewrite the previous program segment using
nested if statements so that it works
properly. Find the output in this case, if the
input is (i)65 (ii)87 (iii) 57
9. Question 9
Consider the following program segment
cin>>score;
if(score<50)
cout<<“Failling”;
else if(score<60)
cout<<“Bellow average”;
else if(score<70)
cout<<“Average”;
else if(score<80)
cout<<“Above average”;
else if(score<90)
cout<<“Very good”;
else
cout<<“Excellent”;
a) Write the output if the input data is 65. Is this
output correct? Why?
b) Rewrite the previous program segment using
nested if statements so that it works
properly. Find the output in this case, if the
input is (i)65 (ii)87 (iii) 57