MSEV102
Content covered: Chapter 9
Complete each of the following exercises as a separate project:
Page 432 No 3
Page 432 No 4
Page 432 No 5 (change miles per gallon to kilometres per litre)
Page 433 No 9
The exercises appear below for your convenience:
1. 3. Create an application named SalesTransactionDemo that declares several
SalesTransaction objects and displays their values and their sum. The
SalesTransaction class contains fields for a salesperson name, sales amount, and
commission and a readonly field that stores the commission rate. Include three
constructors for the class. One constructor accepts values for the name, sales amount,
and rate, and when the sales value is set, the constructor computes the commission
as sales value times commission rate. The second constructor accepts a name and
sales amount, but sets the commission rate to 0. The third constructor accepts a name
and sets all the other fields to 0. An overloaded + operator adds the sales values for
two SalesTransaction objects.
2. 4. Create a program named DemoSquares that instantiates an array of 10 Square
objects with sides that have values of 1 through 10 and that displays the values for
each Square. The Square class contains fields for area and the length of a side, and
a constructor that requires a parameter for the length of one side of a Square. The
constructor assigns its parameter to the length of the Square’s side field and calls a
private method that computes the area field. Also include read-only properties to get a
Square’s side and area.
3. 5. Create an application named CarDemo that declares at least two Car objects and
demonstrates how they can be incremented using an overloaded ++ operator. Create
a Car class that contains a model and a value for kilometres per litre. Include two
overloaded constructors. One accepts parameters for the model and kilometres per
litre; the other accepts a model and sets the kilometres per litre to 20. Overload a ++
operator that increases the kilometres per litre value by 1. The CarDemo application
creates at least one Car using each constructor and displays the Car values both
before and after incrementation. (In some other languages, notably C++, you can write
two methods to overload ++ as a prefix and postfix operator. However, when you
overload either the ++ or — operator in C#, the operator can be used either before or
after the object, but the same method executes either way, and there is no difference
in the results.)
4. 9. a. Create a program named FriendList that declares an array of eight Friend
objects and prompts the user to enter data about the friends. Display the Friend
objects in alphabetical order by first name. The Friend class includes autoimplemented properties for the Friend’s name, phone number, and three integers that
together represent the Friend’s birthday—month, day, and year.
9. b. Create a FriendBirthday program that modifies the FriendList program created
in Exercise 9a so that after the list of Friend objects is displayed, the program prompts
the user for a specific Friend’s name and the program returns the Friend’s phone
number and birthday. Display an appropriate message if the friend requested by the
user is not found.
9. c. Create a program named AllFriendsInSameMonth that modifies the program in
Exercise 9b so that after the requested Friend’s birthday is displayed, the program
also displays a list of every Friend who has a birthday in the same month.
Remember: All the exercises must be handed in as a single .zip file.