Question

solve it in c++10 Create a composition between the classes Job and Salary. Class Salary a....

solve it in c++10

Create a composition between the classes Job and Salary.

Class Salary

a. data member:
   1. money
b. constructors:
   1. default constructor
   2. user defined constructor with a parameter to set money
c. standard accessor and mutator functions

Class Job

a. data members:
   title (name of the job)
   salary (object of type Salary)

b. constructors:
   1. default constructor
   2. user defined constructor to set title and salary
   3. implement constructor delegation

c. standard accessor and mutator function for title
d. accessor function to read the money value of the internal Salary object
e. mutator function to update the money value of the internal Salary object
f. accessor function to return a copy of the internal Salary object
g. mutator function to replace the internal Salary object

Main

** question 1

. Instantiate a Job object and print it to screen (match output below)

Example Output

Programmer 100000

****question 2

Overload the << operator for the Job class:
Assume that this operator is not overloaded for the Salary class.

a) Write how the function will be declared in your code.
b) Write an external function definition (not inside the class).

****question 3

Overload the >> operator for the Salary class:

a) Write how the function will be declared in your code.
b) Write an external function definition (not inside the class).

**** question 4

Overload a relational operator for the Job class:
Assume that this operator is not overloaded for the Salary class.

a) Write how the function will be declared in your code.
b) Write an external function definition (not inside the class).

quesion 5

Overload an arithmetic operator for the Salary class which supports automatic type conversion:

a) Write how the function will be declared in your code.
b) Write an external function definition (not inside the class).

**** question 6

Overload a relational operator for Job to determine which job is better (makes more money):

a) Write how the function will be declared in your code.
b) Write an external function definition (not inside the class).

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

Program:

#include<iostream>

using namespace std;

//Salary class
class Salary
{
private:
//private member
double money;
public:
//default constructor
Salary(){money = 0;}
//parameterized constructor
Salary(double money){this->money = money;}
//accessor function
double getMoney(){ return money;}
//mutator function
void setMoney(double money){this->money = money;}
//declaration of >> operator overloading
friend istream& operator>>(istream &is, Salary &salary);
//arithmetic operator overloading for type conversion:
operator double();
};

//definition of >> operator overloading
istream& operator>>(istream &is, Salary &salary)
{
is>>salary.money;
return is;
}

//arithmetic operator overloading for type conversion:
Salary::operator double()
{
return this->money;
}

//Job class
class Job
{
private:
//private members
string title;
Salary salary;
public:
//default constructor
Job()
{
title = "";
salary = 0;
}
//parameterized constructor
Job(string jobname)
{
title = jobname;
}
//parameterized constructor
Job(string jobname, Salary sal): Job(jobname)
{
salary = sal;
}
//accessor function for title
string getTitle(){ return title;}
//mutator function for title
void setTitle(string jobname){title = jobname;}
//accessor function for the internal Salary object
Salary getSalary() {return salary;}
//mutator function for the internal Salary object
void setSalary(Salary sal){salary = sal;}
//accessor function for the money value
double getMoneyValue() {return salary.getMoney();}
//mutator function for the the money value
void setMoneyValue(double money){salary = Salary(money);}
//declaration of << operator overloading
friend ostream& operator<<(ostream &os, Job &job);
//declaration of relational operator == overloading
bool operator==(Job &job);
//declaration of relational operator > overloading
bool operator>(Job &job);

};

//definition of << operator overloading
ostream& operator<<(ostream &os, Job &job)
{
os<<job.title<<" ";
os<<job.getMoneyValue();
return os;
}

//definition of relational operator overloading
bool Job::operator==(Job &job)
{
return this->getMoneyValue()==job.getMoneyValue();
}

//definition of relational operator > overloading
bool Job::operator>(Job &job)
{
return this->getMoneyValue() > job.getMoneyValue();
}

//main function
int main()
{
//Instantiate a Job object
Job job("Programmer", 100000);

//print it to screen
cout<<job;

return 0;
}

Output:

Programmer 100000

