67 007
Assignments Done
99,2%
Successfully Done
In November 2018

Answer to Question #31956 in C++ for Jay

Question #31956
Derive a class Programmer from Employee. Supply a constructor Programmer(string name, double salary) that calls the base-class constructor. Supply a function get_name that returns the name in the format “Hacker, Harry (Programmer)”.
Expert's answer
#ifndef CLASSES_H
#define CLASSES_H

#include <iostream>
#include <string>

using namespace std;

class Employee
{
protected:
string name;
double salary;

public:
Employee(const string& name, double salary)
{
this->name = name;
this->salary = salary;
}
};

class Programmer : Employee
{
public:
Programmer(string name, double salary) : Employee(name, salary) {}
string get_name()
{
return name + string(" (Programmer)");
}
};

#endif

int main()
{
Programmer p("Hacker, Harry", 9400);
cout << p.get_name();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions