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...
#include <iostream> #include <string> #include <vector> using namespace std; class Song{ public: Song(); //default constructor Song(string...
#include <iostream> #include <string> #include <vector> using namespace std; class Song{ public: Song(); //default constructor Song(string t, string a, double d); //parametrized constructor string getTitle()const; // return title string getAuthor()const; // return author double getDurationMin() const; // return duration in minutes double getDurationSec() const; // return song's duration in seconds void setTitle(string t); //set title to t void setAuthor(string a); //set author to a void setDurationMin(double d); //set durationMin to d private: string title; //title of the song string author;...
--- 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 =...
#include <iostream> #include <string> #include <iomanip> #include <cstdlib> #include "Contact.h" using namespace std; class Contact {...
#include <iostream> #include <string> #include <iomanip> #include <cstdlib> #include "Contact.h" using namespace std; class Contact { public: Contact(string init_name = "", string init_phone = "000-000-0000"); void setName(string name); void setPhone(string phone); string getName()const; string getPhone()const; friend ostream& operator << (ostream& os, const Contact& c); friend bool operator == (const Contact& c1, const Contact& c2); friend bool operator != (const Contact& c1, const Contact& c2); private: string name, phone; }; Contact::Contact(string init_name, string init_phone) { name = init_name; phone = init_phone;...
C++ Given Code: #include <iostream> #include <string> using namespace std; int main() { //declare variables to...
C++ Given Code: #include <iostream> #include <string> using namespace std; int main() { //declare variables to store user input bool cont = true; //implement a loop so that it will continue asking until the user provides a positive integer // the following provides ONLY part of the loop body, which you should complete { cout <<"How many words are in your message? \n"; cout <<"Enter value: "; // get user input integer here    cout <<"\nInvalid value. Please Re-enter a...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT