Define a class Student with the following specification:
PRIVATE DATA MEMBERS:
regno integer sname 20 character s1, s2. s3 float total float
PUBLIC MEMBER FUNCTIONS:
Student() Default constructor to initialize data members, s1 = s2 = s3 = 0
Student(rn, sn, m, p, c) Parameterized constructor accept values for regno, sname, s1, s2 and s3
calculate() Function to calculate the student total marks
putdata() Function to display all the data members of student
~student() Destructor to destroy the data objects
#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
Student() {};
Student(int reg, string n, float m, float p, float c);
float calculate();
void putData();
~Student() {};
private:
int regNumber;
string name;
float s1;
float s2;
float s3;
float total;
};
Student::Student(int reg, string n, float m, float p, float c) : regNumber(reg), name(n), s1(m), s2(p), s3(c) {}
float Student::calculate()
{
total = s1 + s2 + s3;
return total;
}
void Student::putData()
{
cout << "Student number is: " << regNumber << endl;
cout << "Student name is: " << name << endl;
cout << "Student specification #1 is: " << s1 << endl;
cout << "Student specification #2 is: " << s2 << endl;
cout << "Student specification #3 is: " << s3 << endl;
cout << "Student total is: " << calculate() << endl;
}
int main()
{
Student Mike(10012, "Mike Wazowski", 25.3, 69.8, 95.3);
Mike.putData();
return 0;
}
Comments
Leave a comment