Question

In: Computer Science

Previous Lab Code files: PersonType.h: #include <string> using namespace std; class personType { public: void print()...

Previous Lab Code files:

PersonType.h:

#include <string>
using namespace std;

class personType
{
public:
void print() const;
void setName(string first, string middle, string last);
   void setLastName(string last);
   void setFirstName(string first);
   void setMiddleName(string middle);

   bool isLastName(string last) const;
   bool isFirstName(string first) const;

string getFirstName() const;
   string getMiddleName() const;
   string getLastName() const;

personType(string first = "", string middle = "", string last = "");

private:
string firstName;
string middleName;
string lastName;
};

PersonTypeImp:

#include <iostream>
#include <string>
#include "personType.h"

using namespace std;

void personType::print() const
{
cout << firstName << " " << middleName << " " << lastName;
}

void personType::setName(string first, string middle, string last)
{
firstName = first;
middleName = middle;
lastName = last;
}

void personType::setLastName(string last)
{
lastName = last;
}

void personType::setFirstName(string first)
{
firstName = first;
}

void personType::setMiddleName(string middle)
{
middleName = middle;
}

bool personType::isLastName(string last) const
{
return (lastName == last);
}

bool personType::isFirstName(string first) const
{
return (firstName == first);
}

string personType::getFirstName() const
{
return firstName;
}

string personType::getMiddleName() const
{
return middleName;
}

string personType::getLastName() const
{
return lastName;
}


//constructor
personType::personType(string first, string middle, string last)

{
firstName = first;
middleName = middle;
lastName = last;
}

Main:

#include <iostream>
#include "personType.h"
using namespace std;

int main()
{
personType student("Mary", "Beth", "Regan");

student.print();
cout<<endl;

if (student.isLastName("Regan"))
cout<<"Student\'s last name is Regan"<<endl;
else
cout<<"Student\'s last name is not Regan"<<endl;
  
if (student.isFirstName("Mary"))
cout<<"Student\'s first name is Mary"<<endl;
else
cout<<"Student\'s first name is not Mary"<<endl;

return 0;
}

Question:

Suppose that a class employeeType is derived from the class personType (see the previous lab code). Create employeeType class with following members

public members

void setData(string n = "", string d = "", int a = 0, double p = 0);

void setName(string n);

string getName() const;

void setDepartment(string dept);

string getDepartment() const;

void setAge(int a);

int getAge() const;

void setPay(double p);

double getPay() const;

employee(string n = "", string d = "", int a = 0, double p = 0);

Private members

string name;

string department;

int age;

double pay;

Write a program to test employeeType.

Language is C++

Solutions

Expert Solution

#include <iostream>
#include <string>
#include "personType.h"

using namespace std;

class employeeType : personType
{
private:

string name;

string department;

int age;

double pay;
public:

void setData(string n = "", string d = "", int a = 0, double p = 0)
{
    name=n;
    department=d;
    age=a;
    pay=pay;
}

void setName(string n)
{
    name=n;
}

string getName() const
{
    return name;
}

void setDepartment(string dept)
{
    department=dept;
}

string getDepartment() const
{
    return department;
}

void setAge(int a)
{
    age=a;
}

int getAge() const
{
    return age;
}

void setPay(double p)
{
    pay=p;
}

double getPay() const
{
    return pay;
}

employeeType(string n = "", string d = "", int a = 0, double p = 0)
{
    name=n;
    department=d;
    age=a;
    pay=p;
}
void print()//print overload
{
    cout<<"Name: "<<name<<" department: "<<department<<" age: "<<age<<" pay: "<<pay;
}
};


int main()
{
employeeType employee("John","Business",25,250000);

employee.print();
cout<<endl;


return 0;
}

I hope it helps.


Related Solutions

