cpp:templates
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
cpp:templates [2019/05/02 13:30] – created gthanos | cpp:templates [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
- [[cpp:: | - [[cpp:: | ||
- | - [[cpp:: | ||
- [[cpp:: | - [[cpp:: | ||
- | - [[cpp:: | ||
- [[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.1556803825.txt.gz · Last modified: 2019/05/02 12:30 (external edit)