Author |
Message |
Martin
|
Posted: Fri Aug 20, 2004 4:24 pm Post subject: Are YOU ready for Waterloo CS? |
|
|
http://www.cs.uwaterloo.ca/undergrad/admissions/placement/cs134.shtml
This is the test to see if you are ready for CS 134 (the most advanced of the three first year choices for computer science) at the University of Waterloo.
Note: don't email it to the guys unless you actually are attending the university .
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dan
|
Posted: Fri Aug 20, 2004 7:11 pm Post subject: (No subject) |
|
|
dose not seem that hard to me, i think i had a question alot like that on my grade 12 compsci exame that was on java.
|
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
wtd
|
Posted: Fri Aug 20, 2004 7:35 pm Post subject: (No subject) |
|
|
It does seem pretty easy.
|
|
|
|
|
|
Dan
|
Posted: Fri Aug 20, 2004 7:50 pm Post subject: (No subject) |
|
|
Well i guse they do not expceted you to know everything, alot of poleop could have had no compsci corses during high school and/or not progaming excpicen at all. So that whould probly be a good way to weed out any one that has no progaming excpricne from going in to the highested 1st year level right away.
|
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
wtd
|
Posted: Fri Aug 20, 2004 8:00 pm Post subject: (No subject) |
|
|
And, I suppose, to figure out which people are willing to take the time to figure it out, if they didn't already know.
Would it be wrong to post a solution in another language?
I keep hacking stuff together to work my mind around the baroqe syntax of O'Caml.
|
|
|
|
|
|
Martin
|
Posted: Fri Aug 20, 2004 10:51 pm Post subject: (No subject) |
|
|
Post it if you want. It's not a test or anything, and anyone at this point who's in CS 134 is stuck in CS 134. Also, Dan, it's required that you have ICS 3M to get into this course (and a teacher recommendation...a joke to get).
|
|
|
|
|
|
wtd
|
Posted: Fri Aug 20, 2004 11:30 pm Post subject: (No subject) |
|
|
The module:
code: | module RealEstate =
struct
let sum_list = List.fold_left (fun a b -> a +. b) 0.
class agent name =
object(self)
val mutable commissions = []
method get_name = name
method name_nil = name = ""
method add_commission amount =
commissions <- amount :: commissions
method total_commissions = sum_list commissions
end
exception No_listing_agent
class basic_property address init_asking_price =
object(self)
val mutable asking_price = init_asking_price
val mutable selling_price = 0
val mutable listing_agent = ref (new agent "")
val mutable selling_agent = ref (new agent "")
val mutable sold = false
method private listing_agent_commision_rate = 0.
method private selling_agent_commision_rate = 0.
method get_asking_price = asking_price
method get_selling_price = selling_price
method get_address = address
method increase_asking_price_by amount =
asking_price <- asking_price + amount
method decrease_asking_price_by amount =
asking_price <- asking_price - amount
method set_selling_price amount =
selling_price <- amount
method has_listing_agent = not !listing_agent#name_nil
method has_selling_agent = not !selling_agent#name_nil
method get_listing_agent = !listing_agent
method get_selling_agent = !selling_agent
method set_listing_agent new_agent =
listing_agent <- ref new_agent
method set_selling_agent new_agent =
selling_agent <- ref new_agent
method sold = sold
method set_sold = sold <- true
method as_string =
if sold then
Printf.sprintf "The property at %s sold for $%d" address selling_price
else
Printf.sprintf "The property at %s is for sal, asking $%d" address asking_price
method close =
let listing_agent_commission =
((float_of_int selling_price) *. self#listing_agent_commision_rate) and
selling_agent_commission =
((float_of_int selling_price) *. self#selling_agent_commision_rate) in
if self#has_listing_agent && self#has_selling_agent then
begin
!listing_agent#add_commission listing_agent_commission;
!selling_agent#add_commission selling_agent_commission
end
else if self#has_listing_agent then
let total_commission = listing_agent_commission +. selling_agent_commission in
!listing_agent#add_commission total_commission
else
raise No_listing_agent;
self#set_sold
end
class residential_property address init_asking_price =
object(self)
inherit basic_property address init_asking_price as super
method private listing_agent_commision_rate = 0.02
method private selling_agent_commision_rate = 0.03
end
class rental_property address init_asking_price rental_income =
object(self)
inherit basic_property address init_asking_price as super
method private listing_agent_commision_rate = 0.03
method private selling_agent_commision_rate = 0.03
method rental_income = rental_income
method as_string =
super#as_string ^ Printf.sprintf ", and offers annual rental income of $%d" rental_income
end
end |
A simple sample:
code: | open RealEstate
open Printf
include RealEstate
let prop = new residential_property "42 Oak St." 2_000
let lister = new agent "Bob Smith"
prop#set_listing_agent (ref lister)
prop#set_selling_price 3_000
prop#close
Printf.printf "Commission: %f\n" lister#total_commissions |
O'Caml: Because static typing can be useful, but explicitly stating those types is lame.
|
|
|
|
|
|
Martin
|
Posted: Sat Aug 21, 2004 12:27 am Post subject: (No subject) |
|
|
How do I do java inheritance without protected variables?
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Sat Aug 21, 2004 2:53 am Post subject: (No subject) |
|
|
Darkness wrote: How do I do java inheritance without protected variables?
Properly.
For something this simple, the child class shouldn't need to directly access the parent class' instance variables. Rather you use the interface exposed by the parent class.
This is where accessors (get, set) come in handy.
|
|
|
|
|
|
Martin
|
Posted: Sat Aug 21, 2004 9:44 am Post subject: (No subject) |
|
|
The inheritence that I was using was CRentalProperty extends CProperty.
Now, everything is the same as CProperty, except there is also an annual income.
How do I do this (efficiently) without using protected variables? And what's so bad about protected variables anyway?
|
|
|
|
|
|
rizzix
|
Posted: Sat Aug 21, 2004 11:49 am Post subject: (No subject) |
|
|
hmm nothing?!?
|
|
|
|
|
|
wtd
|
Posted: Sat Aug 21, 2004 8:49 pm Post subject: (No subject) |
|
|
Darkness wrote: The inheritence that I was using was CRentalProperty extends CProperty.
Now, everything is the same as CProperty, except there is also an annual income.
How do I do this (efficiently) without using protected variables? And what's so bad about protected variables anyway?
I'm guessing they want to see if you can realize that you don't need protected variables in this case.
Why would CRentalProperty need to access the instance variables of CProperty?
|
|
|
|
|
|
wtd
|
Posted: Sat Aug 21, 2004 9:42 pm Post subject: (No subject) |
|
|
Feel free to peruse the attached file and comment freely.
Python version added.
Ruby version added.
Eiffel version added.
I love demonstrating the beauty of these languages.
Description: |
|
Download |
Filename: |
main.e.txt |
Filesize: |
4.58 KB |
Downloaded: |
666 Time(s) |
Description: |
|
Download |
Filename: |
main.rb.txt |
Filesize: |
2.51 KB |
Downloaded: |
709 Time(s) |
Description: |
|
Download |
Filename: |
main.py.txt |
Filesize: |
2.45 KB |
Downloaded: |
654 Time(s) |
Description: |
|
Download |
Filename: |
RealEstate.java |
Filesize: |
4.64 KB |
Downloaded: |
902 Time(s) |
|
|
|
|
|
|
|