Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSEB114: Principle of programming

Similar presentations


Presentation on theme: "CSEB114: Principle of programming"— Presentation transcript:

1 CSEB114: Principle of programming
Tutorial 1

2 Question 1 You are required to design a program that will computes and displays a circle’s area and circumference, given its radius. The program should repeatedly continue calculating and displaying the area and circumference until the user enter 0 for radius. Use pseudocode and flow chart. (Area=r2, Circumference=2r)

3 Answer Problem Analysis Input: radius
Output: area and circumference of a circle Formula: Area=r2 Circumference=2r Constraint: none

4 Answer Pseudocode Begin Set pi = 3.14 Read radius, r
Calculate Area = pi * r * r Calculate Circumference = 2 * pi * r Print Area and Circumference End

5 Answer Flowchart Begin Set pi = 3.14 Read radius, r Area= pi * r * r
Circ= 2 * pi* r End Print Area and Circ

6 Question 2 You are assigned a job that requires you to study some maps that give distances in kilometres and some use miles. You prefer to deal in metric measurement. (Note: 1 mile = km) Analyse the problem by identifying the input, output, constraints (if any) and the formula required to solve the problem Design an algorithm to solve the problem using pseudocode and flowchart diagram.

7 Answer Problem Analysis Input: distance miles
Output: distance in kilometers Formula: kilometer = distance in mile * 1.609 Constraint: none

8 Answer Pseudocode Begin Read distance if distance is in miles
kilometer = distance in miles * 1.609 end_if Print distance in kilometers End

9 Answer Flowchart Begin Read distance Distance in miles
kilometer = distance in miles * 1.609 Print kilometer End yes no


Download ppt "CSEB114: Principle of programming"

Similar presentations


Ads by Google