Accept & Display student details - C++ Program

Q. Write a C++ program to accept and display the name, roll number and fees of a student using structure.

Answer:

Following program is accepting and displaying the student details using structure.

#include<iostream>
#include<stdio.h>
using namespace std;
struct student    //Defining structure
{
        char sname[20];
        int rollno;
        float fee;
};
int main()
{
        struct student st;  //Declare st of type student
        cout<<"\n Enter Student Details "<<" ";
        cout<<"\n ---------------------------------\n";
        cout<<" Student Name : ";
        gets(st.sname);   
        //Accessing member of structure using member access operator (.)
        cout<<" Roll Number : ";
        cin>>st.rollno;
        cout<<" Student Fee : ";
        cin>>st.fee;

        cout<<"\n\n Student Details\n"<<" ";
        cout<<"---------------------------------";
        cout<<"\n Student Name : "<<st.sname;
        cout<<"\n Roll Number : "<<st.rollno;
        cout<<"\n Student Fee : "<<st.fee;
        return 0;
}


Output:

display student details