CSEB114: Principle of programming Tutorial 1
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=2r)
Answer Problem Analysis Input: radius Output: area and circumference of a circle Formula: Area=r2 Circumference=2r Constraint: none
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
Answer Flowchart Begin Set pi = 3.14 Read radius, r Area= pi * r * r Circ= 2 * pi* r End Print Area and Circ
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 = 1.609 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.
Answer Problem Analysis Input: distance miles Output: distance in kilometers Formula: kilometer = distance in mile * 1.609 Constraint: none
Answer Pseudocode Begin Read distance if distance is in miles kilometer = distance in miles * 1.609 end_if Print distance in kilometers End
Answer Flowchart Begin Read distance Distance in miles kilometer = distance in miles * 1.609 Print kilometer End yes no