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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #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