In C++,
Create a class COMPLEXNUM, each has two private member data, ipart and rpart, both are doubles. Create three COMPLEXNUM objects, for the first two set the ipart and rpart either manually or from the keyboard (you pick) then create a function with this structure:
COMPLEXNUM ADDTWO(COMPLEXNUM CN1, COMPELXNUM CN2);
Add the rparts and add the iparts from them set the sums as data in the third COMPLEXNUM and return it to main(), then display all three to the screen, something like this:
CN1 rpart = 4 ipart = 3
CN2 rpart = 5 ipart = -1
CN3 rpart = 9 ipart = 2
#include<iostream>
using namespace std;
class COMPLEXNUM{
private:
double ipart;
double rpart;
public:
// constructor
COMPLEXNUM()
{
this->ipart = 0.0;
this->ipart = 0.0;
}
// constructor
COMPLEXNUM(double r, double i)
{
this->ipart = r;
this->ipart = i;
}
// setter method
void setReal(double r)
{
this->rpart = r;
}
void setImaginary(double i)
{
this->ipart = i;
}
// getter method
double getReal()
{
return this->rpart;
}
double getImaginary()
{
return this->ipart;
}
};
COMPLEXNUM ADDTWO(COMPLEXNUM CN1, COMPLEXNUM CN2)
{
// calculate real part
double r = CN1.getReal() + CN2.getReal();
// calculate imaginary part
double i = CN1.getImaginary() + CN2.getImaginary();
// calculate the resultant object
COMPLEXNUM ans(r, i);
return ans;
}
void display(COMPLEXNUM CN)
{
cout<<"rpart = "<<CN.getReal()<<" ipart = "<<CN.getImaginary()<<endl;
}
int main()
{
COMPLEXNUM CN1(4, 3);
COMPLEXNUM CN2(5, -1);
COMPLEXNUM CN3 = ADDTWO(CN1, CN2);
cout<<"CN1 ";
display(CN1);
cout<<"CN2 ";
display(CN2);
cout<<"CN3 ";
display(CN3);
return 0;
}
In C++, Create a class COMPLEXNUM, each has two private member data, ipart and rpart, both...
Create a class called Skateboard. Skateboard has 3 private member variables and 3 public member functions.(C++, Visual Studios) Skateboard has the following 3 private member variables: 1) the brand of the skateboard (such as “Sector 9”) 2) the model of the skateboard (such as “Hot Steppa”) 3) the length of the skateboard in inches (such as “22”) Skateboard has the following 3 public member functions: a member function named print which does not have any return value or input...
C++ Define the class HotelRoom. The class has the following private data members: the room number (an integer) and daily rate (a double). Include a default constructor as well as a constructor with two parameters to initialize the room number and the room’s daily rate. The class should have get/set functions for all its private data members [3pts]. The constructors and the set functions must throw an invalid_argument exception if either one of the parameter values are negative. The exception...
C++C++
Exercise 1: Create a class Resource. The class should have: a) Two private variables status and writeTo representing integer value either 0 or 1. b) One default constructor that initializes the status and writeTo to zero. c) One single parameterized constructor to initialize the writeTo variable. d) Two constant accessor functions per class that return the values of status e) Two mutator functions per class that set the values of status and writeTo One output (member) function that outputs...
Write the definition for a generic class called time that has hours and minutes as structure. The class has the following member functions: SetTime to set the specified value in object ShowTime to display time object Sum to sum two time object & return time Write the definitions for each of the above member functions. Write main function to create three time objects. Set the value in two objects and call sum() to calculate sum and assign it in third...
Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...
Create a class named Date in C++ Class has 3 private data items (name the data items month, day, year) int month int day int year Member functions ‘getters’ a getter for each data item Use ‘get’ and the data items name The data item name must be capitalized Return the data item Example: int getMonth() {return month;} ‘setters’ a setter for each data item Use ‘set’ and the data items name The data item name must be capitalized Change...
C++ write a class “Dog” with a private int field called months and two public member functions setAge and GetStage. setAge takes as argument monthsToSet and sets the member field months. setAge returns void. getStage is a const member function that takes no argument and returns a string “Puppy” if the dog is less than 9 months old, “Adolescence” if more than 9 and less than 13 months, “Adulthood” if more than 13 and less than 60 months and “Senior”...
C++ program Create a Student class that contains three private data members of stududentID (int), lastName (string), firstName(string) and a static data member studentCount(int). Create a constructor that will take three parameters of studentID, lastName and firstName, and assign them to the private data member. Then, increase the studentCount in the constructor. Create a static function getStudentCount() that returns the value of studentCount. studentCount is used to track the number of student object has been instantiated. Initialize it to 0...
a) Create saving account Class. Use a static data member annualBonusRate to store the annual bonus rate for each of the savers (objects) b) The class contains a private data member savingBalance indicating the amount the saver currently has on deposit. c) Provide member function calculate MonthlyBonus that calculates the monthly bonus by multiplying the savingBalance by annualBonusRate divided by 12; this bonus should be addad to savingBalance. d) Provide a static member function modifyBunusRate that has a parameter and...
Write a c# console program called “ArrayOfThings” where you create a class called Staff with private fields for StaffID and StaffName. Create Properties that can write data and retrieve data from these private fields. Create a Staff array that can hold up to ten Staff objects. Create ten objects using a for loop that automatically creates a new (empty) Staff object at each iteration of the loop and adds that object into the Staff array. Write data into the first...