Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Object Oriented Programming Please write the code in C++ and answer all the questions Time Class: #include using namespace std; class ComplexNumber { private: int

Object Oriented Programming

Please write the code in C++ and answer all the questions

Time Class:

#include using namespace std; class ComplexNumber { private: int realPart; int imagPart; public: ComplexNumber(int r = 0, int i = 0): realPart(r), imagPart(i) {}; void setComplex(void) { cout > this->realPart; cin >> this->imagPart; } ComplexNumber add(const ComplexNumber& c) { ComplexNumber comp; comp.realPart = this->realPart + c.realPart; comp.imagPart = this->imagPart + c.imagPart; return comp; } ComplexNumber subtract(const ComplexNumber& c) { ComplexNumber comp; comp.realPart = this->realPart - c.realPart; comp.imagPart = this->imagPart - c.imagPart; return comp; } void printComplex(void) { cout realPart imagPart

image text in transcribed

9.7 (Enhancing Class Tine) Modify the Time class of Figs. 9.40-9.5D to include a tick member function that increments the time stored in a Time object by one second. Write a program that tests the tick member function in a loop that prints the time in standard format during each iteration of the loop to illustrate that the tick member function works correctly. Be sure to test the following cases: a. Incrementing into the next minute. b. Incrementing into the next hour. c. Incrementing into the next day (i.e., 11:59:59 PM to 12:00:00 AM) 9.8 Enhancing Class Date Modify the Date class of Figs. 9.13 -9.14 to perform error checking on the inti lizer values for data members month, day and year. Also, provide a member function nextDay to increment the day by one. Write a program that tests function nextDay in a loop that prints the date during each iteration to illustrate that nextDay works correctly. Be sure to test the following cases: a. Incrementing into the next month. b. Incrementing into the next year. 9.9 (Combining Class Time and Class Date) Combine the modified Time class of Exercise 9.7 and the modified Date class of Exercise 9.8 into one class called DateAndTime . (in Chapter 1 1, we'll discuss inheritance, which will enable us to accomplish this task quickly without modifying the existing class definitions.) Modify the tick function to call the nextDay function if the time increments into the next day. Modify functions printstandard and printUniversal to output the date and time. Write a program to test the new class DateAndTime. Specifically, test incrementing the time into the next day

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

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

How can we visually describe our goals?

Answered: 1 week ago

Question

What metaphors might describe how we work together?

Answered: 1 week ago

Question

What are some of the possible scenes from our future?

Answered: 1 week ago