Wednesday, November 17, 2010

Wednesday - Rest of Repetition Assignments

    As I stated in my last post, I did not want my posts to become so clustered with information, therefore I decided to post the rest of the repetition assignments (# 11, 12, 13) on this post. If there are any mistakes please comment on this post and I will do my best to fix, as soon as possible. Here they are:

#11

%declaration section
var sum_of_numbers : int := 0
var number : int
var total_of_numbers : int := 0
var mean : real
var answer : string

%input and processing section
loop
    colourback ( black )
    cls
    colour (43)
    put "Number? : " ..
    get number
    if number not= 0 then
    sum_of_numbers := number + sum_of_numbers
    total_of_numbers := total_of_numbers + 1
    colour (5)
    put skip, "You have ", total_of_numbers, " number stated."
    colour (red)
    put skip, "The sum of your numbers is, ", sum_of_numbers, "."
    colour (9)
    put skip, "More numbers (yes/no)? " ..
    get answer
    else
    put skip, "Enter any number other than 0 "
    end if
    exit when answer = "no" or answer = "NO" or answer = "No"
end loop

% extro
colourback (blue)
cls
mean := sum_of_numbers / total_of_numbers
colour (8)
put "The mean of your marks is: ", mean : 0 : 2

# 12

% documentation section
% Produce a cash-register receipt: Gather price and tax-status data,
% item by item, display those data, then display the total PST, total GST,  

and overall total. (Hints: For each item, gather the price and its   
% taxable status with a single get statement, and use an appropriate
% number of accumulators. )

%
% declaration section
const GST := 0.05
const PST := 0.08

var answer : string
var item_price : real
var number_of_items : int := 0
var tax_status : string
var total : real := 0
var total_without_tax : real := 0
var tax_PST : real := 0
var tax_GST : real := 0

% input and processing section
loop
colourback(black)
cls
colour ( 43 )
put "Item price: $" ..
get item_price

if item_price > 0 then
number_of_items := number_of_items + 1
tax_GST := GST * item_price
tax_PST := PST * item_price
total_without_tax := total + item_price
total := total + item_price + tax_GST + tax_PST

colour(white)
put repeat ("=" ,20)
put repeat ("=" ,20)

colour(red)
put skip, "Price of item(s) : $", total_without_tax : 0 : 2
put skip, "GST : $", tax_GST : 0 : 2
put skip, "PST : $", tax_PST : 0 : 2
put skip, "Total : $", total : 0 : 2
put skip, "Number of items : $", number_of_items
colour(white)
put repeat ("-" ,20)
else
put "Please enter valid price!"
end if
colour(purple)
put skip, "Continue? (y/n) " ..
get answer
exit when answer = "n" or answer = "N"
end loop
% extro
colourback (red)
cls
colour(blue)
put "Thank you! " 

# 13

% declaration section
const child := 5
const adult := 10
const senior := 7.50
var ticket_type : string
var number_of_tickets : int := 0
var total_price_of_tickets : real := 0
var answer : string
% input and processing section
loop
    colourback (black)
    cls
    colour (43)
    put "Ticket type (adult/senior/children) : " ..
    get ticket_type
    number_of_tickets := number_of_tickets + 1
    if ticket_type = "adult" or ticket_type = "Adult" or ticket_type = "ADULT" then
        total_price_of_tickets := total_price_of_tickets + adult
    elsif ticket_type = "senior" or ticket_type = "Senior" or ticket_type = "SENIOR" then
        total_price_of_tickets := total_price_of_tickets + senior
    elsif ticket_type = "children" or ticket_type = "Children" or ticket_type = "CHILDREN" then
        total_price_of_tickets := total_price_of_tickets + child
    else
        put "Enter valid type of ticket ! "
    end if
    colour (red)
   
    put "Continue? (y/n) " ..
    get answer
    exit when answer = "n" or answer = "N"
end loop
% extro
colour (purple)
put "The total amount of tickets you purchased is : ", number_of_tickets, ", and must pay : $", total_price_of_tickets : 0 : 2, " for the tickets. "
 
  I hope these assignments can help everyone carry on with the repetition assignments. Once more if anyone has any questions or concerns please comment on this post, I will truly appreciate it.

No comments:

Post a Comment