Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- class DisciplinaryAction {
- private:
- char* name;
- int index;
- char* reason;
- int sessions;
- public:
- DisciplinaryAction() {
- name = new char[100];
- reason = new char[100];
- index = 0;
- sessions = 0;
- }
- DisciplinaryAction(char n[], int i, char r[], int s) {
- name = new char[100];
- strcpy(name, n); // copy the name
- index = i;
- reason = new char[100];
- strcpy(reason, r); // copy the reason
- sessions = s;
- }
- DisciplinaryAction(const DisciplinaryAction& d) {
- name = new char[100];
- reason = new char[100];
- strcpy(name, d.getName());
- index = d.getIndex();
- strcpy(reason, d.getReason());
- sessions = d.getSessions();
- }
- ~DisciplinaryAction() {
- delete name;
- delete reason;
- }
- void print() {
- cout << "Student: " << name << endl;
- cout << "Student's index: " << index << endl;
- cout << "Reason: " << reason << endl;
- cout << "Sessions: " << sessions << endl;
- }
- void setIndex(int i) {
- index = i;
- }
- int getIndex() const {
- return index;
- }
- char* getName() const {
- return name;
- }
- char* getReason() const {
- return reason;
- }
- int getSessions() const {
- return sessions;
- }
- void operator=(const DisciplinaryAction& d) {
- strcpy(name, d.getName());
- index = d.getIndex();
- strcpy(reason, d.getReason());
- sessions = d.getSessions();
- }
- bool operator>=(const DisciplinaryAction& d) {
- return (sessions >= d.getSessions());
- }
- friend ostream& operator<<(ostream &os, const DisciplinaryAction &d) {
- os << "Student: " << d.name << endl;
- os << "Student's index: " << d.index << endl;
- os << "Reason: " << d.reason << endl;
- os << "Sessions: " << d.sessions << endl;
- return os;
- }
- DisciplinaryAction& operator++() {
- ++sessions;
- return *this;
- }
- };
- int main() {
- int n;
- cin >> n;
- /// Testing Default constructor and equal operator
- /// Array input
- DisciplinaryAction arr[n];
- for (int i = 0; i < n; i++) {
- char name[100];
- char reason[100];
- int index;
- int sessions;
- cin >> name >> index >> reason >> sessions;
- arr[i] = DisciplinaryAction(name, index, reason, sessions);
- }
- cout << "-- Testing operator = & operator << --\n";
- cout << arr[0];
- /// Testing copy constructor & set index
- DisciplinaryAction merka(arr[0]);
- merka.setIndex(112233);
- cout << "\n-- Testing copy constructor & set index --\n";
- cout << "-------------\n";
- cout << "Source:\n";
- cout << "-------------\n";
- cout << arr[0];
- cout << "\n-------------\n";
- cout << "Copied and edited:\n";
- cout << "-------------\n";
- cout << merka;
- /// Testing if array is OK
- cout << "\n-- Testing if array was inputted correctly --\n";
- for (int i = 0; i < n; i++)
- cout << arr[i];
- cout << "\nTesting operator ++ and <<" << endl;
- for (int i = 0; i < n; i++)
- cout << (++arr[i]);
- cout << "\nTesting operator >=" << endl;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if (i != j) {
- cout << i << " " << ((arr[i] >= arr[j]) ? ">= " : "< ") << j << endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment