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

Class Example Input and Display Information

The document defines a StudentClass with methods to read student data, calculate totals and averages, and print the results. It then uses two StudentClass objects to read, calculate, and print data for two students.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Class Example Input and Display Information

The document defines a StudentClass with methods to read student data, calculate totals and averages, and print the results. It then uses two StudentClass objects to read, calculate, and print data for two students.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

#include<conio.h>

using namespace std;

class StudentClass {
private:
char name[40];
int regNo, sub1, sub2, sub3;
float total, avg;

public:

void read() {
cout << "Enter Name :";
cin >> name;

cout << "Enter Registration Number :";


cin >> regNo;

cout << "Enter Marks for Subject 1,2 and 3 :";


cin >> sub1 >> sub2>> sub3;
}

void sum() {
total = sub1 + sub2 + sub3;
avg = total / 3;
}

void print() {
cout << "Name :" << name << endl;
cout << "Registration Number :" << regNo << endl;
cout << "Marks :" << sub1 << " , " << sub2 << " , " << sub3 << endl;
cout << "Total :" << total << endl;
cout << "Average :" << avg << endl;
}
};

int main() {
StudentClass stu1, stu2;

cout << "Read and Print Student Information \n";

cout << "\nStudentClass : Student 1" << endl;


stu1.read();
stu1.sum();
stu1.print();

cout << "\nStudentClass : Student 2" << endl;


stu2.read();
stu2.sum();
stu2.print();

getch();
return 0;
}

You might also like