Store Information(name, roll and marks) of a Student Using Structure using C++ Prg.
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.
C++ Program to Store Information of Single Variable
#include <iostream>
#include <cstring>
using namespace std;
struct student{
char name[50];
int roll;
float marks;
};
int main(){
struct student s;
cout << "Enter information of students: " << endl;
cout << "Enter name: ";
cin >> s.name;
cout << "Enter roll number: ";
cin >> s.roll;
cout << "Enter marks: ";
cin >> s.marks;
cout << endl << "Displaying Information" << endl;
cout << endl << "Name: " << s.name;
cout << endl << "Roll: " << s.roll;
cout << endl << "Marks: " << s.marks;
return 0;
}
Output
Enter information of students:
Enter name: Adele
Enter roll number: 21
Enter marks: 334.5
Displaying Information
name: Adele
Roll: 21
Marks: 334.5