Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C++ Assignments: Creating Classes for Time, Complex, and Rational Numbers, Lecture notes of Computer Programming

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

2012/2013

Uploaded on 04/27/2013

kid
kid 🇮🇳

4.3

(18)

111 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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
pf3
pf4

Partial preview of the text

Download C++ Assignments: Creating Classes for Time, Complex, and Rational Numbers and more Lecture notes Computer Programming in PDF only on Docsity!

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.