Using the structure below, write the C++ codes to enter data into each field and display the output: struct Person {     char name[15];     int age;     float salary; };

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Using the structure below, write the C++ codes to enter data into each field and display the output:

struct Person

{

    char name[15];

    int age;

    float salary;

};

Expert Solution
Step 1

The below given C++ program will obey the following rubrics:

  • Importing essential header files.
  • Declaring structure name person with attributes name, age and salary.
  • In the main method, displaying message to user to enter the name.
  • Reading input of name from user.
  • Displaying message to user to enter age.
  • Reading input of age from user.
  • Displaying message to user to enter salary.
  • Reading input of salary from user.
  • After taking all the inputs from user displaying all the entered data to the user.

 

Step 2

Program code:

 

    //importing neccessary header files

    #include <iostream>

    //using namespace standard

    using namespace std;

    //defining structure name person

    struct Person

    {

        //declaring name with char data type 

        char name[15];

        //declaring age with integer data type

        int age;

        //declaring salary with float data type

        float salary;

    };

    //main method

    int main()

    {

        //creating object of person p1

        Person p1;

        //displaying message to user to enter name

        cout << "Enter Full name: ";

        // reading input of name from user

        cin.get(p1.name, 15);

        //displaying message to user to enter age

        cout << "Enter age: ";

        //reading input of age from user

        cin >> p1.age;

        //displaying message to user to enter salary

        cout << "Enter salary: ";

        //reading input of salary

        cin >> p1.salary;

        //displaying message to user

        cout << " Displaying Information." << endl;

        //displaying name to user

        cout << "Name: " << p1.name << endl;

        //displaying age to user

        cout <<"Age: " << p1.age << endl;

        //displaying salary to user

        cout << "Salary: " << p1.salary;

        return 0;

    }//end of main method

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY