1. Program to display names, roll numbers, and grades of 3 students who have appeared in an examination using a class. Create an array of class objects and read and display the contents of the array.
#include <iostream.h>
#include<conio.h>
class Student {
public:
char name[50];
int rollNo;
float grade;
void inputDetails() {
cout << "Enter name: ";
cin >> name;
cout << "Enter roll number: ";
cin >> rollNo;
cout << "Enter grade: ";
cin >> grade;
}
void displayDetails() {
cout << "Name: " << name << endl;
cout << "Roll Number: " << rollNo << endl;
cout << "Grade: " << grade << endl;
}
};
int main() {
Student students[3];
int student_count=0;
cout << "\nEnter the number of students: ";
cin >> student_count;
for (int i = 0; i < student_count; i++) {
cout << "Enter details for student " << i + 1 << endl;
students[i].inputDetails();
}
cout << "\nStudent Details:\n";
for (int j = 0; j < student_count; j++) {
students[j].displayDetails();
cout << endl;
}
getch();
return 0;
}