SlideShare a Scribd company logo
1 of 9
Chapter 6
If statements
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
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
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
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
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
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
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
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

More Related Content

Similar to If.pptx

6. using control structures, conditional statements and loops
6. using control structures, conditional statements and loops6. using control structures, conditional statements and loops
6. using control structures, conditional statements and loops
CtOlaf
 
Cs1123 5 selection_if
Cs1123 5 selection_ifCs1123 5 selection_if
Cs1123 5 selection_if
TAlha MAlik
 
Lab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practiceLab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practice
ranaibrahim453
 

Similar to If.pptx (20)

Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
 
lab-8 (1).pptx
lab-8 (1).pptxlab-8 (1).pptx
lab-8 (1).pptx
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
White box-sol
White box-solWhite box-sol
White box-sol
 
C important questions
C important questionsC important questions
C important questions
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
 
6. using control structures, conditional statements and loops
6. using control structures, conditional statements and loops6. using control structures, conditional statements and loops
6. using control structures, conditional statements and loops
 
The Ring programming language version 1.5.1 book - Part 25 of 180
The Ring programming language version 1.5.1 book - Part 25 of 180The Ring programming language version 1.5.1 book - Part 25 of 180
The Ring programming language version 1.5.1 book - Part 25 of 180
 
12th information Practices multiple choice questions CBSE INDIA
12th information Practices multiple choice questions CBSE INDIA12th information Practices multiple choice questions CBSE INDIA
12th information Practices multiple choice questions CBSE INDIA
 
04 Conditions.pptx
04 Conditions.pptx04 Conditions.pptx
04 Conditions.pptx
 
Cs1123 5 selection_if
Cs1123 5 selection_ifCs1123 5 selection_if
Cs1123 5 selection_if
 
lesson 2.pptx
lesson 2.pptxlesson 2.pptx
lesson 2.pptx
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
White Box Testing (Introduction to)
White Box Testing (Introduction to)White Box Testing (Introduction to)
White Box Testing (Introduction to)
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
Lab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practiceLab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practice
 
C++ practical
C++ practicalC++ practical
C++ practical
 

More from ntabdelnaiem (7)

transport.pdf
transport.pdftransport.pdf
transport.pdf
 
tutorial 3.pptx
tutorial 3.pptxtutorial 3.pptx
tutorial 3.pptx
 
9108528.ppt
9108528.ppt9108528.ppt
9108528.ppt
 
8076892 (1).ppt
8076892 (1).ppt8076892 (1).ppt
8076892 (1).ppt
 
6262846.ppt
6262846.ppt6262846.ppt
6262846.ppt
 
4535092.ppt
4535092.ppt4535092.ppt
4535092.ppt
 
loops_part1.pptx
loops_part1.pptxloops_part1.pptx
loops_part1.pptx
 

Recently uploaded

Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 

If.pptx

  • 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