Daily Blog - Friday, November 26th, 2010

Turing, a simple language that can make extraordinary programs.

     Today was an amazing class. I found out that Turing can make programs I never knew was possible. Especially by one student, that made a very entertaining run- catch game. The coding was very unusual though. I hope to learn how to make programs like this in the near future. Mr. Arkin showed us a game he made, which was quite good. It involved two players. One player had to write a word, and the other player had to guess it. A simple game but also involved a lot of coding to be done.

     After this we went on the computer to work on our assignments. I worked on refining my repetition 12 assignment, which I think now is probably near- perfect now. Here is the code to all you blog readers.

% declaration section
% constants
const ARRAY_LIMIT := 1000
const DELAY := 3000
const GST_TAX := 0.05
const PST_TAX := 0.08
const SENTINEL_VALUE := 0

% variables
var counter : int
var gst_total : real
var nontaxable_amount : real
var price : array 1 .. ARRAY_LIMIT of real
var priceindex : int
var pst_total : real
var taxable_amount : real
var taxstatus : array 1 .. ARRAY_LIMIT of int
var taxstatusindex : int
var total_price : real

% intro
% colour 8 = gray, colourback 5 = purple
colour (8)
colourback (5)
put "WELCOME TO MASSEULLAH ADEL's PROGRAM! REPETITION ASSIGNMENT 12 USING ARRAYS!"
delay (DELAY)
cls

% initialization section
counter := 0
gst_total := 0
nontaxable_amount := 0
priceindex := 1
pst_total := 0
taxable_amount := 0
taxstatusindex := 1

% input and processing section
loop
    put skip, "What is the price? (To exit enter 0)" ..
    get price (priceindex)
    if price (priceindex) < SENTINEL_VALUE then
        put skip, "Price can not be LESS than 0"
    end if
    counter := counter + 1
    exit when price (priceindex) = 0
    put skip, "What is the tax status?"
    put "1 = NON TAXABLE"
    put "2 = TAXABLE"
    colour (12)
    get taxstatus (taxstatusindex)
    colour (8)
    if taxstatus (taxstatusindex) = 1 then
        nontaxable_amount := nontaxable_amount + price (priceindex)
    elsif taxstatus (taxstatusindex) = 2 then
        taxable_amount := taxable_amount + price (priceindex)
        pst_total := taxable_amount * PST_TAX
        gst_total := taxable_amount * GST_TAX
        total_price := nontaxable_amount + taxable_amount + pst_total + gst_total
    else
        put "YOU MUST ENTER 0 OR 1 FOR THE TAX STATUS!"
    end if
    priceindex := priceindex + 1
    taxstatusindex := taxstatusindex + 1
end loop

% output section
total_price := nontaxable_amount + taxable_amount + pst_total + gst_total
priceindex := 1
taxstatusindex := 1

put "~~~~~~~~~~RECEIPT~~~~~~~~~~"

loop
    if taxstatus (taxstatusindex) = 1 then
        put "Not taxable so... "
        put "Price of item ", priceindex, "= $", price (priceindex)
    elsif taxstatus (taxstatusindex) = 2 then
        put "Price of item ", priceindex, "= $", price (priceindex)
        put "Gst price of item = $", GST_TAX * price (priceindex) : 0 : 2
        put "Pst price of item = $", PST_TAX * price (priceindex) : 0 : 2
    end if
    priceindex := priceindex + 1
    taxstatusindex := taxstatusindex + 1
    exit when priceindex = counter
end loop

put "Subtotal: $", nontaxable_amount + taxable_amount
put "Price of gst tax: $", gst_total : 0 : 2
put "Price of pst tax: $", pst_total : 0 : 2
put "TOTAL PRICE : $", total_price : 0 : 2

     As you can see it is a very long program. It involves two arrays, one for the price and one for the tax status. I finally realize now how to use arrays, unlike Wednesday night, where I was stressing on how to make the arrays work.

     Also we have a test next week but the date is not decided. That doesn't mean I won't study like a maniac. I will hope to study everything by Monday and review my work during the weekdays so I am sure I am 150% prepared for this test. Wish me good luck :).

     For homework we also have the repetition assignments to work on. I still have repetition 13 to do, which I think will be even more challenging then repetition 12. Again, wish me good luck.

Alright fellow blog readers, until next time.
Masseullah Adel

No comments:

Post a Comment