0% found this document useful (0 votes)
65 views24 pages

Group 1 Laboratory 3

The program takes in the marks of 4 quizzes as input, calculates the total and average, and uses nested if-else statements to determine the remarks based on the average. It prints "Excellent" if the average is between 95-100, "Very Satisfactory" if between 90-94, and so on, with thresholds of 85, 80, 75 and 74 to determine the other remarks ending with "Poor". The nested if statements check the average against the thresholds to determine the appropriate remark.

Uploaded by

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

Group 1 Laboratory 3

The program takes in the marks of 4 quizzes as input, calculates the total and average, and uses nested if-else statements to determine the remarks based on the average. It prints "Excellent" if the average is between 95-100, "Very Satisfactory" if between 90-94, and so on, with thresholds of 85, 80, 75 and 74 to determine the other remarks ending with "Poor". The nested if statements check the average against the thresholds to determine the appropriate remark.

Uploaded by

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

GROUP 1

LABORATORY ACTIVITY NO.3


CONTROL STRUCTURE
(Conditional Structure)
GROUP MEMBER:
IVIER TRISTAN LABUGUEN
ANDRE DOMINIQUE A. CORDERO
Mark Mariquit
RICHMOND ROBERT CONDE
JERICHO ANGELO REOPTA
ARNAN ARO
JOHN SELWYN DIGOL
JOSHUA GARALDE
EXERCISE NO.1
A student took four quizzes in a
term and would like to compute
their average. He also would like
to know if the average has a
passing mark. Note that the
passing mark is 75%.

LETS GET STARTED


ALGORITHM
PSEUDOCODE

Start
NARRATIVE Integer marks1
Integer marks2

Integer marks3
Start collecting the marks of first Integer marks4
subject. Collect the marks of second INPUT marks1
subject. Collect the marks of third INPUT marks2
subject. Collect the marks of the INPUT marks 3
fourth subject. Add the marks o al INPUT marks4
subjects to find total marks. Divide total<-
total marks by four to find the marks1+marks2+marks3+marks4
avera. If Average is greater than or average <- total/4
equal to 75 then you are pass. If OUTPUT " you are pass!"
average is lesser than 75 then you IF average >= 75 THEN
are fail and end . OUTPUT "You are pass!"

ELSE
OUTPUT average
END

QUESTIONS
1. What statement in the program that determines that the average is passing?
The statement if (average>=75) determines that the average is passing.

2. What was the condition applied to satisfy the requirement?


The condition to check whether the students is pass or not is average>=75.

3. What have you observed in using if-else statement in this program?


If the condition in the IF clause is true then the next statement is executed
IF not then the statement after ELSE clause is executed.
4. What have you observed in using nested if statement in this program?
stacking one if statement inside another and combining an if statement with an else
statement. We need to use if statement nesting to put the full code flow in a semantically
correct sequence when an else statement fails and the subsequent statement execution
wishes to return a true statement.
Code
EXERCISE NO.2
Mary Jane would like to invest her money amounting 100,000 at the bank. Before investing her

money, she would like to determine which type of account that she will chose. The amount of

interest that her money earns depends on which type of account the money is in. The bank has 6

different types of accounts and they earn interest as follows:

Mary Jane as a programmer would like to make a program that computes automatically the interest

earned of her money in each type of account.


ALGORITHM
NARRATIVE PSEUDOCODE

1. initialize the investment amount as 10000.


2. an interest list is created with float data type to


class Account{ string type; float
store the calculated interest for 6 account.
interestRate;
3. assigning the interest value in the list,
getInterest(deposit); }
a. position with 1.5 %
vector<Account> accounts
b. position with 2 %
initialize: push all given
c. position with 2.5 %
accounts in the accounts vector
d. position with 3 %
main: maxInterest=0,
e. position with 3.5 %
maxindex=0 for each account in
f. position with 4 %
accounts do:
4. all account is displayed
account.getInterest(1000000)->interest if
5. interest rate value is been calculated with the
intereset>maxinterest
interest list for all 6 account by using while loop and
interest->maxinterest currentindex->maxindex
counter will be i and it determines the account type.

Presentation by GROUP 1
FLOWCHART

Big
Business
SCREEN DISPLAY
QUESTIONS
1. What are the data needed for the solution of the program to produce
the desired output?
The data required for the program's solution to produced the
desired output are the interest rate, the principal sum and the time.
2.What statements in the program that determine interest earned of each
type of account?
The following are the statement programs:
amount *0.015 = totalPersonalFinancial
amount *0.02 = totalPersonalHomeOwner
amount *0.025 = totalPersonalgold
amount *0.03 = totalSmallBusiness
amount *0.035 = totalBigBusiness
amount * 0.04 = totalgoldBusiness
3.What was the condition applied to satisfy the requirement?
The conditions used as index numbers for the options for
each account type are referred to as requirements. The
index number for interest and account type are identical.

