codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#ifndef STUDENT_H #define STUDENT_H #define ID_MAX 999 #define ID_MIN 111 #define EXAM_MAX 100 #define EXAM_MIN 0 #include<fstream> #include<iomanip> #include <iostream> #include "mmm.h" using namespace std; class student{ public: //structures: //viarables: //functions: student(); //student(const student& tocopy); student(int nid, float exam1, float exam2, float exam3, char nmajor, char sex); ~student(); void setall(int nid, float exam1, float exam2, float exam3, char nmajor, char nsex); void print(ofstream &fout); bool isgood() const {return isGood;} int myid() const {return id;} bool operator== (student other); //private: //structures: //viarables: int id; float exam[3]; char major, sex; bool isGood; //functions: inline void init(int nid, float exam1, float exam2, float exam3, char nmajor, char sex); protected: //structures: //viarables: //functions: }; bool student::operator== (student other){ cout<<id<<":"; cout<<other.id<<endl; return (&other!=NULL && other.id==id); } student::student(){ cout<<"enpty initializer called for student\n"; init(0,0,0,0,'n','n'); } /*student::student(const student& tocopy){ id=tocopy.id; exam[0]=tocopy.exam[0]; exam[1]=tocopy.exam[1]; exam[2]=tocopy.exam[2]; major=tocopy.major; sex=tocopy.sex; }*/ student::student(int nid, float exam1, float exam2, float exam3, char nmajor, char nsex){ init(nid,exam1,exam2,exam3,nmajor,nsex); } student::~student(){ cout<<"removing student: "<<id<<endl; } void student::setall(int nid, float exam1, float exam2, float exam3, char nmajor, char nsex){ init(nid,exam1,exam2,exam3,nmajor,nsex); } inline void student::init(int nid, float exam1, float exam2, float exam3, char nmajor, char nsex){ id=nid; exam[0]=exam1; exam[1]=exam2; exam[2]=exam3; major=tolower(nmajor); sex=tolower(nsex); isGood=false; if(id>ID_MAX || id<ID_MIN){ }else if(exam[0]>EXAM_MAX || exam[0]<EXAM_MIN){ }else if(exam[1]>EXAM_MAX || exam[1]<EXAM_MIN){ }else if(exam[2]>EXAM_MAX || exam[2]<EXAM_MIN){ }else if(major!='c' && major!='i'){ }else if(sex!='m' && sex!='f'){ }else{ isGood=true; } } void student::print(ofstream &fout){ fout<<setw(5)<<id<<setw(7)<<exam[0]<<setw(7)<<exam[1]<<setw(7)<<exam[2]; fout<<setw(7)<<(major=='c'?"CS":"IS")<<sex<<endl; } #endif
Private
[
?
]
Run code
Submit