0% found this document useful (0 votes)
23 views3 pages

Class

The document contains a C++ program that defines a 'student' class to manage student data, including roll number, name, and marks in three subjects. It allows users to input data for multiple students and then displays the details along with total marks. The program uses dynamic allocation based on user input for the number of students.
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)
23 views3 pages

Class

The document contains a C++ program that defines a 'student' class to manage student data, including roll number, name, and marks in three subjects. It allows users to input data for multiple students and then displays the details along with total marks. The program uses dynamic allocation based on user input for the number of students.
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

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:

You might also like