0% found this document useful (0 votes)
559 views4 pages

Model Questions

The document contains a series of programming tasks including a case statement to evaluate a flag value and print corresponding messages, pseudocode for calculating average mileage of a car after six fill-ups, and an algorithm for converting a distance in meters to light-years. Each task includes specific instructions and pseudocode to guide the implementation. Additionally, flowchart tasks are mentioned for visual representation of processes.

Uploaded by

ninavpsninavps
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
559 views4 pages

Model Questions

The document contains a series of programming tasks including a case statement to evaluate a flag value and print corresponding messages, pseudocode for calculating average mileage of a car after six fill-ups, and an algorithm for converting a distance in meters to light-years. Each task includes specific instructions and pseudocode to guide the implementation. Additionally, flowchart tasks are mentioned for visual representation of processes.

Uploaded by

ninavpsninavps
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Q.

Write a case statement that will examine the value of flag and print one of the following
messages, based on the value assigned to the flag. (3 Marks)

Flag value Message


1 HOT
2 LUKE WARM
3 COLD
Any other value OUT OF RANGE

Ans:

CASE flag OF
1: PRINT “HOT”
2: PRINT “LUKE WARM”
3: PRINT “COLD”
OTHERWISE: PRINT “OUT OF RANGE”
ENDCASE

Pseudocode

BEGIN
READ flag
CASE flag OF
1: PRINT “HOT”
2: PRINT “LUKE WARM”
3: PRINT “COLD”
OTHERWISE: PRINT “OUT OF RANGE”
ENDCASE
END

Q. Draw a flowchart to print the numbers that are divisible by 4 but not by 3 in a list of n positive
numbers.
Q. Draw a flowchart to find the average mileage of a car in kilometres per litre after six fill-ups at
petrol pumps. Input data include the number of litres of diesel, the starting odometer reading, and
the odometer reading at each fill-up.

PSEUDOCODE

BEGIN
SET: total_distance = 0,total_fuel = 0
INPUT previous_odometer_reading
FOR i FROM 1 TO 6:
INPUT: odometer_reading (current odometer reading)
INPUT: litres_of_fuel (amount of fuel filled)
distance_covered = odometer_reading - previous_odometer_reading
total_distance = total_distance + distance_covered
total_fuel = total_fuel + litres_of_fuel
SET previous_odometer_reading = odometer_reading.
END FOR
average_mileage = total_distance / total_fuel
DISPLAY average_mileage.
END

total_distance – td

total_fuel – tf

previous_odometer_reading – pr

odometer_reading – cr

litres_of_fuel – ff

distance_covered – dc

average_mileage - mileage
Q. Light travels at 3 × 108 meters per second. A light-year is the distance a light beam travels in
one year. Write an algorithm that inputs a large distance value (in meters) and displays it in light-
years.

Algorithm

1. START
2. Input: Distance_in_meters
3. Define constants

Speed_of_light = 3 × 108 (in meters/second)

Seconds_in_year = 365.25 × 24 × 60 × 60 (total seconds in a year)

4. Calculate the distance light travels in one year (light-year)

Light_year = Speed_of_light × Seconds_in_year

5. Compute the distance in light-years

Distance_in_light_years = Distance_in_meters / Light_year

6. Output the result

DISPLAY "The distance in light-years is: ", Distance_in_light_years

7. STOP

You might also like