Show person Information using Structure in C++


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.

Source Code

#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

Output

Enter Full name: Ram
Enter age: 20
Enter salary: 20000
Displaying Information.
Name: Ram
Age: 20
Salary: 20000

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples