This program defines a Person struct that has three members: name, age, and salary. It then creates an instance of this struct: p1. The program prompts the user to enter values for name, age, and salary using cout statements and cin input. The cin.get() function is used to read in the name member as a string with a maximum length of 50 characters.
The program then prints the values of each member of p1 using cout statements. Overall, this program is an example of how to define and use a struct in C++ to store information about a person. It creates an instance of the Person struct, prompts the user to enter values for its members, and then prints out the values of each member.
#include<iostream> using namespace std; struct Person { char name[50]; int age; float salary; }; int main() { Person p1; cout<<"Enter Full name: "; cin.get(p1.name,50); cout<<"Enter age: "; cin>>p1.age; cout<<"Enter salary: "; cin>>p1.salary; cout<<"\nDisplaying Information."<<endl; cout<<"Name: "<<p1.name<<endl; cout<<"Age: "<<p1.age<<endl; cout<<"Salary: "<<p1.salary; return 0; }To download raw file Click Here
Enter Full name: Ram Enter age: 20 Enter salary: 20000 Displaying Information. Name: Ram Age: 20 Salary: 20000
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions