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...
Array based application #include <iostream> #include <string> #include <fstream> using namespace std; // Function prototypes void...
Array based application #include <iostream> #include <string> #include <fstream> using namespace std; // Function prototypes void selectionSort(string [], int); void displayArray(string [], int); void readNames(string[], int); int main() {    const int NUM_NAMES = 20;    string names[NUM_NAMES];    // Read the names from the file.    readNames(names, NUM_NAMES);    // Display the unsorted array.    cout << "Here are the unsorted names:\n";    cout << "--------------------------\n";    displayArray(names, NUM_NAMES);    // Sort the array.    selectionSort(names, NUM_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 <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;...
#include <iostream> #include <string> #include <array> #include <vector> using namespace std; void f(int x, int &y);...
#include <iostream> #include <string> #include <array> #include <vector> using namespace std; void f(int x, int &y); int main(){ char s1[] = "zoey"; char s2[] = "zoey"; string s3 = s1; string s4 = s2; cout << "1. sizeof(s1) = " << sizeof(s1) << endl; if(s1 == s2) cout << "2. s1 == s2 is true" << endl; else cout << "2. s1 == s2 is false" << endl; if(s3 == s4) cout << "3. s3 == s4 is true" <<...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT