Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

9 . 1 ( The Rectangle class ) Design a class named Rectangle to represent a rectangle. The class contains: Two double data fields named

9.1
(The Rectangle class) Design a class named Rectangle to represent a rectangle.
The class contains:
Two double data fields named width and height that specify the width and height of the rectangle.
A no-arg constructor that creates a rectangle with width 1 and height 1.
A constructor that creates a default rectangle with the specified width and height.
The accessor and mutator functions for all the data fields.
A function named getArea that returns the area of this rectangle.
A function named getPerimeter that returns the perimeter.
Draw the UML diagram for the class. Implement the class. Write a test program that creates two Rectangle objects. Assign width 4 and height 40 to the first object and width 3.5 and height 35.9 to the second. Display the properties of both objects and find their areas and perimeters.
9.3
(The Account class) Design a class named Account that contains:
An int data field named id for the account.
A double data field named balance for the account.
A double data field named annualInterestRate that stores the current interest rate.
A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0.
The
accessor
and
mutator functions for id, balance, and
annualInterestRate.
A function named getMonthlyInterestRate that returns the monthly interest rate.
A function named withdraw(amount) that withdraws a specified amount from the account.
A function named deposit (amount) that deposits a specified amount to the account.
Draw the UML diagram for the class. Implement the class. Write a test program that creates an Account object with an account ID of 1122, a balance of 20000, and an annual interest rate of 4.5%. Use the withdraw function to withdraw $2500, use the deposit function to deposit $3000, and print the balance, the monthly interest.
*9.5
(The Time class) Design a class named Time. The class contains:
Data fields hour, minute, and second that represent a time.
A no-arg constructor that creates a Time object for the current time.
A constructor that constructs a Time object with a specified elapsed time since the middle of night, Jan 1,1970, in seconds.
A constructor that constructs a Time object with the specified hour, minute, and second.
Three get functions for the data fields hour, minute, and second.
A function named setTime(int elapseTime) that sets a new time for the object using the elapsed time.
Draw the UML diagram for the class. Implement the class. Write a test program that creates two Time objects, one using a no-arg constructor and the other using Time (555550), and display their hour, minute, and second.
(Hint: The first two constructors will extract hour, minute, and second from the elapsed time. For example, if the elapsed time is 555550 seconds, the hour is 10, the minute is 19, and the second is 9. For the no-arg constructor, the current time can be obtained using time(0), as shown in Listing 2.9, ShowCurrentTime.cpp.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Make a presentation about OWASP Threat modeling methodology?

Answered: 1 week ago