Share the knowledge

1.2 Logical structure “sequence”

1.2.1 Sequence Examples

Example Seq1

Problem :- For the computer studies SC exams (old syllabus 7010) students were assessed on a significant piece of practical work (project) and a theory exam. The problem is a very simple one, it is just to find out the total of the 2 assessments.

Solution :-

Data Required                :-       (i) marks for project

(ii) marks for theory exam

Processing involved       :-       total = project + theory

Output Required            :-       total marks

Algorithm :- (only pseudocode shown; as a supplementary exercise do the flowchart)

Read marks for Project

Read marks for Theory exam

Add the marks together

Print the sum

Note :- Instead of Print we can say Output, Display or Write.


Everyone really wants to do something, but there are few that will put forward the needed effort to make the necessary sacrifice to secure it.

Pascal Program:-

program seq1_project;

var

project,theory,sum:real;

begin

write (‘Please key in marks for Project   ‘);

read(project);

write (‘Please key in marks for Theory exam   ‘);

readln (theory);

sum:=project +  theory;

writeln (‘The sum is  ‘,sum)

end.


Example Seq2

Problem :- In an order processing system it is required to calculate the total cost of any product, knowing the price and the quantity ordered.

Solution :-

Data Required                :-       (i) product code

(ii) quantity ordered

(ii) unit price

Processing involved       :-       total cost = quantity ordered * unit price

Output Required            :-       total cost

 

Algorithm :- (only pseudocode shown; as a supplementary exercise do the flowchart)

Read product code

Read quantity ordered

Read unit price

total cost = quantity ordered * unit price

Print the total cost


Pascal Program:-

program seq2_order;

var

product, qty : integer;

price, cost : real;

 

begin

write (‘please key in the product number   ‘);

readln (product);

write (‘please key in the price   ‘);

readln (price);

write (‘please key in quantity required   ‘);

readln (qty);

cost := qty * price;

writeln (‘Product    Quantity  Price        Cost’);

writeln (product:5, qty:10, price:11:2, cost:13:2);

end.


Example Seq3

 

Problem :- A payroll program is to calculate the total pay of an employee.

 

Solution :-

Data Required                :-       (i) no. of hours worked

(ii) rate of pay per hour

Processing involved       :-       total pay = hours * rate

Output Required            :-       total pay

 

Algorithm :- (only pseudocode shown; as a supplementary exercise do the flowchart)

Read no. of hours worked

Read rate of pay per hour

Multiply the hours worked by the hourly pay rate

Print the total pay


Pascal Program:-

program seq3_payroll;

var

hours,rate,pay:real;

begin

write (‘Please enter No. of Hours worked   ‘);

read(hours);

write (‘Please enter rate of pay per hour   ‘);

readln (rate);

pay:=hours *  rate;

writeln (‘The total pay is  ‘,pay)

end.


1.1.1     Sequence Exercises

 

For each of the exercises below you are required to:-

 

  • define an appropriate algorithm using pseudocode language and,
  • write the corresponding pascal program to test your algorithm.
  1. Suppose the government is giving additional allowance to all secondary schools so that they can put tiles in all the classrooms. As a class captain you have been asked to find out the number of titles required for your classroom.
  2. Assuming that last term you sat for 2 tests (one theory and one practical). The maximum marks obtainable for the theory and practical tests are 45 and 15 respectively. The problem is to find out the percentage.
  3. In a currency conversion program, there are 2 modules. The 1st one converts Mauritian rupees to Australian dollars and the 2nd one converts Mauritian rupees to Singapore dollars. For each of the 2 modules define the algorithm and write the corresponding pascal program.

Honest review for Wealthy Affiliate