Show person Information using Structure and Function in C++


Example Program:

Here is the simple program for printing the person Information using Structure and Functions in C++.

Source Code Example : 1

#include<iostream>
using namespace std;
struct Person
{
  char name[50];
  int age;
  float salary;
};
void displayData(Person);
int main()
{
  Person p;
  cout<<"Enter Full name: ";
  cin.get(p.name, 50);
  cout<<"Enter age: ";
  cin>>p.age;
  cout<<"Enter salary: ";
  cin>>p.salary;
  return 0;
}
void displayData(Person p)
{
  // cout<<"\nDisplaying Information."<<endl;
  // cout<<"Name: "<<p.name<<endl;
  // cout<<"Age: "<<p.age<<endl;
  // cout<<"Salary: "<<p.salary;
}
To download raw file Click Here

Output

Enter Full name: Ram
Enter age: 23
Enter salary: 20000


Source Code Example : 2

#include<iostream>
using namespace std;
struct Person
{
  char name[50];
  int age;
  float salary;
};
Person getData(Person);
void displayData(Person);
int main()
{
  Person p;
  p = getData(p);
  displayData(p);
  return 0;
}
Person getData(Person p)
{

  cout<<"Enter Full name: ";
  cin.get(p.name, 50);
  cout<<"Enter age: ";
  cin>>p.age;
  cout<<"Enter salary: ";
  cin>>p.salary;
  return p;
}
void displayData(Person p)
{
  cout<<"\nDisplaying Information."<<endl;
  cout<<"Name: "<<p.name<<endl;
  cout<<"Age: "<<p.age<<endl;
  cout<<"Salary: "<<p.salary;
}
To download raw file Click Here

Output

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


Basic Programs


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



Learn All in Tamil © Designed & Developed By Tutor Joes