Let’s see Student Mark List Program In C++ Using Array and structures.
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
#include <iostream> using namespace std; struct student { string name; int Subjects_Quantity; int marks[30]; }; void Show_StudentDetails(student students[], int Students_Quantity) { for (int i = 0; i < Students_Quantity; i++) { cout << "Student name : " << students[i].name << endl; cout << "Marks :" << endl; for (int j = 0; j < students[i].Subjects_Quantity; j++) { cout << students[i].marks[j] << endl; } } } int main() { int Students_Quantity; cout << "Please Enter total number of students : "; cin >> Students_Quantity; if (Students_Quantity <= 0) { cout << "Please Please Enter a valid number" << endl; return -1; } student Array4students[Students_Quantity]; for (int i = 0; i < Students_Quantity; i++) { cout << "Please Enter the name of student " << (i + 1) << " : " << endl; cin >> Array4students[i].name; cout << "Please Enter total number of subjects : "; cin >> Array4students[i].Subjects_Quantity; if (Array4students[i].Subjects_Quantity > 20 || Array4students[i].Subjects_Quantity <= 0) { cout << "Please Please Enter a valid number" << endl; return -1; } for (int j = 0; j < Array4students[i].Subjects_Quantity; j++) { cout << "Please Enter marks for subject " << (j + 1) << " : " << endl; cin >> Array4students[i].marks[j]; } } Show_StudentDetails(Array4students, Students_Quantity); } |
Output
Please Enter total number of students : 2
Please Enter the name of student 1 :
fazal
Please Enter total number of subjects : 2
Please Enter marks for subject 1 :
33
Please Enter marks for subject 2 :
44
Please Enter the name of student 2 :
rehman
Please Enter total number of subjects : 2
Please Enter marks for subject 1 :
77
Please Enter marks for subject 2 :
88
Student name : fazal
Marks :
33
44
Student name : rehman
Marks :
77
88