Write a C++ program segment to assign data to members of a STRUCTURE called EMPLOYEE having name, age and salary then display it.
SOLUTION CODE TO THE ABOVE QUESTION
SOLUTION CODE
// C++ program to store data of an EMPLOYEE in a structure variable
#include <iostream>
using namespace std;
struct EMPLOYEE{
char employee_name[50];
int employee_age;
int employee_salary;
};
int main() {
//declare a variable of type Employee as
EMPLOYEE emp;
//propmt the user to enter the employee details
//i.e name, age, salary and store them in corresponding
// fields of structure variable
cout << "Enter name of employee : ";
cin.getline(emp.employee_name, 50);
cout << "Enter employee age : ";
cin >> emp.employee_age;
cout << "Enter salary of employee : ";
cin >> emp.employee_salary;
// Printing employee details
cout << "\n*** Employee Details ***" << endl;
cout << "Employee Name : " << emp.employee_name << endl;
cout << "Employee age : " << emp.employee_age<<endl;
cout<< "Employee Salary : " << emp.employee_salary << endl;
return 0;
}
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment