-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVirtualFunctions.cpp
116 lines (85 loc) · 2.09 KB
/
VirtualFunctions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
*/
// problem : https://www.hackerrank.com/challenges/virtual-functions/problem
// solution ===============================================================
/*
class Person {
protected:
string name;
short age;
public:
virtual void getdata() {};
virtual void putdata() {};
Person() {
}
};
class Professor : public Person {
protected:
int publications;
public:
static int cur_Pid;
void getdata() {
string newN;
short newAG;
int newPubs;
cin >> newN >> newAG >> newPubs;
name = newN; age = newAG; publications = newPubs;
}
void putdata() {
Professor::cur_Pid += 1;
cout << name << " " << age << " " << publications << " " << cur_Pid << endl;
}
Professor() {
}
};
int Professor::cur_Pid = 0;
class Student :public Person {
protected:
int marks[6]; int sum = 0;
public:
static int cur_id;
void getdata() {
string newN;
short newAG;
cin >> newN >> newAG;
name = newN; age = newAG;
for (int m = 0; m < 6; m += 1) {
cin >> marks[m];
sum += marks[m];
}
}
void putdata() {
Student::cur_id += 1;
cout << name << " " << age << " " << sum << " " << cur_id << endl;
}
Student() {
}
};
int Student::cur_id = 0;
*/
//=================================================================================
/*
int main() {
int n, val;
cin >> n; //The number of objects that is going to be created.
Person* per[n];
for (int i = 0; i < n; i++) {
cin >> val;
if (val == 1) {
// If val is 1 current object is of type Professor
per[i] = new Professor;
}
else per[i] = new Student; // Else the current object is of type Student
per[i]->getdata(); // Get the data from the user.
}
for (int i = 0; i < n; i++)
per[i]->putdata(); // Print the required output for each object.
return 0;
}
*/