Add a comment
Know the answer?
Add Answer to:
solve it in c++10 Create a composition between the classes Job and Salary. Class Salary a....
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
  • Overload a relational operator for the Job class: Assume that this operator is not overloaded for...

    Overload a relational operator for the Job class: Assume that this operator is not overloaded for the Salary class. a) Write how the function will be declared in your code. b) Write an external function definition (not inside the class). solve it in C++10 to solve this you nedd question number 1. Create a composition between the classes Job and Salary. Class Salary a. data member:    1. money b. constructors:    1. default constructor    2. user defined constructor with a parameter...

  • Student.h Student.cpp Person.h Person.cpp In this assignment, you need to create a class to keep track...

    Student.h Student.cpp Person.h Person.cpp In this assignment, you need to create a class to keep track of books borrowed bya student. Each book has a name, Student (who borrowed it), and the date that was borrowed (see the .h file below). Use also need to use the Person class and the Student class included in the folder. Student class inherits from the Person class as was shown in the classroom Create a Date class (in the same project of the...

  • Question 3: Q3 (Polymorphism & virtual function) a) Consider the class, derived class, and the virtual functions as shown in Display for Q3. Create a derived class (of Sale) called 'Mailorder...

    Question 3: Q3 (Polymorphism & virtual function) a) Consider the class, derived class, and the virtual functions as shown in Display for Q3. Create a derived class (of Sale) called 'MailorderSale' having one private member variable called 'shipping charge'. It should have constructor function and virtual function 'bill' (this function adds shipping charge to the price). Define all these functions (no need of default constructors). b) In the main function, define one object of DiscountSale with (11,10) initial values and...

  • 1. Create an “include guard” (all lines of code required) for a file “plane.h” 2. When...

    1. Create an “include guard” (all lines of code required) for a file “plane.h” 2. When you look at a constructor, how can you determine if it is THE default constructor? 3. What can a “friend” function do that other non-member functions can not do? 4. class plane { int x;} ---------------- is x public or private? 5. What kind of a search first sorts the data into ascending or descending order, then splits the data in half, searches, splits,...

  • C++ code For each of the following classes create default constructor and parameterized constructors(calling parent(s) parameterized...

    C++ code For each of the following classes create default constructor and parameterized constructors(calling parent(s) parameterized constructors where it applies Add accessor and mutator function for the attribute inherent to the class Create a Base class called Shape2d with the protected floating point attribute area operator overload the + & - and operations to return the float respective to the area Derive from the Base class from called Shape2d called Rectangle with the additional floating-point attributes length & width Derive...

  • C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember...

    C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name. Define a class called Athlete which is derived from FitnessMember. An Athlete record has the Athlete's name (defined in the FitnessMember class), ID number of type String and integer number of training days. Define a class...

  • Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a...

    Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a class Employee (with member variables: char * name, int id, and double age). 2. Create a constructor that should be able to take arguments and initialize the member variables. 3. Create a copy constructor for employee class to ensure deep copy. 4. Create a destructor and de allocate the dynamic memory. 5. Overload the assignment operator to prevent shallow copy and ensure deep copy....

  • This in in C# There are two classes, class Fraction and class FractionDemo The user needs...

    This in in C# There are two classes, class Fraction and class FractionDemo The user needs to be able to input a value for the numerator and the denominator Create a Fraction class with private fields that hold a positive int numerator and a positive int denominator. In addition, create Properties for each field with the set mutator such that the numerator is greater than or equal to 0 and the denominator is greater than 0 (illegal values should be...

  • C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to...

    C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to the project. Copy and paste the code is listed below: Design a class named Employee. The class should keep the following information in member variables: Employee name Employee number Hire date // Specification file for the Employee class #ifndef EMPLOYEE_H #define EMPLOYEE_H #include <string> using namespace std; class Employee { private:        // Declare the Employee name string variable here. // Declare the Employee...

  • Create a base class called WaterVehicle that has: -length of ship (in number of grid spaces)...

    Create a base class called WaterVehicle that has: -length of ship (in number of grid spaces) starting grid location -horizontal or vertical orientation on grid -sunk (boolean) Then create a class called Submarine that is derived from WaterVehicle and has the following additional properties: -dive depth -surfaced (Boolean) Be sure your classes have a reasonable complement of constructors, accessor, and mutator methods including a public function to determine if the Submarine was hit by a torpedo and whether a hit...

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