Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLESE HELP This C++ Create the following classes: Person -first name(string) -la

ID: 3686160 • Letter: P

Question

PLESE HELP This C++
Create the following classes:

Person

-first name(string)

-last name(string)

-constructor of the form person(string,string)

Employee

-hiredhand(Person)

-salary(float)

-constructor of the form Employee(string,string,float)

use the class in main

-prompt the user for the first name,last name and salary

-instantiate an Employee object and initialize with the data provided

-use a constructor initialization list

-use a getter function to retrieve the value for each data member and write the information out to a file on 3 separate line

Explanation / Answer

#include<iostream>
#include<cstdlib>
#include<fstream>

using namespace std;

class Person{
  
   private:
       string firstName;
       string lastName;
   public:
       Person(string fname, string lname){
           firstName = fname;
           lastName = lname;
       }
      
       string getFirstName(){
           return firstName;
       }
       string getLastName(){
           return lastName;
       }
       void setFirstName(string fname){
           firstName = fname;
       }
       void setLastName(string lname){
           lastName = lname;
       }
};

class Employee{
  
   private:
       Person *hiredhand;
       float salary;
   public:
       Employee(string fname, string lname, float sal){
               hiredhand = new Person(fname, lname);
               salary = sal;
       }
      
       void setSalary(float sal){
           salary = sal;
       }
      
       float getSalary(){
           return salary;
       }
      
       Person *getHiredHand(){
           return hiredhand;
       }
};


int main(){
  
   string fname, lname;
   float sal;
  
   cout<<"Enter first name: ";
   cin>>fname;
   cout<<"Enter lastname: ";
   cin>>lname;
   cout<<"Enter salary: ";
   cin>>sal;
  
   //creating Employee object
  
   Employee emp(fname, lname, sal);
  
   //writing to file
   char fileName[20];
   cout<<"Enter file name to write: ";
   cin>>fileName;
  
   ofstream output(fileName);
  
   // getting Person
   Person *p = emp.getHiredHand();
   output<<"First Name: "<<p->getFirstName()<<endl;
   output<<"Last Name: "<<p->getLastName()<<endl;
   output<<"Salary: "<<emp.getSalary()<<endl;
  
   output.close();
  
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote