Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help using Classes and object orientation
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
dwarf1579




PostPosted: Sun May 03, 2009 9:24 pm   Post subject: Help using Classes and object orientation

I have two problems that need to be solved and I have no idea how to do them.


The balloons centre is the centre of the circle. The circle can be any colour, but the string is always black.
the circle can instantly grow (or shrink) by a specified percent. EX a growth factor of 1.10
will make the balloons radius increase to 110 percent of its present value
(but not redrawn on the screen. A growth factor of .85 will make it shrink to 85 percent
of its current radius. A balloon cannot have a radius that is less than zero.
Balloons can have different string lengths. A balloon can be popped either by being
pricked by a pin or by growing beyond its maximum radius.
When it pops, the circle will briefly change its colour to a yellow then display only the
string. Once popped, a balloon cannot grow or pop again. It can be drawn but only the string will show
A pin has a head and a tail as shown and is always drawn in black.
A pin consists of a line drawn between its head and its point, having a circle centred at
is head with a 5 pixel radius. A pin can be positioned by specifying both its head and
its point (x,y) coordinates.

1. create a balloon class stored in a file called balloon.tu that will include all of
the encapsulated data and the methods necessary to model the balloon as described above.
Write a main program called ooptest1.t that will create two balloons having different sizes,
at different in different colours. Using a loop, make one grow by 5% until it pops.
Using another loop, make the other shrink by 5% until its radius is zero

2. Create a pin class stored in a file called pin.tu that will include all of
the encapsulated data and methods necessary to model the pin as described above.
Write a main program called ooptest2.t that will create two pins.
Randomly choose the head and the tail of the first pin. Position the point of the
second pin directly on top of the tail of the first pin and randomly choose
the tail of the second pin.

3. Write a main program called ooptest3.t that will display a balloon at the centre of
the screen. Wait one second and then at one tenth of a second intervals, display a
series of up to 100 randomly placed pins on the screen. Stop when one of the pins pops
the balloon. Use a method to check if the balloon has been popped. If the balloon pops, then
redraw all of the pins that you have drawn so far.



If you can help me that will be greatly appreciated.


This is the already given code for the first part. This is called Balloon.tu

Turing:
unit
class Balloon
    export draw, erase, setColor, setRadius, setTailLength, getColor, getRadius, getTailLength, setCentre, getCentre
    %encap data for all shapes
    var radius : int := 20
    var tailLength : int := 10
    var x : int := 100
    var y : int := 100
    var icolor : int := 7

    proc setColor (inum : int)
        if inum > -1 and inum < 225 then
            icolor := inum
        end if
    end setColor

    proc setRadius (inum : int)
        if inum >= 0 and inum < 100 then
            radius := inum
        end if
    end setRadius

    proc setTailLength (inum : int)
        if inum >= 0 and inum < 100 then
            tailLength := inum
        end if
    end setTailLength

    proc setCentre (inumx, inumy : int)
        if inumx >= 0 and inumx < 540 and inumy >= 0 and inumy < 480 then
            x := inumx
            y := inumy
        end if
    end setCentre

    function getRadius : int
        result radius
    end getRadius

    function getTailLength : int
        result tailLength
    end getTailLength

    function getColor : int
        result icolor
    end getColor

    proc getCentre (var px, py : int)
        px := x
        py := y
    end getCentre

    procedure draw
        Draw.FillOval (x, y, radius, radius, icolor)
        Draw.Line (x, y - radius, x, y - 2 * radius, black)
    end draw

    procedure erase
        Draw.FillOval (x, y, radius, radius, white)
        Draw.Line (x, y - radius, x, y - 2 * radius, white)
    end erase
end Balloon



Please help me.

Mod Edit: Remember to use syntax tags! Thanks Smile
code:
[syntax="turing"]Code Here[/syntax]
Sponsor
Sponsor
Sponsor
sponsor
Dusk Eagle




PostPosted: Sun May 03, 2009 10:12 pm   Post subject: Re: Help using Classes and object orientation

You're asking us to do your homework for you. NO. Besides the fact that it is against forum rules, it neither teaches you anything nor demonstrates any ability to code at all. Even if someone did do this for you, the only mark you'd deserve would be a zero (in University they might even expel you).
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: