C++ Program to Store Information of a Student Using Structure
In this example, we will learn to Store Information of a Student Using Structure.
To understand this example, you should have the knowledge of the following C++ programming topics:
Introduction
In this program, a structure(student) is created which contains name, roll and marks as its data member. Then, a structure variable(s) is created. Then, data (name, roll and marks) is taken from user and stored in data members of structure variable s
. Finally, the data entered by user is displayed.
Example: Program to Store and Display Information Using Structure
#include <iostream>
using namespace std;
struct student
{
char name[50];
int roll;
float marks;
};
int main()
{
student s;
cout << "Enter information," << endl;
cout << "Enter name: ";
cin >> s.name;
cout << "Enter roll number: ";
cin >> s.roll;
cout << "Enter marks: ";
cin >> s.marks;
cout << "\nDisplaying Information," << endl;
cout << "Name: " << s.name << endl;
cout << "Roll: " << s.roll << endl;
cout << "Marks: " << s.marks << endl;
return 0;
}
Output
Enter information, Enter name: Bill Enter roll number: 4 Enter marks: 55.6 Displaying Information, Name: Bill Roll: 4 Marks: 55.6
working
In this program, student (structure) is created. This structure has three members: name (string), roll (integer) and marks (float). Then, a structure variable s is created to store information and display it on the screen.
Next Example
We hope that this Example helped you develop better understanding of the concept of "Store Information of a Student Using Structure" in C++.
Keep Learning : )
In the next Example, we will learn about C++ Add Two Distances (in inch-feet system) using Structures
.