0% found this document useful (0 votes)
10 views

Tutorial Task 1.2 - Answers V2

Uploaded by

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

Tutorial Task 1.2 - Answers V2

Uploaded by

tito.yame96
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Answers to Questions from TT1.

2
Name:
Student ID:

1. Desk Check Task: Calculate Bill Total


Required Variables:
Real (floating point):
appetizer_price, main_price, dessert_price
total_price

Pseudocode:
Read the value of appetizer_price
Read the value of main_price
Read the value of dessert_price
total_price = appetizer_price + main_price + dessert_price
Print ‘$’ then the value of total_price to the terminal showing two
decimal places.

Test Data:
First data set Second data set
appetizer_pric 10.30 12.40
e
main_price 34.00 41.00
dessert_price 8.50 9.80

Expected Result:

First data set Second data set


Output: $52.80 $63.20
Desk check - fill this in by hand-tracing/hand-executing the pseudocode
provided with the test data above:

Statement appetize main dessert total output


r _price _price _pric 2.
_price e
C
First Read the value of
Pass appetizer_price
Read the value of
main_price
Read the value of
dessert_price
Calculate the total_price
Convert to dollars
Output the total_price
Secon Read the value of
d Pass appetizer_price
Read the value of
main_price
Read the value of
dessert_price
Calculate the total_price
Convert to dollars
Output the total_price
omplete Program Calculate Bill Total

Now check the actual code produces the output you expected

Do this by completing the missing code in bill_total.rb in Task 1.3 then running the
program.

3. Short Answer Questions:

Focus in the following on using the correct computing terminology.

Here are some terms that may help you: Assignment, evaluate, increment,
1. Using a few sentences explain why it may be important to execute statements in
the correct sequence. (eg: what might happen if the last statement in Program 2
was executed earlier)

2: The code main_price = 10 is an example of which kind of programming


statement?

This is an ???? statement.

3: What actions does the computer perform when it executes a = a + b?

The computer first ????


Then it ????

4: How would the value of variable i change in the statement i = i + 1?

The value of i will be ???

5: What sort of types will Ruby use to store the following variables (given the
associated variable values)?

Data Type

A person's name e.g: “Fred Smith”

Number of students in a class e.g: 23

Average age of a group of people e.g: 23.5

A temperature in Celsius e.g: 45.7

True or false e.g: 1 == 2

Note: possible types include: Integer, String, Float, Boolean


6: Variables have a scope – what are two different scopes variables can have in
Ruby?

See the lesson materials for help with Question 6. You could also see:
https://www.tutorialspoint.com/ruby/ruby_variables.htm

You might also like