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)”.
1
Expert's answer
2013-06-14T09:10:51-0400
#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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS