C++ program to read and print Employee information

 

C++ program to define an Employee class to read and print Employee information using an array within the class

Problem Definition:

Write a C++ program to define a Employee class with the following Members:

Data  Members: empid, emp salary

Member Functions: to read a data and to print the data.

Program should use array within class to read 3 employee information and print the 3 employee information.

Video Tutorial:

Source Code for C++ program to read and print Employee information

 #include<iostream>
 using namespace std;
 class Employee
 {
     private:
     int empid[3];
     int empsal[3];
     public:
     void read_data();
     void print_data();  
 };
 void Employee::read_data()
 {
     for (int i=0; i<3;i++)     
    {         
         cout<<"Enter the Employee ID. ";         
         cin>>empid[i];
         cout<<"Enter the Employee salary. ";         
         cin>>empsal[i];
     }
 }
 void Employee::print_data()
 {
     for (int i=0; i<3;i++)
     {
         cout<<empid[i]<<"\t"<<empsal[i]<<endl;
     }
 }
 int main()
 {
     Employee emp;
     emp.read_data();
     cout<<endl<<"Employee Information is: "<<endl;
     cout<<"EmpID\tEMP Salary"<<endl;
     emp.print_data();
 }

Output:

Enter the Employee ID. 123

Enter the Employee salary. 10000

Enter the Employee ID. 234

Enter the Employee salary. 20000

Enter the Employee ID. 345

Enter the Employee salary. 30000

Employee Information is:

EmpID EMP Salary

123 10000

234 20000

345 30000

In this tutorial, we understand how to C++ program to define an Employee class to read and display Employee information using an array within the class.

If you like the tutorial share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.

Leave a Comment

Your email address will not be published. Required fields are marked *

Welcome to VTUPulse.com


Computer Graphics and Image Processing Mini Projects -> Click Here

Download Final Year Project -> Click Here

This will close in 12 seconds