Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <list>
- #include <iterator>
- #include <fstream>
- using namespace std;
- class cstudent
- {
- private:
- vector <double> grades;
- protected:
- string fnum;
- public:
- cstudent(string getfnum)
- {
- fnum = getfnum;
- }
- cstudent(const cstudent& obj)
- {
- fnum = obj.fnum;
- }
- void set_fnum(string getfnum)
- {
- fnum = getfnum;
- }
- string getfnum()
- {
- return fnum;
- }
- virtual double avgcalc()
- {
- if (grades.size() > 0)
- {
- vector<double>::iterator iter;
- double avg_grade(0);
- for (iter = grades.begin(); iter != grades.end(); iter++)
- {
- avg_grade += (*iter);
- }
- avg_grade = avg_grade / grades.size();
- return avg_grade;
- }
- }
- friend ostream& operator <<(ostream& out, const cstudent& obj)
- {
- out << obj.fnum;
- return out;
- }
- friend istream& operator >>(istream& in, cstudent& obj)
- {
- in >> obj.fnum;
- return in;
- }
- cstudent operator =(cstudent& obj)
- {
- fnum = obj.fnum;
- return *this;
- }
- };
- class examBook
- {
- string discipline;
- unsigned int discPoints;
- public:
- examBook(string getdiscipline, int getdiscPoints)
- { discipline = getdiscipline; discPoints = getdiscPoints; }
- string getdiscipline() {
- return discipline;
- }
- int getdiscPoints() {
- return discPoints;
- }
- friend ostream& operator <<(ostream& out, const examBook& obj) {
- return (out << obj.discipline << endl << obj.discPoints << endl);
- }
- friend istream& operator >>(istream& in, examBook& obj){
- in >> obj.discipline;
- in >> obj.discPoints;
- return in;
- }// i/o stream
- // friend ofstream& operator >>(ofstream& out, const examBook& obj) {
- // return (out << obj.discipline << endl << obj.discPoints << endl);
- //}
- friend ifstream& operator <<(ifstream& in, examBook& obj) {
- in >> obj.discipline;
- in >> obj.discPoints;
- return in;
- }// i/o fstream
- /* examBook operator +(examBook ob) {
- examBook temp;
- temp.discPoints = discPoints + ob.discPoints;
- return temp;
- }*/
- /* friend int iCardSum(examBook& obj, int addedPoints) {
- obj.discPoints += addedPoints;
- return obj.discPoints;
- }*/
- friend unsigned operator +(examBook& ob,const unsigned int & iCardSum) {
- return ob.discPoints = ob.discPoints + iCardSum;
- }
- };
- class CStudentBook:public cstudent
- {
- private:
- list<examBook>exmB_points;
- public:
- CStudentBook();
- void showAll() {
- list<examBook>::iterator it;
- for (it = exmB_points.begin(); it != exmB_points.end(); it++)
- {
- cout << (*it).getdiscipline() << (*it).getdiscPoints() << endl;
- }
- }
- void setList(examBook& ob) {
- exmB_points.push_back(ob);
- }
- };
- int main()
- {
- examBook predmet("matematika", 10), predmet1("da",3);
- // cout << predmet << endl;
- // cin >> predmet;
- //// iCardSum(predmet, 10);
- // predmet + (predmet,10);
- // cout << predmet << endl;
- /*ofstream myfile("test.txt");
- cin >> predmet;
- if (myfile.is_open())
- {
- myfile << predmet;
- myfile.close();
- }
- else cout << "Unable to open file";
- string line;
- ifstream da("test.txt");
- if (da.is_open())
- {
- cout << line << '\n';
- da.close();
- }
- else cout << "Unable to open file";*/
- CStudentBook obe;
- obe.set_fnum("123");
- obe.setList(predmet);
- obe.setList(predmet1);
- obe.showAll();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement