TutorialTopic 2(2)
SEQUENCE STRUCTURE
Question 1:
a) Find at least TWO logic errors in the following program :
#include <iostream.h>
void main()
{
int total, num1;
cout << “Please enter a number : “;
cin >> num1;
total = total + num1;
cout <<”\n Please enter another number :”;
int num2;
cin >> num2;
total = total + num1;
float average = total/2;
cout << “\n The average of the two numbers is “<<average <<’\n’;
}
b) Identify the errors, if any, in the following program.
i. void main() ii. void main()
{ {
int x, y; int p, q, sum;
cout << “Enter the value of x and y ‘; p = q = 10;
cin >> x, y; sum + 1 = p * q;
cout >> “The sum is “ << sum;
} }
iii. void main() iv. void main()
{ {
char x, y; int a, b;
x = 5; cout << “Enter two number ‘;
y = “siapa”; cin >> a, b;
cout << x << y; cout << “The sum is “ << a + b;
} }
Question 2:
a) Design a flowchart to represent Step 1 –Step 3 below.
b) Write a complete program to allow the following data processing:
i. Declare the variables (name, program code, part, CGPA).
ii. Ask the user the data of name, program code, part, and CGPA.
iii. Display the data in a proper format.
Question 3:
Company ABC Sdn Bhd is planning to develop a program to summarize their employees’
salary information. Each of the employee is required to register the name, IC number, ID
number (in format 123456) and salary data. Identify the data needs for the program.
Design the simple flow to allow the registration process for one employee. And finally
deploy your analysis and design to build a complete program.