consolidate all repos to one for archive
This commit is contained in:
24
semester_2/programiranje_2/primeri/Example25/Assistant.h
Normal file
24
semester_2/programiranje_2/primeri/Example25/Assistant.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef EXAMPLE25_ASSISTANT_H
|
||||
#define EXAMPLE25_ASSISTANT_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Assistant : public Person {
|
||||
//class Assistant : public virtual Person {
|
||||
protected:
|
||||
std::string faculty;
|
||||
std::string subject;
|
||||
public:
|
||||
Assistant(std::string n, std::string f, std::string s) : Person(n), faculty(f), subject(s) {
|
||||
}
|
||||
virtual ~Assistant() {
|
||||
}
|
||||
virtual void print() const {
|
||||
std::cout << "Assistant: " << name << " " << faculty << " " << subject << std::endl;
|
||||
}
|
||||
virtual std::string department() const {
|
||||
return faculty;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EXAMPLE25_ASSISTANT_H
|
18
semester_2/programiranje_2/primeri/Example25/Person.h
Normal file
18
semester_2/programiranje_2/primeri/Example25/Person.h
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
#ifndef EXAMPLE25_PERSON_H
|
||||
#define EXAMPLE25_PERSON_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Person {
|
||||
protected:
|
||||
std::string name;
|
||||
public:
|
||||
Person(std::string n) : name(n) {};
|
||||
virtual ~Person() {}
|
||||
virtual void print() const {
|
||||
std::cout << "Person: " << name << " " << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EXAMPLE25_PERSON_H
|
25
semester_2/programiranje_2/primeri/Example25/Student.h
Normal file
25
semester_2/programiranje_2/primeri/Example25/Student.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef EXAMPLE25_STUDENT_H
|
||||
#define EXAMPLE25_STUDENT_H
|
||||
|
||||
#include <iostream>
|
||||
#include "Person.h"
|
||||
|
||||
class Student : public Person {
|
||||
//class Student : virtual public Person {
|
||||
protected:
|
||||
std::string faculty;
|
||||
double avgGrade;
|
||||
public:
|
||||
Student(std::string n, std::string f, double g) : Person(n), faculty(f), avgGrade(g) {
|
||||
};
|
||||
virtual ~Student() {
|
||||
}
|
||||
virtual void print() const {
|
||||
std::cout << "Student: " << name << " " << faculty << " " << avgGrade << std::endl;
|
||||
}
|
||||
virtual std::string department() const {
|
||||
return faculty;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EXAMPLE25_STUDENT_H
|
@@ -0,0 +1,32 @@
|
||||
#ifndef EXAMPLE25_STUDENTASSISTANT_H
|
||||
#define EXAMPLE25_STUDENTASSISTANT_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class StudentAssistant : public Assistant, public Student {
|
||||
public:
|
||||
|
||||
StudentAssistant(std::string n, std::string f1, double g, std::string f2, std::string s) :
|
||||
Student(n, f1, g), Assistant(n, f2, s) {}
|
||||
//Student("S-"+n, f1, g), Assistant("A-"+n, f2, s) {}
|
||||
// When virtual derivation calls to constructors Person are ignored in classes Student and Assistant
|
||||
// calling constructor Person needs to be explicit here
|
||||
//StudentAssistant(std::string n, std::string f1, double g, std::string f2, std::string s) :
|
||||
//Person(n), Student(n, f1, g), Assistant(n, f2, s) {}
|
||||
//Person(n), Student("S-"+n, f1, g), Assistant("A-"+n, f2, s) {}
|
||||
|
||||
virtual ~StudentAssistant() {
|
||||
}
|
||||
void print() const {
|
||||
// without virtual derivation it does not work
|
||||
//std::cout << "Student-Assistant: " << Person::name << " " << Student::faculty << " "
|
||||
// << avgGrade << " " << Assistant::faculty << " " << subject << std::endl;
|
||||
std::cout << "Student-Assistant: " << Student::name << " " << Student::faculty << " "
|
||||
<< avgGrade << " " << Assistant::name << " " << Assistant::faculty << " " << subject << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif //EXAMPLE25_STUDENTASSISTANT_H
|
||||
|
||||
|
31
semester_2/programiranje_2/primeri/Example25/main.cpp
Normal file
31
semester_2/programiranje_2/primeri/Example25/main.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
#include "Person.h"
|
||||
#include "Student.h"
|
||||
#include "Assistant.h"
|
||||
#include "StudentAssistant.h"
|
||||
|
||||
int main() {
|
||||
Person o1("Anna");
|
||||
Student s1("Mark", "FERI", 8.3);
|
||||
Assistant a1("Mary", "FKKT", "Introduction to chemistry");
|
||||
StudentAssistant sa1("John", "FNM", 10, "FERI", "Discrete math");
|
||||
|
||||
o1.print();
|
||||
s1.print();
|
||||
a1.print();
|
||||
sa1.print();
|
||||
/*
|
||||
std::cout << "--------------" << std::endl;
|
||||
Person* society[4];
|
||||
society[0]=&o1;
|
||||
society[1]=&s1;
|
||||
society[2]=&a1;
|
||||
//society[3]=&a1;
|
||||
society[3]=&sa1; //without virtual derivation class StudentAssistant can not be converted to class Person
|
||||
for (int i=0; i < 4; i++) {
|
||||
society[i]->print();
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user