Input and Display Data in Structure using functions
#include <iostream>
using namespace std;
struct Person
{
char name[50];
int age;
float salary;
};
Person getData(Person);
void displayData(Person);
int main()
{
Person p, x;
getData(p);
p = x;
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;
}
Comments
Post a Comment