Question

Object Oriented Programming

Please write the code in C++

Please answer the question in text form

9.5 (complex Class) Create a class called complex for performing arithmetic with complex numbers. Write a program to test your class. Complex numbers have the form where i is V-I Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when its declared. The constructor should contain default values in case no initializers are provided. Provide public member functions that perform the following tasks: a. Adding two complex numbers: The real parts are added together and the imaginary parts are added together b. Subtracting 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. 9.7 (Enhancing Class rime) Modify the Time class of Figs.9.4 D-9.5to 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 initializer 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 rime and Class Date) Combine the modified rime class of Exercise 9.7 and the modified Date class of Exercise 9.8 into one class called DateAndTime . (in Chapter 11 , well 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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answering the first part of your question :

The class ComplexNumber containing Add, Subtract and print functions.


#include <iostream>
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 << "Enter the realPart and imaginary parts : ";
cin >> 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 << "(" << this->realPart << ", " << this->imagPart << ")"<<endl;
}
};

Add a comment
Know the answer?
Add Answer to:
Object Oriented Programming Please write the code in C++ Please answer the question in text form...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN C++ pls. Modify the Time class of Figs. 9.8–9.9 of your book 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 me...

    IN C++ pls. Modify the Time class of Figs. 9.8–9.9 of your book 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...

  • IN C++ pls. Modify the Time class of Figs. 9.8–9.9 of your book to include a...

    IN C++ pls. Modify the Time class of Figs. 9.8–9.9 of your book 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...

  • C++ Complex Class! Create a class called Complex for performing arithmetic with complex numbers. Write a...

    C++ Complex Class! Create a class called Complex for performing arithmetic with complex numbers. Write a program to test your class. Complex numbers have the form realPart + imaginaryPart * i where i is Squareroot -1 Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when ifs declared. The constructor should contain default values in case no initializers are provided. Provide public member functions that...

  • C++ Create a class called Complex for performing arithmetic with complex numbers. Write a program to...

    C++ Create a class called Complex for performing arithmetic with complex numbers. Write a program to test your class. Complex numbers have the form realPart + j imaginaryPart Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided. Provide public member functions that perform the following tasks: Adding two Complex...

  • Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form:...

    Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form: realPart + imaginaryPart * i where i is √-1 Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it’s declared. The constructor should contain default values of (1,1) i.e. 1 for the real part and 1 for the imaginary part. Provide public member functions that perform the following...

  • write a C programming code for the following prompt. please use stucture concept and test if...

    write a C programming code for the following prompt. please use stucture concept and test if the code works perfectly. Project Description: In this project, you will write a program to calculate the roots of a quadratic equation. Structure concepts will be used in this project. Your program will prompt the user to enter the coefficients of a quadra coefficientsType. Then it will compute the roots of the quadratic equation and store the result in a structure variable of type...

  • c++ 2) Complex Class A complex number is of the form a+ bi where a and...

    c++ 2) Complex Class A complex number is of the form a+ bi where a and b are real numbers and i 21. For example, 2.4+ 5.2i and 5.73 - 6.9i are complex numbers. Here, a is called the real part of the complex number and bi the imaginary part. In this part you will create a class named Complex to represent complex numbers. (Some languages, including C++, have a complex number library; in this problem, however, you write the...

  • c++ programming language Instructions In this exercise, you will design the class memberType. Each object of...

    c++ programming language Instructions In this exercise, you will design the class memberType. Each object of memberType can hold the name of a person, member ID, number of books bought, and amount spent. Include the member functions to perform the various operations on the objects of memberType—for example, modify, set, and show a person’s name. Similarly, up-date, modify, and show the number of books bought and the amount spent. Add the appropriate constructors. Write the definitions of the member functions...

  • JAVA PROGRAMMING A complex number is a number in the form a + bi, where a...

    JAVA PROGRAMMING A complex number is a number in the form a + bi, where a and b are real numbers and i is V-1. The numbers a and b are known as the real part and imaginary part of the complex number, respectively. You can perform addition, subtraction, multiplication, and division for complex numbers using the following formulas: a + bi + c + di = (a + c) + (b + di a + bi - (c +...

  • Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and...

    Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and please add comments for the whole code. Include a class diagrams, and explain the approach you used for the project and how you implemented that, briefly in a few sentences. Please note the following: -Names chosen for classes, functions, and variables should effectively convey the purpose and meaning of the named entity. - Code duplication should be avoided by factoring out common code into...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT