Concept explainers
(Complex Class) Create a class called Complex for performing arithmetic with complex numbers. Write a
{
}
where i is
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 in case no initializers are provided. Provide public member functions that perform the following tasks:
- Adding two Complex numbers: The real parts are added together and the imaginary parts are added together.
- 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.
- Printing Complex numbers in the form (a, b), where a is the real part and b is the imaginary part.
Want to see the full answer?
Check out a sample textbook solutionChapter 17 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Absolute Java (6th Edition)
Modern Database Management
Computer Science: An Overview (12th Edition)
Concepts Of Programming Languages
Starting Out with C++: Early Objects (9th Edition)
- (Person Class) Design a class named Person that contains: o name, gender, and personCase as a private attribute o Non-default constructor that specifies name and gender o toString method that returns person data o personCase () method with no implementation (Student Class) Design a class named Student which is a child of Person that contains: o studentID as a private attribute o Nondefault constructor that specifies the name, gender, and studentID o toString method that returns student data o Implement personCase () that assigns "Not Studying" to personCase if studentID equals 0, “Studying" in case studentID greater than 0, and "Not a student" in case studentID less than 0. (Employee Class) Design a class named Employee which is a child of Person that contains: o employeelD as a private attribute o Non-default constructor that specifies the name, gender, and employeelD o toString method that returns employee data o Implement personCase () that assign “Technical" to personCase if…arrow_forward(After reading the instructions given in the pictures attached, read the following) Class membersdoctorType Class must contain at least these functionsdoctorType(string first, string last, string spl); //First Name, Last Name, Specialty void print() const; //Formatted Display First Name, Last Name, Specialtyvoid setSpeciality(string); //Set the doctor’s Specialtystring getSpeciality(); //Return the doctor’s SpecialtypatientType Class must contain at least these functionsvoid setInfo(string id, string fName, string lName,int bDay, int bMth, int bYear,string docFrName, string docLaName, string docSpl,int admDay, int admMth, int admYear,int disChDay, int disChMth, int disChYear);void setID(string);string getID();void setBirthDate(int dy, int mo, int yr);int getBirthDay();int getBirthMonth();int getBirthYear();void setDoctorName(string fName, string lName);void setDoctorSpl(string);string getDoctorFName();string getDoctorLName();string getDoctorSpl();void…arrow_forwardReadme.md: Stars(C++) This lab exercise will practice creating objects with constructors and destructors and demonstrate when constructors and destructors are called. Star Class Create a class, Star. A Star object has two member variables: its name, and a solar radius. This class should have a constructor which takes a std::string, the name of the star, and a double, the solar radius of the star. In the constructor, the Star class should print to the terminal that the star was born. For example, if you create a Star as follows: Star my_star("Saiph", 22.2); Then the constructor should print: The star Saiph was born. In the destructor, the Star class should print to the terminal that the star was destroyed, along with the number of times the volume of the sun that that star was, formatted to two decimal places. Hint: use the following line to set the precision to 2 decimal places: std::cout << std::fixed << std::setprecision(2); For example, when my_star above has its…arrow_forward
- 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 elapse 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 elapse time. For example, if the elapse time is 555550 seconds, the hour is 10, the minute is 19, and the…arrow_forward- Create a class Rational for performing arithmetic with fractions.Write a driver program to test the class. Provide a constructor thatenables an object of this class to be initialized when it isinstantiated. The constructor should contain default values in caseno initializes are provided and should store the fraction in reducedform. Provide a private function to reduce numbers.Provide Public member functions for each of the followingarithmatic’s functions (addition – subtraction – multiplication –division), printing in the form a/b, printing in floating point formatand final overload the == and != operators to allow comparisons oftwo fraction numbers.Include any additional operations that you think would be useful fora rational number class.Design, implement, and test your class.arrow_forward(The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate class defined in Programming Exercise 10.14 – see the textbook - to create an object for date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person's name. Draw the UML diagram for the classes and implement them. Write a test program that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods.arrow_forward
- Rewrite the calculator program using a class called calculator. Your program will keep asking the user if they want to perform more calculations or quit and will have a function displayMenu to display the different functions e.g .(1 - addition, 2- subtraction, 3- multiplication, 4- division) Your program must have appropriate constructors and member functions to initialize, access, and manipulate the data members as well as : A member function to perform the addition and return the result A member function to perform the subtraction and return the result A member function to perform the multiplication and return the result A member function to perform the division and return the resultarrow_forwardBank Accounts (Use Python) Write a program that accepts bank transactions and prints out the balance of an account afterwards. PROGRAM DESIGN Create a class named bankAccount. A bank account should have the following attributes: accNumber, balance, and dateOpened. This class should also have the option to do the following transactions: deposit, withdraw and drop. Initially there is only one bankAccount active in the program, with a balance amount of 1515, and was opened back in 10/01/1987. Depositing adds to a current bankAccount’s balance, while withdrawing – does otherwise. Dropping would equate the current balance to zero. Refer to the following class diagram for more details about the current bankAccount: bankAccountaccNumber = 1balance = 1515dateOpened = "10/27/1987" deposit(dep)withdraw(wd)drop(accNumber) INPUTThe input would be a string that contains the following data: the transaction to be done (dep – for deposit, wd – for withdraw and drop – for drop), the accNumber, and…arrow_forward2) 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 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 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. Design: Code: Output:arrow_forward
- PS: see image for question.arrow_forwardQ2) Write C++ code to create class called number. The private data members for this class are nobl (double), nob2 (double) and nob3(double). The member function for this class is: 1- (Constructor) that accepts nobl, nob2 and nob3 as arguments (inside the class). Write a main() that create two objects (h1) with initially data members (nob1 :13000, nob2:15 and nob3 :19) , (kl) with initially data members (nob1:16000, nob2:77 and nob3:2018) and (TI) with initially data members (nob1:15000, nob2:37 and nob3:2020). Finally print the information of the object that has smallest nob2 for these three objects using void display friend function:arrow_forward(Date Class) Create a class called Date that includes three pieces of information as auto-implemented properties—a month (type int), a day (type int) and a year (type int). Your class should have a constructor that initializes the three automatic properties and assumes that the values provided are correct. Provide a method DisplayDate that displays the month, day and year separated by forward slashes (/). Write a test app named DateTest that demonstrates class Date’s capabilities.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning