CS201 – Spring 2001

Prof. Hartman - Homework #10

Due Wednesday, April 25th by 4:00 pm

 

 

Homework to be turned in: (remember that all programs must follow the guidelines from handout #3.)

1.      (5 pts)  Written: What are the differences between struct and class?

2.       (5 pts) Written: Write a prototype of a constructor for class Blar that takes an integer and a float in that order.

3.      (5 pts) Written: In a class, what is the difference between private and public?

4.      (5 pts) Written: Explain what the keyword const means in the function prototype below.

foo::dosomething(int x, char y) const;

5.      (15 pts) Programming: Right Triangle Class

Create a class that represents a right triangle. The class will need to store the base and height of the triangle. You will need to have the following member functions.

Default Constructor

Should initialize base and height to 0.

Constructor

Takes two float values for the base and the height.

base()

Returns the length of the base as a float value.

height()

Returns the height as a float value.

hypotenuse()

Returns the length of the hypotenuse as a float value. The length of the hypotenuse can be calculated using the Pythagorean equation

(base)2 + (height)2 = (hypotenuse)2

area()

Returns the area of the right triangle as a float value. The area can be calculated using the equation

(area) = (0.5) * (base) * (height)

perimeter()

Returns the perimeter of the right triangle as a float value. The perimeter can be calculated using the equation

(perimeter) = (base) + (height) + (hypotenuse)


6.       (15 pts) Programming: Calculator Class

Create a class that emulates a calculator. You will need to store the current value as a float. You will need to have the following member functions.

Default Constructor

Starts the calculator with 0 as the currrent value.

Constructor

Takes in a float value and uses that as the initial current value.

increment()

Takes no parameters. Increments the current value by one.

decrement()

Takes no parameters. Decrements the current value by one.

add(float)

Takes in a float value; adds it to the current value.

subtract(float)

Takes in a float value; subtracts it from the current value.

read()

Returns the current value as a float.

clear()

Sets the current value back to 0.