#define _CRT_SECURE_NO_WARNINGS
#include <iostream>//Input output stream
#include <stdio.h>//standart inp-out(C)
#include <stdlib.h>//Standart Library
#include <string.h>//Library for string function
//define and implement class Student
using namespace std;
class Student
{
//Private section
private:
char name[30];//Name
int regNum;//Register number
int mark[5];//total mark 5 subject
public:
//
Student()//default constructor
{
//defaulting
strcpy(this->name, "");//empty name
this->regNum = 0;
for (int i = 0; i < 5; i++)
this->mark[i] = 0;//0 mark
}
//Parametrazed constructor with name and register number
Student(const char* _name, const int reg)
{
strcpy(this->name, _name);
this->regNum = reg;
for (int i = 0; i < 5; i++)
this->mark[i] = 0;
}
//getter and setter
void setName(const char* s)
{
strcpy(this->name, s);
}
void setRegNum(const int a)
{
this->regNum = a;//set register number
}
void setMark(int a[5])
{
for (int i = 0; i < 5; i++)
this->mark[i] = a[i];
}
const char* getName()const
{
return this->name;
}
int getReg()const
{
return this->regNum;
}
//method which return sum all mark
int sumMark()
{
int sum = 0;
for (int i = 0; i < 5; i++)
sum += this->mark[i];
return sum;
}
//Input console
void InputDate()
{
cout << "Please enter date of student\n";
cout << "\tName:";
cin >> this->name;
cout << "\tRegister number: ";
cin >> this->regNum;
cout << "Total mark for 5 subject\n";
for (int i = 0; i < 5; i++)
cin >> this->mark[i];
}
//Out consoleÂ
void Output()
{
cout << "Name: " << this->getName() << "\t" << "Reg Number:Â "<<this->getReg() << endl;
cout << "Total mark: ";
for (int i = 0; i < 5; i++)
printf("%3d", this->mark[i]);
}
//overload operator >(maximum sum total mark
friend bool operator>(const Student& a, const Student& b);
};
bool operator>( Student& a, Student& b)
{
return a.sumMark() > b.sumMark();
}
int main()
{
int n;//count Student
cout << "Please enter count student: ";
cin >> n;
Student* arS = new Student[n];//alloc memory
//InputÂ
for (int i = 0; i < n; i++)
{
arS[i].InputDate();
}
//find student scrored higgest
int mxNum = 0;
for (int i = 0; i < n; i++)
{
if (arS[i] > arS[mxNum])
mxNum = i;
}
//output dateÂ
cout << "=============Student scored the higgest total=============\n";
arS[mxNum].Output();
delete[]arS;//free alocate memory
return 0;
}
Comments
Leave a comment