Program:
#include <iostream>
#include <string>
using namespace std;
class student {
int roll_number; // Corrected variable name
string name;
float m1, m2, m3, total;
public:
void getdata() {
cout << "Enter roll no: ";
cin >> roll_number;
cout << "Enter name: ";
cin >> name;
cout << "Enter mark for s1: ";
cin >> m1;
cout << "Enter mark for s2: ";
cin >> m2;
cout << "Enter mark for s3: ";
cin >> m3;
total = m1 + m2 + m3;
void putdata() const {
cout << "\nStudent details:\n";
cout << "Roll no: " << roll_number << endl;
cout << "Name: " << name << endl;
cout << "Marks in s1: " << m1 << endl;
cout << "Marks in s2: " << m2 << endl;
cout << "Marks in s3: " << m3 << endl;
cout << "Total marks: " << total << endl;
};
int main() {
int n;
cout << "Enter the number of students: ";
cin >> n;
student S[n]; // Dynamic allocation based on user input
for (int i = 0; i < n; i++)
S[i].getdata();
for (int i = 0; i < n; i++)
S[i].putdata();
return 0;
}
Output: