


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Programming assignments for creating classes in c++ for handling time, complex numbers, and rational numbers. The time class requires adding a tick member function, the complex class requires creating a constructor and member functions for setting, addition, subtraction, and printing complex numbers, and the rational class requires creating a constructor and member functions for addition, subtraction, multiplication, division, and printing rational numbers.
Typology: Lecture notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!
Question 1 Modify the Time class to include a tick member function that increments the time stored in a Time object by one second.
class Time { public: Time( ); void setTime( int, int, int ); void printMilitary( ) void printStandard( ); private: int hour; int minute; int second; };
Question 2
Create a class called Complex for performing arithmetic with complex numbers. (a) Use double variables to represent the private data of the class - real part and imaginary part. (b) Provide a constructor function that enables an object of this class to be initialized when it is declared. (c) Provide public member functions of setting, addition, subtraction, and printing for complex number(s).
Complex numbers have the form realPart + imaginaryPart*i where i is square root of (-1)
Question 3
Question 4
Create a class called Complex for performing arithmetic with complex numbers. Write a driver program to test you class. Complex numbers have the form realPart + imaginaryPart*i where i is square root of (-1)
Use double variables to represent the private data of the class - real part and imaginary part. The constructor should contain default values in case no initializers are provided. Provide public member functions for each of the following: (a) Addition of two Complex numbers: The real parts are added together and the imaginary parts are added together. (b) Subtraction of two Complex numbers: The real part of the right operand is subtracted from the real part of the left operand and the imaginary part of the right operand is subtracted from the imaginary part of the left operand. (c) Printing Complex numbers in the form ( a, b) where a is the real part and b is the imaginary part. (d) Setting Complex number.