Write a program that create Employee class with fields id,name and sal and create Employee object and store data and display that data.

Answers

Answer 1

Answer:

Here is the C++ program for Employee class with fields id,name and sal.

#include <iostream>  // to use input output functions

#include <string>  //to manipulate and use strings

using namespace std;   // to access objects like cin cout

class Employee {  //class Employee

private:  

/* the following data members are declared as private which means they can only be accessed by the functions within Employee class */

  string name;  //name field

  int id; //id field

  double sal;   //salary field

public:    

  Employee();  // constructor that initializes an object when it is created

/* setName, setID and setSalary are the mutators which are the methods used to change data members. This means they set the values of a private fields i.e. name, id and sal */

  void setName(string n)  //mutator for name field

     { name = n; }        

  void setId(int i)  //mutator for id field

     { id = i; }        

  void setSalary(double d)  //mutator for sal field

     { sal = d; }  

/* getName, getID and getSalary are the accessors which are the methods used to read data members. This means they get or access the values of a private fields i.e. name, id and sal */

  string getName()  //accessor for name field

     { return name; }        

  int getId()  //accessor for id field

     { return id; }        

  double getSalary()  //accessor for sal field

     { return sal; }  };  

Employee::Employee() {  //default constructor where the fields are initialized

  name = "";  // name field initialized

  id = 0;  // id field initialized to 0

  sal = 0;   }   // sal field initialized to 0

void display(Employee);  

// prototype of the method display() to display the data of Employee

int main() {  //start of the main() function body

  Employee emp;  //creates an object emp of Employee class

/*set the name field to Abc Xyz which means set the value of Employee class name field to Abc Xyz  through setName() method and object emp */

  emp.setName("Abc Xyz");  

/*set the id field to 1234 which means set the value of Employee class id field to 1234  through setId() method and object emp */

  emp.setId(1234);

/*set the sal field to 1000 which means set the value of Employee class sal field to 1000  through setSalary() method and object emp */

  emp.setSalary(1000);    

  display(emp);  }   //calls display() method to display the Employee data

void display(Employee e) {  // this method displays the data in the Employee //class object passed as a parameter.

/*displays the name of the Employee . This name is read or accessed through accessor method getName() and object e of Employee class */

  cout << "Name: " << e.getName() << endl;  

/*displays the id of the Employee . This id is read or accessed by accessor method getId() and object e */

  cout << "ID: " << e.getId() << endl;

/*displays the salary of the Employee . This sal field is read or accessed by accessor method getSalary() and object e */

  cout << "Salary: " << e.getSalary() << endl;  }

Explanation:

The program is well explained in the comments mentioned with each statement of the program.

The program has a class Employee which has private data members id, name and sal, a simple default constructor Employee(), mutatator methods setName, setId and setSalary to set the fields, acccessor method getName, getId and getSalary to get the fields values.

A function display( ) is used to display the Employee data i.e. name id and salary of Employee.

main() has an object emp of Employee class in order to use data fields and access functions defined in Employee class.

The output of the program is:

Name: Abc Xyz                                                                                                      

ID: 1234                                                                                                                  

Salary: 1000

The program and its output are attached.

Write A Program That Create Employee Class With Fields Id,name And Sal And Create Employee Object And
Write A Program That Create Employee Class With Fields Id,name And Sal And Create Employee Object And

Related Questions

Other Questions
Cass is walking her dog (Oreo) around the neighborhood. Upon arriving at Calina's house (a friend of Oreo's), Oreo turns part mule and refuses to continue on the walk. Cass yanks on the chain with a 67 N force at an angle of 30 above the horizontal. Determine the horizontal and vertical components of the tension force. True/False Indicate whether the statement is true or false. ____ 1. Hydrogen is an example of an atom. ____ 2. Medical imaging refers to invasive techniques and processes. ____ 3. Electrolytes are responsible for the acidity or alkalinity of solutions and can conduct an electrical charge. ____ 4. Fructose found in fruit and honey is an example of a disaccharide. ____ 5. Phospholipids are lipids that contain cholesterol. ____ 6. Enzymes are specialized protein molecules found in all living cells. ____ 7. RNA structures are unique for each person and so are usable as a means of identification. ____ 8. Another name for a base is alkali. ____ 9. Buffers help a living organism to maintain a constant pH value. ____ 10. Nuclear medicine is a branch of medicine that uses radioactive isotopes to prevent, diagnose, and treat disease. In intramembranous ossification, the model or template on which the bone forms is Group of answer choices mesenchyme tissue elastic cartilage hyaline cartilage fibrocartilage Based on the excerpt, readers can conclude that Odysseuss men enjoy their leisure time. appreciate their jobs. respect their leader. forge close friendships A copy machine makes 104 copies in 3 minutes and 15 seconds. how many copies does it make per minute define the term network topology? Given the information about each pair of acids fill in the correct answer. a. Acid A has a lower % ionization than B:_______ is a stronger acid. b. Acid B has a larger K_a than acid A._______ will have a larger percent ionization. c. A is a stronger acid than B. Acid B will have________ percent ionization than A. The equal total payments pattern for installment notes consists of changing amounts of interest but constant amounts of principal over the life of the note.A. TrueB. False a+2=6 explain pkleaseeeeeeeeeeeeeeee A simple random sample is a sample drawn in such a way that each member of the population has some chance for being included in the sample every tenth element of an arranged population is included each member of the population has equal chance for being included in the sample each member of the population has 0.10 chance for being included in the sample:__________. If s=1/2 unit and A=12s^2, what is the value of A, in square unit? what is the relationship between variable x and variable y Which of the following is an incorrect statement? a If individual audit risk remains the same, detection risk bears an inverse relationship to inherent and control risk. b The greater the inherent and control risk the auditor believes exist the less detection risk that can be accepted. c The auditor might make separate or combined assessments of inherent risk and control risk. d Detection risk cannot be changed at the auditors discretion. add the following - 4/9,7/12and - 3/8 Determine the following quantities for the circuits shown below:(a) the equivalent resistance(b) the total current from the power supply(c) the current through each resistor(d) the voltage drop across each resistor and(e) the power dissipated in each resistor.WILL MARK AS BRAINLIEST! What's the difference? A system of rewarding managers by linking bonuses to income computed under absorption costing may result in: i need help asap!! Describe the structure of DNA. Be sure to include information about the directionality of the strands and how the molecules are bonded together. someone tell me which ones to check A straight wire carrying a current of 7.2 A has a field of 8.9 103 T at right angles to it. What length of wire in the field will experience a force of 2.1 N? 2.6 103 m 3.1 101 m 1.3 101 m 3.3 101 m