0% found this document useful (0 votes)
39 views

Include - iostre-WPS Office

This C++ program uses a structure to store student details, including name, registration number, and marks. It defines a Student structure with these data members and an array of 100 Student structures to hold details for 100 students. The program prompts the user to input details for each student using a for loop and stores them in the array. It then displays the details of all students in another for loop.

Uploaded by

Emmanuel Otieno
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Include - iostre-WPS Office

This C++ program uses a structure to store student details, including name, registration number, and marks. It defines a Student structure with these data members and an array of 100 Student structures to hold details for 100 students. The program prompts the user to input details for each student using a for loop and stores them in the array. It then displays the details of all students in another for loop.

Uploaded by

Emmanuel Otieno
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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