0% found this document useful (0 votes)
18 views19 pages

Prob. Solving Phases (PSS)

Uploaded by

icha
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)
18 views19 pages

Prob. Solving Phases (PSS)

Uploaded by

icha
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/ 19

PROBLEM SOLVING PHASES

Learning Outcomes
After completing this lab, you will be able to:
o describe the steps in the programming process
o construct an algorithm by using flowchart or pseudocode
o recognize syntax and logic error

A. PRE-LAB ACTIVITIES
Question 1
List the five basic steps in the programming process.

Answer

Question 2
Define an algorithm.

Answer

Question 3
Define a flowchart.

Answer
Question 4
Define a pseudocode.

Answer

Question 5
What is a syntax error?

Answer

Question 6
What is a logic error?

Answer

Question 7
What is the purpose of documentation inside a program?

Answer

Question 8
What is the symbol used to represent input/output in a flowchart?

Answer

Question 9
Ammar lives in Shah Alam that charges 3% income tax on yearly wages. He wants you
to write a program that will display the income tax. Identify the input, process and output
of this problem.
Answer

Question 10
Write a pseudocode to calculate the change given back to the customer if the customer
gives RM250.00 and the price of an item bought in the supermarket is RM206.50.

Answer

Question 11
Write a pseudocode to calculate the value of distance, in miles, giving the relationship

distance = rate x eclipsed time.

Giving rate is 55 miles per hour and eclipsed time is 2.5 hours.

Answer

Question 12
A finance company will give a loan to a customer for buying a car based on the amount
of a loan. If the loan is RM100,000 or more, the interest rate will be 3.5%, otherwise it
will be 5%. Given the amount of loan and the period of repayment, draw a flowchart to
calculate the amount of interest and the monthly payment or installment and display the
amount in the screen as output.
Answer
B. LAB ACTIVITIES
Exercise 1

Assume that your weight is 56 kilograms. You need to convert your weight to pound and
display it. Hint: 1 kg = 2.2 pounds.

a. Define the input, process and output of this task.

b. Draw the flow chart.

c. Write the pseudocode.


d. Enter, compile and run the Program 2.1 below.

//Program Name: lab2_prog1.cpp


//This program is able to convert the weight from
//kilogram to pound
#include <iostream >
using namespace std;

int main()
{
float weightInKg = 56.0;
float weightInPound;

weightInPound = weightInKg * 2.2;


cout << “The weight in pounds is ” << weightInPound;
return 0;
}

Program 2.1

e. What is the output displayed on the screen?

Exercise 2

The length and width of a rectangle is 5 cm and 8 cm respectively. You need to


calculate the perimeter and area of the rectangle.

a. Define the input, process and output of this task.


b. Draw the flowchart.

c. Write the pseudocode.

d. Enter, compile and run the Program 2.2 below.

//Program Name: lab2_prog2.cpp


//This program is able to calculate the perimeter and
//area of a rectangular
#include <iostream>
using namespace std;

int main()
{
int length = 6, width = 8, perimeter, area;

perimeter = 2 * (length + width);


area = length * width;
cout << “The perimeter is ” << perimeter << endl;
cout << “The area is ” << area << endl;
return 0;
}
Program 2.2
e. What is the output?

Exercise 3

a. Enter, compile and run the Program 2.3 below.

//Program Name: lab2_prog3.cpp


//This program is able to calculate the college fee of a
//student
#include <iostream>
using namespace std;

int main()
{
int numOfHour = 20;
float charges = 105.0;
float fees;
//Line 1
cout << “The fees is RM ” << fees; //Line 2
fees = numOfHour * charges; //Line 3
return 0;
}

Program 2.3

b. What is the output displayed on the screen?

c. Move the statement in Line 3 to Line 1. Compile and run the program and
identify the output.

d. Identity the type of error occurred in b (logic or syntax error)


Exercise 4

a. Type the program below and run it.

//Program Name: lab2_prog3.cpp


//This program is able to calculate the total price
//of CD-RW
#include <iostream>
using namespace std;

int main()
{
int numOfCD = 5;
float totalPrice;
//Line 1
cout << “The total price is RM ” << totalPrice; //Line 2
totalPrice = numOfCD * 5; //Line 3
return 0;
}

Program 2.3

b. What is the displayed output on screen?

c. Move the statement in Line 3 to Line 1. Compile and run the program and
identify the output.

d. Identity the type of error occurred in b (logic or syntax error)

Exercise 5
Sumayyah College charges RM105.00 for each credit hour taken by its students. The
number of hours that enrolled by a student is 20 hours. You need to calculate the fees
that the student has to pay.

a. Define the input, process and output of this task.


b. Draw the flowchart.

c. Write the pseudocode.

Exercise 6

Your program should be able to determine whether the applicant is qualified to apply for
a credit card or not based on his salary. If the salary is greater than RM1500, then
display a message that the applicant entitles to apply. Otherwise, display a message
that the applicant cannot apply for the credit card.
a. Define the input, process and output of this task.

b. Draw the flow chart.

c. Write the pseudocode.


Exercise 7
Your program is able to determine and display the waveform depending on the input
time value. A certain waveform is 0 volts for time less than 30 seconds and 10 volts for
the time equal to or greater than 30 seconds.

a. Define the input, process and output of this task.

b. Draw the flow chart.

c. Write the pseudocode.


Exercise 8

Your program is able to determine the correct password. A message, “Password


Accepted”, is displayed when the user entered the correct password. The process will
repeat until the correct password is entered.

d. Define the input, process and output of this task.

e. Draw the flow chart.

f. Write the pseudocode.


Exercise 9

BilalComputer.com sell computers, software, TV’s, computer hardware, games and all
types of media such as CD, VHS, DVD and audio book. The store sells CD-RW with
RM3.50 per unit. Calculate the total price when a customer bought 5 units of CD-RW.

a. Define the input, process and output of this task.

b. Draw the flow chart.


c. Write the pseudocode.
Name :

Student ID :

Date :

C. POST-LAB ACTIVITIES
Question 1

Draw a flowchart to calculate and display an average salary of three employees.

Question 2

Write a pseudocode for the problem in Question 1.


Name :

Student ID :

Date :

Question 3

Draw a flow chart to find the highest salary of three employees.

Question 4
Draw a flow chart to calculate an average of a series positive numbers. The process will stop if
the number entered has a negative value.
Name :

Student ID :

Date :

You might also like