Answers for "structure in c++ all in one"

C++
0

structure in c++ all in one

#include <iostream>
using namespace std;

struct Person {
    char name[50];
    int age;
    float salary;
};

struct Person p;

Person getData();
void displayData();

int main()
{
    struct Person p;
  
    p = getData();
    displayData();
  
    return 0;
}

Person getData() {

    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()
{
    cout << "\nDisplaying Information." << endl;
    cout << "Name: " << p.name << endl;
    cout << "Age: " << p.age << endl;
    cout << "Salary: " << p.salary;
}
Posted by: Guest on November-30-2020

Browse Popular Code Answers by Language