Write a short program to implement a data structure to store the following information: last name first name age (int) salary (float) The program should then request input data from the console to be assigned to the members of the structure and then output the information stored in the structure members to the screen. C++
Expert Answer
here your below program:
#include <iostream>
using namespace std;
struct Persondetails
{
char firstname[50];
char lastname[50];
int age;
float salary;
};
int main()
{
Persondetails p1;
cout << “Enter first name: “;
cin>>p1.firstname;
cout << “Enter last name: “;
cin>>p1.lastname;
cout << “Enter age: “;
cin >> p1.age;
cout << “Enter salary: “;
cin >> p1.salary;
cout << “nDisplaying Information.” << endl;
cout << “Name: ” << p1.firstname << endl;
cout << “Name: ” << p1.lastname << endl;
cout <<“Age: ” << p1.age << endl;
cout << “Salary: ” << p1.salary;
return 0;
}
OUTPUT:
Enter first name: hemanth
Enter last name: kumar
Enter age: 90
Enter salary: 789
Displaying Information.
Name: hemanth
Name: kumar
Age: 90
Salary: 789