0% found this document useful (0 votes)
47 views

Week 8 Selection Control Structures

This document contains the solutions to programming exercises involving selection control structures like if/else statements and switch statements in C++. It includes examples of if/else statements for conditions checking angles, temperatures, numbers, slopes, and based on flowcharts. It also shows how to rewrite an if/else chain as a switch statement and a program that checks if a grade is a pass or fail.

Uploaded by

Daniel Jadol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Week 8 Selection Control Structures

This document contains the solutions to programming exercises involving selection control structures like if/else statements and switch statements in C++. It includes examples of if/else statements for conditions checking angles, temperatures, numbers, slopes, and based on flowcharts. It also shows how to rewrite an if/else chain as a switch statement and a program that checks if a grade is a pass or fail.

Uploaded by

Daniel Jadol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Name: Aireen G.

Jadol BSCS-1 B Date accomplished: 11-9-20


Course Instructor: Christine W. Pitos W-8 Selection Control Structures
Subject: Fundamentals of Programming

(1.) Write suitable if statements for the following


conditions:

1. if(angle == 90){
cout<<"The angle is a right angle!!";
}else{
cout<<"The angle is not a right angle!!";
}

2. if(Temperature > 100){


cout<<"Above the boiling point of water!!";
}else{
cout<<"Below the boiling point of water!!";
}
3. if(number < 0){
negativesum += number;
}else{
positivesum += number;
}

4. if(slope < 0.5){


flag = 0;
}else{
flag = 1;
}
5. if((slope1-slope2) < 0.001){
approx = 0;
}else{
approx = (slope1-slope2)/2.0;
}

(2.) Write if statements corresponding to the conditions


shown in the following flowcharts:

1. if(ace<25){
sum = sum+a;
}else{
count=count+1;
}

2. if(c==15){
credit=10;
limit=1200;

}else{
credit=8;
limit=800;
}
3.) Rewrite the following if-else chain by using a
switch statement:
switch (gradeletter){
case "A":
cout<<"The numerical grade is between 90 and 100 \n";
break;
case "B":
cout<<"The numerical grade is between 80 and 89.9 \n";
break;
case "C":
cout<<"The numerical grade is between 70 and 79.9 \n";
break;
case "D":
cout<<"How are you going to explain this one? \n";
break;
default:
cout<<"Of course I had nothing to do with my grade. \n";
cout<<"It must have been the professor's fault' \n";
}

(4.) In a pass/fail course, a student passes if the grade


is greater than or equal to 70 and fails if the grade is
lower than 70. Write a c++ program that accepts a
grade and prints the message “ A passing grade” or
“A failing grade,” as appropriate
int grade;
cout<<"Input Grade: ";
cin>> grade;

if(grade >= 70){


cout<<"A Passing Grade";
}else{
cout<<"A Failing Grade";
}

You might also like