C++ Program to store information of a student in a Structure

In this tutorial, we will write a program to store information of a student in a Structure in C++. You may go through the following topics first.

C++ program using structure.

#include <iostream>
using namespace std;

//creating the structure
struct student
{
    char name[50];
    int roll;
    float marks;
    char grade;
};

//main
int main() 
{
    student std;
    cout << "Enter your Detail:" << endl;
    cout << "Name: ";
    cin >> std.name;
    cout << "Roll Number: ";
    cin >> std.roll;
    cout << "Marks: ";
    cin >> std.marks;
    cout << "Grade: ";
    cin >> std.grade;

    cout << "\nDisplaying Information," << endl;
    cout << "Name: " << std.name << endl;
    cout << "Roll: " << std.roll << endl;
    cout << "Marks: " << std.marks << endl;
    cout << "Grade: " << std.grade << endl;
    return 0;
}

Output:

Enter your Detail:
Name: Pushpa
Roll Number: 1101
Marks: 80
Grade: A

Displaying Information,
Name: Pushpa
Roll: 1101
Marks: 80
Grade: A