cpp:templates
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| cpp:templates [2019/05/04 04:47] – gthanos | cpp:templates [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| - [[cpp:: | - [[cpp:: | ||
| + | Στα παραδείγματα που ακολουθούν χρησιμοποιούμε τη βοηθητική κλάση **Student** που δίνεται παρακάτω: | ||
| + | |||
| + | <code cpp Student.hpp> | ||
| + | |||
| + | #ifndef _STUDENT_HPP_ | ||
| + | #define _STUDENT_HPP_ | ||
| + | # | ||
| + | |||
| + | class Student { | ||
| + | char *name; | ||
| + | int aem; | ||
| + | | ||
| + | public: | ||
| + | Student(const char *name, int aem); | ||
| + | Student(); | ||
| + | Student(const Student& | ||
| + | Student(const Student* ); | ||
| + | ~Student(); | ||
| + | char *getName() const; | ||
| + | int getAEM() const; | ||
| + | void setName(const char *name); | ||
| + | void setAEM(int aem); | ||
| + | friend std:: | ||
| + | bool operator> | ||
| + | bool operator< | ||
| + | Student& | ||
| + | }; | ||
| + | |||
| + | Student:: | ||
| + | this-> | ||
| + | strcpy(this-> | ||
| + | this-> | ||
| + | } | ||
| + | |||
| + | Student:: | ||
| + | name = new char [strlen(st.name) + 1]; | ||
| + | strcpy(name, | ||
| + | aem = st.aem; | ||
| + | } | ||
| + | |||
| + | Student:: | ||
| + | name = new char [strlen(st-> | ||
| + | strcpy(name, | ||
| + | aem = st->aem; | ||
| + | } | ||
| + | |||
| + | Student:: | ||
| + | this-> | ||
| + | this-> | ||
| + | } | ||
| + | |||
| + | Student:: | ||
| + | if(name != nullptr) | ||
| + | delete []name; | ||
| + | } | ||
| + | |||
| + | char* Student:: | ||
| + | return name; | ||
| + | } | ||
| + | |||
| + | int Student:: | ||
| + | return aem; | ||
| + | } | ||
| + | |||
| + | void Student:: | ||
| + | if(this-> | ||
| + | delete this-> | ||
| + | this-> | ||
| + | strcpy(this-> | ||
| + | } | ||
| + | |||
| + | void Student:: | ||
| + | this-> | ||
| + | } | ||
| + | |||
| + | Student& | ||
| + | if(name != nullptr) | ||
| + | delete name; | ||
| + | name = new char [strlen(st.name) + 1]; | ||
| + | strcpy(name, | ||
| + | aem = st.aem; | ||
| + | return *this; | ||
| + | } | ||
| + | |||
| + | std:: | ||
| + | if(st.name != nullptr) | ||
| + | out << st.name << " " << st.aem; | ||
| + | return out; | ||
| + | } | ||
| + | |||
| + | bool Student:: | ||
| + | if(aem > st.aem) | ||
| + | return true; | ||
| + | return false; | ||
| + | } | ||
| + | |||
| + | bool Student:: | ||
| + | if(aem < st.aem) | ||
| + | return true; | ||
| + | return false; | ||
| + | } | ||
| + | #endif | ||
| + | </ | ||
cpp/templates.1556945236.txt.gz · Last modified: 2019/05/04 03:47 (external edit)