4.What have you observed in using nested if statement in this program?


In essence, nested if is used to test any condition that
specifies other condition. Therefore, if else must be used in
this structure, but if the initial condition is not satisfied,
otherwise is executed, with all subsequent if else statements
nested inside of it. When not necessary, using nested makes a
program complex.
EXERCISE NO.3

A student took four quizzes in a term and would like to compute their average. He also would like to
know what will be the remarks. Follow the range of grades and its equivalent remarks, and then fill-
up the table below:
ALGORITHM
NARRATIVE PSEUDOCODE

int a,b,c,d;
• Input mark of 4 quiz
int tot= a+b+c+d;
• Add the remarks of 4 quiz to get total (tot)
double avg = tot/4;
• Divide the add value by 4 to get the average (avg)
If (avg>=95 && avg<=100)
• Use an if statement
print "Excellent"
• If avg greater than or equal to 95 and less than or
If (avg>=90 && avg<=94)
equal to 100, print "Excellent"
print "Very Satisfactory"
• If avg greater than or equal to 90 and less than or
If (avg>=85 && avg<=89)
equal to 94, print "Very Satisfactory"
print "Satisfactory"
• If avg greater than or equal to 85 and less than or
If (avg>=80 && avg<=84)
equal to 89, print "Satisfactory"
print "Fine"
• If avg greater than or equal to 84 and less than or
If (avg>=75 && avg<=79)
equal to 80, print "Fine"
print "Fair"
• If avg greater than or equal to 75 and less than or
If (avg>=74)
equal to 79, print "Fair"
print "Poor"
• If avg greater than or equal to 74, print "Poor"
SCREEN DISPLAY
QUESTIONS
1. What statement in the program that determines that the average is
passing
• double avg = tot/4;
If (avg>=80 && avg<=84)
If (avg>=95 && avg<=100)
print "Fine"
cout<<"Excellent"
If (avg>=75 && avg<=79)
If (avg>=90 && avg<=94)
print "Fair"
print "Very Satisfactory"
If (avg>=74)
If (avg>=85 && avg<=89)
print "Poor"
print "Satisfactory"

2. What was the condition applied to satisfy the requirement?


The score of 4 quizzes is required to produce the desire output values of a,b,c and d are
needed.
3. What have you observed in using if-else statement in this program?

• We cannot use switch-case here because in switch case, every case takes a constant value
but here the values are ranged in a specific way to producue the exact average grade
remark. So if-else statements can be used instead of using any other better execution.

4. What have you observed in using nested if statement in this program?


• If statement is initially a conditional statement; if condition is true, program runs. The
checking of a condition within a conditional statement is what nested if looks like. If the first
condition is satisfied, the second condition inside the first condition is checked and the
statement is entered.
SUPPLEMENTAL
ACTIVITIES

1. Get the value of variable num assuming it is equal to 5.


if (num >= 6)
cout << "Yes";
cout << No;

What will be the output?


We Answer is option (B) NO.

Explain your answer


Since the value of num is equal to 5 so the conditional statement
will fail hence the line “cout<< “Yes”;” will not be executed so next
line will be executed.
2. What is the output of the following code fragment
assuming num is 10?
if (num == 20)
cout << "teenager";
cout << "adult"

Record the output screen display:


No output; compile error

Explain your answer


Since semicolon ; is missing in the last line of code
hence it will throw compilation error.
3. After execution of the following code, what is stored
in valueNum?

All variables are using data type int. Note that num1=3, num2=5, and num3=7.
if (num2> num3)
if (num1 > num2)
valueNum =num2;
else
valueNum =num3;
else
if (num2 > num3)
valueNum =num1;
else
valueNum = num3;
Record the output screen display:
The largest value of num1, num2 and num3

Explain your answer


The letter b has the highest value among numbers 1, 2, and 3. The above code's logic
seeks to determine the highest total of the three.
The C++ programming language is rather broad, and we are only on the very
first page of a sizable chapter. Today, we discovered numerous new
programming paradigms that are applicable.Every program should have a
conditional expression, and the tasks and exercises provided actually help
us.to deepen our comprehension and expertise in this area, in order to
successfully complete the laboratory exercise done in a group. In summary,
The C++ programming language is among the most useful tools with a variety
ofhelps us create or construct a program and solve several types of
Group presentation

You might also like