-
Notifications
You must be signed in to change notification settings - Fork 1
/
quad.cpp
119 lines (98 loc) · 2.39 KB
/
quad.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
117
118
119
#include <iostream>
using namespace std;
class Pair{
protected:
int x, y;
public:
Pair():x(0),y(0) {}
Pair(int v1, int v2):x(v1), y(v2) {}
int GetX()const{return x;}
int GetY()const{return y;}
void SetX(int v){ x = v;}
void SetY(int v){ y = v;}
virtual void Set(int v1, int v2){x=v1;y=v2;}
void Print()const{cout << "[" << x << "," << y << "]";}
};
class Triple : public Pair{
protected:
int z;
public:
Triple(): z(0){}
Triple(int v):z(v){}
Triple(int v1, int v2, int v3):Pair(v1,v2),z(v3){}
int GetZ()const {return z;}
void SetZ(int v){z=v;}
virtual void Set(int v1, int v2, int v3){
Pair::Set(v1,v2);
z=v3;
}
void Print()const{
cout << "[" << GetX() << "," << GetY() << "," << z << "]";
}
};
class Quad : public Triple{
int w;
public:
Quad(): w(0){}
Quad(int v):w(v){}
Quad(int v1, int v2, int v3, int v4):Triple(v1,v2,v3),w(v4){}
int GetW()const {return w;}
void SetW(int v){w=v;}
void Set(int v1, int v2, int v3, int v4){
Triple::Set(v1,v2,v3);
w=v4;
}
void Print()const{
cout << "[" << GetX() << "," << GetY() << "," << GetZ() << "," << w << "]";
}
};
int main() {
Pair p1;
Pair* ptrarr[5];
int choice = -1;
int x;
int y;
int z;
int w;
for(int i=0; i<5; i++){
while(choice < 2 || choice > 4){
cout<<"2: For ordered pair\n3: For triple\n4: For Quad\n";
cin>>choice;
}
if(choice == 2){
Pair temp;
ptrarr[i] = &temp;
cout<<"Enter x: ";
cin>>x;
cout<<"Enter y: ";
cin>>y;
ptrarr[i]->Set(x,y);
}
else if(choice == 3){
Triple temp3;
ptrarr[i] = &temp;
cout<<"Enter x: ";
cin>>x;
cout<<"Enter y: ";
cin>>y;
cout<<"Enter z: ";
cin>>z;
ptrarr[i]->Set(x,y,z);
}
else if(choice == 4){
Quad temp4;
ptrarr[i] = &temp;
cout<<"Enter x: ";
cin>>x;
cout<<"Enter y: ";
cin>>y;
cout<<"Enter z: ";
cin>>z;
cout<<"Enter w: ";
cin>>w;
ptrarr[i]->Set(x,y,z,w);
}
choice = -1;
}
return 0;
}