structure in c 2b 2b all in one

Solutions on MaxInterview for structure in c 2b 2b all in one by the best coders in the world

showing results for - "structure in c 2b 2b all in one"
Lucas
13 Jun 2018
1#include <iostream>
2using namespace std;
3
4struct Person {
5    char name[50];
6    int age;
7    float salary;
8};
9
10struct Person p;
11
12Person getData();
13void displayData();
14
15int main()
16{
17    struct Person p;
18  
19    p = getData();
20    displayData();
21  
22    return 0;
23}
24
25Person getData() {
26
27    cout << "Enter Full name: ";
28    cin.get(p.name, 50);
29
30    cout << "Enter age: ";
31    cin >> p.age;
32
33    cout << "Enter salary: ";
34    cin >> p.salary;
35
36    return p;
37}
38
39void displayData()
40{
41    cout << "\nDisplaying Information." << endl;
42    cout << "Name: " << p.name << endl;
43    cout << "Age: " << p.age << endl;
44    cout << "Salary: " << p.salary;
45}