# PRG1002 Simple Programming Application Programming 1 Assessment 2 Answer

Pages: 4 Words: 890

## Question :

 Subject Code and Name PRG1002 Programming 1 Assessment Number 2 Assessment Title Simple Programming Application Assessment Type Individual - Application Code Length or Duration Four (4) Programs / Tasks Weighting 25%

Assessment Purpose

Many common problems solved by programmers include manipulation of numeric values and lists of numbers. In this assessment, you will use your understanding of the fundamental programming principles to solve four problems that involve numbers.

Assessment Item

For this assessment, you must submit four (4) algorithm descriptions and C++ programs, one for each task described in the brief below

Assessment Instructions

This assessment consists of four (4) tasks. You will need to prepare the following two components for each task.

Component 1: Algorithms

An algorithm is a set of well-defined instructions in sequence to solve the problem. An algorithm should not be computer code. Instead, the algorithm should be written in such a way that it can be used in similar programming languages to implement a solution in code.

Example: Find the largest of two numbers entered by the user.

Step 1: Start

Step 2: Declare variables a and b

Step 3: Get input from the user for a and b Step 4: if a is greater than b

Step 4.1: print a Step 5: if b is greater than a

Step 5.1: print b Step 6: Stop

Component 2: C++ Coding

You will provide a C++ program for each of the four (4) questions given below that implements the algorithm you describe in Part 1.

Write a program that allows the user to enter the mark scored within a range of 0 - 50. Given a positive value, do the following:

• If the given score is between 0 and 50 (0 ≤ score ≤ 50), then calculate the percentage (e.g., 100% for 50, 75% for 37.5, etc). A percentage is a number or ratio that represents a fraction of 100.

F, if the percentage is 0 - 59.99. D, if the percentage is 60 - 69.99. C, if the percentage is 70 - 79.99. B, if the percentage is 80 - 89.99. A, if the percentage is 90 - 100.

• If the given score is greater than 50, print “Score is greater than 50.”.

Example 1

Example 2

Example 3

Example 4

Score is greater than 50.

Note: Inputs from the user are shown in bold blueTask 2 - Calculate Miles per Gallon

Write a program that allows a user to enter the litres of petrol consumed and the number of miles travelled by the car. Given a positive value for both litres of petrol and miles travelled, calculate the number of miles per gallon the car delivered. One litre of petrol is 0.264179 gallons.

You must show the output in three decimal places as shown in the example.

Example

Please enter the number of litres of petrol consumed: 15.5

Please enter the number of miles travelled: 75

Petrol Consumed: 15.500

Miles Travelled: 75.000 Miles per gallon: 18.316

Note: Inputs entered by the user are shown in bold blueTask 3 - Looping Through all Numbers from Start to Finish

Write a program that prompts the user to input two (2) integer values; a starting value and an end value. Loop through all the values from start to end, which should include the start and end values. For each value:

• If the number is divisible by both 3 and 5, print the word “ticktock”. For example for 15, 30, and 45 you would print “ticktock”.
• Else if it is a multiple of 3 (value % 3 == 0), print the word “tick”. For example, for 3, 6, and 9 you would print “tick”.
• Else if it is a multiple of 5 (value % 5 == 0) , then print “tock”. For example, for 5, 10, and 20 you would print “tock”.
• Else if it is not divisible by 3 or 5, print the number. For example, for 1 you would just print ‘1’.

Example

Please enter a start value: 4

Please enter an end value: 15

tock tick 7

8

tick tock 11

tick 13

14

ticktock

Note: Inputs entered by the user are shown in bold blueTask 4 - Order Numbers

Write a program that prompts the user to input 3 integer values and print these values in ascending and

descending order.

Example

Please enter the first number: 45 Please enter the second number: 12 Please enter the third number: 78

Ascending order:

12

45

78

Descending order:

78

45

12

Note: Inputs entered by the user are shown in bold blue.