Answer to Question #268153 in C++ for Agola Shem

Question #268153

Write a C++ program segment to assign data to members of a STRUCTURE called EMPLOYEE having name, age and salary then display it.


1
Expert's answer
2021-11-18T15:20:53-0500


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






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS