Question

c++ please need help with this question Consider a class Employee with data members: age(an integer),...

c++ please need help with this question

Consider a class Employee with data members: age(an integer), id (an integer) and salary (a float), and their corresponding member functions as follows:

class Employee

{

       private:

            int age;

            int id;

            float salary;

       public:

            Employee( ); // default constructor: age=0, id=0, and salary=0

            Employee(Employee &x);   // copy constructor

          Employee& operator = (Employee &x); // equal sign operator

            void setAge(int x);    // let age = x

            void setId(int x);       // let id = x

            void setSalary(float x);   // salary = x

int getAge( );        // return age

            int getId( );            // return id

            float getSalary( ); // return salary

            void print( );   // print out the values of attributes on computer screen

};

You need to provide the definition of the default constructor and the first three member functions (setAge, setId and setSalary) inside the scope defined by the brackets of class Employee and other three member functions (getAge, getId, and getSalary) outside the scope defined by the brackets of class Employee, as shown in the following skeleton:

class Employee

{

Employee( )

{ ..... }

void setAge(int x)

{ ......... }

void setId(int x)

{ ......... }

void setSalary(float x)

{ ......... }

};

int Employee::getAge( )

{

.....

}

int Employee::getId( )

{

....

}

float Employee::getSalary( )

{

......

}

Write a main routine in which you create 5 Employee objects: a, b, c, d, and e. Set the values of a, b and c as follows:

Objects

Age

Id

Salary

a

40

111

30000

b

41

112

31000

c

42

113

32000

The skeleton of the main( ) is as follows:

void main( )

{

            // create 4 Employee objects: a, b, c, d

           …..

            // set the values of a, b and c according to the above table

           ……

            // Use copy constructor to assign the content of object a to the content of object e

           ……

            // print out the contents of a and e to show they are the same

           ……

          // Use “=” operator to assign the content of object b to the content of object d

           ……

          // print out the contents of b and d to show they are the same

           ……

          // create an output file name: “output.txt”

……

// output the contents of d and e to the file, “output.txt”

           

}

You should open “output.txt” with a text editor and create a screenshot to show its contents.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

#include<iostream>

#include<fstream>

using namespace std;

class Employee

{

private:

int age;

int id;

float salary;

public:

Employee() // default constructor: age=0, id=0, and salary=0

{

age = 0;

id = 0;

salary = 0;

}

Employee(Employee &x) // copy constructor

{

age = x.getAge();

id = x.getId();

salary = x.getSalary();

}

Employee& operator=(Employee &x) // equal sign operator

{

age = x.getAge();

id = x.getId();

salary = x.getSalary();

return *this;

}

void setAge(int x) // let age = x

{

age = x;

}

void setId(int x) // let id = x

{

id = x;

}

void setSalary(float x) // salary = x

{

salary = x;

}

int getAge( ); // return age

int getId( ); // return id

float getSalary( ); // return salary

void print(); // print out the values of attributes on computer screen

};

int Employee::getAge( )

{

return age;

}

int Employee::getId( )

{

return id;

}

float Employee::getSalary( )

{

return salary;

}

void Employee::print(){

cout<<"Age: "<<age<<endl;

cout<<"Id: "<<id<<endl;

cout<<"Salary: "<<salary<<endl;

}

int main()

{

// create 4 Employee objects: a, b, c, d

Employee a, b, c, d;

// set the values of a, b and c according to the above table

a.setAge(40);

a.setId(111);

a.setSalary(30000);

b.setAge(41);

b.setId(112);

b.setSalary(31000);

c.setAge(41);

c.setId(113);

c.setSalary(32000);

// Use copy constructor to assign the content of object a to the content of object e

Employee e(a);

// print out the contents of a and e to show they are the same

cout<<"object a: "<<endl;

a.print();

cout<<endl;

cout<<"object e: "<<endl;

e.print();

cout<<endl;

// Use “=” operator to assign the content of object b to the content of object d

d = b;

// print out the contents of b and d to show they are the same

cout<<"object b: "<<endl;

b.print();

cout<<endl;

cout<<"object d: "<<endl;

d.print();

// create an output file name: “output.txt”

ofstream outFile;

outFile.open("output.txt");

// output the contents of d and e to the file, “output.txt”

outFile<<"object d: "<<endl;

outFile<<"Age: "<<d.getAge()<<endl;

outFile<<"Id: "<<d.getId()<<endl;

outFile<<"Salary: "<<d.getSalary()<<endl;

outFile<<endl<<"object 'e': "<<endl;

outFile<<"Age: "<<e.getAge()<<endl;

outFile<<"Id: "<<e.getId()<<endl;

outFile<<"Salary: "<<e.getSalary()<<endl;

outFile.close();

return 0;

}

Add a comment
Know the answer?
Add Answer to:
c++ please need help with this question Consider a class Employee with data members: age(an integer),...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Program 2 Consider a class Employee with data members: age (an integer), id (an integer)...

    C++ Program 2 Consider a class Employee with data members: age (an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee { private: int age; int id; float salary: public: Employee; // default constructor: age=0, id=0, and salary=0 void setAge(int x); // let age = x void setId(int x); // let id = x void setSalary(float x); // salary = x int getAge(); // return age int getId; // return id float...

  • c++ only Design a class representing an Employee. The employee would have at least these private...

    c++ only Design a class representing an Employee. The employee would have at least these private fields (Variables): name: string (char array) ID: string (char array) salary: float Type: string (char array) All the variables except for the salary should have their respective setters and getters, and the class should have two constructors, one is the default constructor and the other constructor initializes the name,ID and type of employee with valid user input. The class should have the following additional...

  • Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and...

    Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and will add various functionality. We will store the following private variables specific to Warehouse: . a std::vector of float values which indicate the monetary values of each sale made by this salesman . a std::string which stores that salesman's position title . a float which stores their commission percentage, i.e., the percentage of sales they receive as a paycheck . a float which stores...

  • It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming...

    It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming Challenge 2 Employee Class.pdf Program Template: // Chapter 13, Programming Challenge 2: Employee Class #include <iostream> #include <string> using namespace std; // Employee Class Declaration class Employee { private: string name; // Employee's name int idNumber; // ID number string department; // Department name string position; // Employee's position public: // TODO: Constructors // TODO: Accessors // TODO: Mutators }; // Constructor #1 Employee::Employee(string...

  • I have most of the code for this assignment but need some help getting the rest....

    I have most of the code for this assignment but need some help getting the rest. Go to bottom to see what I have. Please help me figure out the foreach loops and the put() statement. In this assignment, you will be using a new data structure, HashMaps, to repeat Assignment 8.3. Main Method (5 points) Declare and initialize an HashMap with values of type of type Employee, and keys of type integer. In a while loop, keep initializing objects...

  • Language: C++ Create an abstract base class person. The person class must be an abstract base...

    Language: C++ Create an abstract base class person. The person class must be an abstract base class where the following functions are abstracted (to be implemented in Salesman and Warehouse): • set Position • get Position • get TotalSalary .printDetails The person class shall store the following data as either private or protected (i.e., not public; need to be accessible to the derived classes): . a person's name: std::string . a person's age: int . a person's height: float The...

  • Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a...

    Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a class Employee (with member variables: char * name, int id, and double age). 2. Create a constructor that should be able to take arguments and initialize the member variables. 3. Create a copy constructor for employee class to ensure deep copy. 4. Create a destructor and de allocate the dynamic memory. 5. Overload the assignment operator to prevent shallow copy and ensure deep copy....

  • In Java: Executable Class create an array of Employee objects. You can copy the array you...

    In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...

  • Following is the EmployeeTester class, which creates object of the class Employee and calls the methods...

    Following is the EmployeeTester class, which creates object of the class Employee and calls the methods of that object. The EmployeeTester class is written to test another class: Employee. You are required to implement the class Employee by: declaring its instance variables: name, age, salary. implementing its constructor. implementing its methods: getEmployeeName(), getEmployeeAge(), getEmployeeSalary(), setEmployeeAge(int empAge),      setEmployeeSalary(double empSalary) public class EmployeeTester { public static void main(String args[]) { // Construct an object Employee employeeOne = new Employee("Ahmad Abdullah"); //...

  • Java Do 68a, 68b, 68c, 68d. Show code & output. public class Employee { private int...

    Java Do 68a, 68b, 68c, 68d. Show code & output. public class Employee { private int id; private String name; private int sal; public Employee(int id, String name, int sal) { super(); this.id = id; this.name = name; this.sal = sal; } public int getid) { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; public void setName(String name) { this.name = name; } public int get Sall) { return sal;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT