You are on page 1of 4

#include <iostream>

using namespace std;

struct Student {

string name;

int regNo;

int marks;

};

int main() {

const int numStudents = 100;

Student students[numStudents];

// Input details for each student

for (int i = 0; i < numStudents; i++) {

cout << "Enter details for student " << i + 1 << ":" << endl;

cout << "Name: ";

cin >> students[i].name;

cout << "Registration Number: ";

cin >> students[i].regNo;

cout << "Marks: ";

cin >> students[i].marks;

cout << endl;

}
// Display details of each student

cout << "Details of all students:" << endl;

for (int i = 0; i < numStudents; i++) {

cout << "Student " << i + 1 << ":" << endl;

cout << "Name: " << students[i].name << endl;

cout << "Registration Number: " << students[i].regNo << endl;

cout << "Marks: " << students[i].marks << endl;

cout << endl;

return 0;

Certainly! Here's an example of a C++ program that uses a structure to store and display details of 100
students, including their full name, registration number, and marks:

```cpp

#include <iostream>

using namespace std;

struct Student {

string fullName;

int regNumber;
int marks;

};

int main() {

Student students[100];

// Input details of students

for (int i = 0; i < 100; i++) {

cout << "Enter details for student " << i+1 << ":" << endl;

cout << "Full Name: ";

getline(cin, students[i].fullName);

cout << "Registration Number: ";

cin >> students[i].regNumber;

cout << "Marks: ";

cin >> students[i].marks;

cin.ignore(); // Ignore the newline character

cout << endl;

// Display details of students

cout << "Details of all students:" << endl;


for (int i = 0; i < 100; i++) {

cout << "Student " << i+1 << ":" << endl;

cout << "Full Name: " << students[i].fullName << endl;

cout << "Registration Number: " << students[i].regNumber << endl;

cout << "Marks: " << students[i].marks << endl;

cout << endl;

return 0;

```

In this program, we define a structure named `Student` with three members: `fullName` (string),
`regNumber` (integer), and `marks` (integer).

We declare an array of `Student` structures named `students` with a size of 100 to store the details of
100 students.

The program then prompts the user to input the details for each student using a loop. It asks for the full
name, registration number, and marks for each student. The `getline` function is used to read the full
name, while the `>>` operator is used to read the registration number and marks.

After inputting the details, the program displays the details of all students using another loop.

Note that the program assumes valid input and doesn't perform any error checking. It also uses `using
namespace std;` for simplicity, but it's generally recommended to avoid this practice in larger program

You might also like