#include<iostream> using namespace std; class point{ private: int x; int y; public: void print()const; void setf(int,...
#include<iostream> using namespace std; class point{ private: int x; int y; public: void print()const; void setf(int, int); }; class line{ private: point ps; point pe; public: void print()const; void setf(int, int, int, int); }; class rectangle{ private: line length[2]; line breadth[2]; public: void print()const; void setf(int, int, int, int, int, int, int, int); }; int main(){ rectangle r1; r1.setf(3,4,5,6, 7, 8, 9, 10); r1.print(); system("pause"); return 0; } a. Write function implementation of rectangle, line and point. b. What is...
--- TURN this Code into Java Language --- #include <iostream> #include <string> using namespace std; //...
--- TURN this Code into Java Language --- #include <iostream> #include <string> using namespace std; // constants const int FINAL_POSITION = 43; const int INITIAL_POSITION = -1; const int NUM_PLAYERS = 2; const string BLUE = "BLUE"; const string GREEN = "GREEN"; const string ORANGE = "ORANGE"; const string PURPLE = "PURPLE"; const string RED = "RED"; const string YELLOW = "YELLOW"; const string COLORS [] = {BLUE, GREEN, ORANGE, PURPLE, RED, YELLOW}; const int NUM_COLORS = 6; // names...
c++ #include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start,...
c++ #include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p =...
What is the flowchart for this code. Thank You! #include<iostream> #include<iomanip> #include<string> #include<cmath> using namespace std;...
What is the flowchart for this code. Thank You! #include<iostream> #include<iomanip> #include<string> #include<cmath> using namespace std; float series(float r[], int n) {    float sum = 0;    int i;    for (i = 0; i < n; i++)        sum += r[i];    return sum; } float parallel(float r[], int n) {    float sum = 0;    int i;    for (i = 0; i < n; i++)        sum = sum + (1 / r[i]);...
Debug please. It's in C++ #include<iostream> #include<string> using namespace std; class Prescription {    friend ostream&...
Debug please. It's in C++ #include<iostream> #include<string> using namespace std; class Prescription {    friend ostream& operator<<(ostream&, const Prescription&);    friend istream& operator>>(istream&, Prescription&);    private: int idNum; int numPills; double price;    public: Prescription(const int = 0, const int = 0, const double = 0.0); }; Prescription::Prescription(const int id, const int pills, const double p) {    id = id;    numPills = pills;    price = p; } ostream& operator<<(ostream& out, const Prescription pre) {    out <<...
#include <iostream> #include <stack> #include <queue> using namespace std; void printFromStack(string expr){ stack<char> myStack; for(int i=0;...
#include <iostream> #include <stack> #include <queue> using namespace std; void printFromStack(string expr){ stack<char> myStack; for(int i=0; i<expr.length(); i++){ //Insert code here to push each character onto the stack } cout << "My stack is popped in this order" << endl; while(!myStack.empty()){ //Insert code here to cout the top of the stack one by one //Pop each one after it’s printed out } cout << endl; } void printFromQueue(string expr){ queue<char> myQueue; //Insert code here to push each character onto the...
what am I doing wrong here? thank you! #include <iostream> #include <string> using namespace std; class...
what am I doing wrong here? thank you! #include <iostream> #include <string> using namespace std; class DivSales { private:    int quarterSales[4];    static double totalSales; public:    void add(int, int, int, int);    int sales(int);    static double getValue()    {        return totalSales;    };    void DivSales::add(int s1, int s2, int s3, int s4)    {        quarterSales[0] = s1;        quarterSales[1] = s2;        quarterSales[2] = s3;        quarterSales[3] = s4;...
#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string userInput; getline(cin, userInput);...
#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string userInput; getline(cin, userInput); // Declaring base int N = 30; if (userInput.length() > 10) { cout << 0 << endl; } else { int finalTotal = 0; //Iterates through userInput for(int i = 0; i < 10; i++){ char convertedInput = userInput[i]; // ASCII decimal value of each character int asciiDec = int(convertedInput); //Casts char value from input to int value stringstream chr; chr << convertedInput; int...
*/ #include using namespace std; void start (int boxes [10]); void move (int squares [10], int...
*/ #include using namespace std; void start (int boxes [10]); void move (int squares [10], int x, int y, int z); void add (int arr [10], int first, int last); void print (int arr [10]); int main () {     int my_arr [10];         cout << "The original array is:\n";     print (my_arr);         start (my_arr);     cout << "\n\nThe array after start is:\n";     print (my_arr);         move (my_arr, 2, 4, 6);     cout << "\n\nThe...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT