Last active
December 23, 2021 18:28
-
-
Save zindmax/c72335de0faa970835d1e82ce658d884 to your computer and use it in GitHub Desktop.
Lab 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
class foo { | |
private: | |
int x; | |
public: | |
int y; | |
foo(int _x, int _y) : x(_x), y(_y) {} | |
foo() : x(0), y(0) {} | |
string to_string() { | |
return std::to_string(x); | |
} | |
double to_float(){ | |
return (double)x; | |
} | |
int get_x() { | |
return x; | |
} | |
int get_y() { | |
return y; | |
} | |
void set_x(int _x) { | |
x = _x; | |
} | |
void set_y(int _y) { | |
y = _y; | |
} | |
}; | |
class bar : public foo{ | |
public: | |
int z; | |
}; | |
int main() | |
{ | |
foo a; | |
bar b; | |
cout << sizeof(b); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class foo { | |
private: | |
int x; | |
public: | |
int y; | |
}; | |
int main() | |
{ | |
foo a; | |
cout << sizeof(a); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class A { | |
public: | |
int x; | |
}; | |
class B { | |
public: | |
int x; | |
}; | |
class C: public A, public B{ | |
public: | |
int x; | |
void print(){ | |
cout<<A::x<<" "<< B::x<<" "<<x; | |
} | |
}; | |
int main() | |
{ | |
C c; | |
c.x = 3; | |
c.A::x = 1; | |
c.B::x = 2; | |
c.print(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class A { | |
public: | |
int x; | |
}; | |
class B: public A { | |
public: | |
int y; | |
}; | |
class C: public A { | |
public: | |
int z; | |
}; | |
class D: public B, public C{ | |
public: | |
int t; | |
}; | |
int main() | |
{ | |
D d; | |
B &b=d; | |
C &c=d; | |
A &a=c; | |
A &a_1=c; | |
d.B::x = 1; | |
d.C::x = 3; | |
cout << d.B::x << " " << d.C::x << endl; | |
cout << &a << " " << &a_1 << endl; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class A { | |
public: | |
int x; | |
}; | |
class B: virtual public A { | |
public: | |
int y; | |
}; | |
class C: virtual public A { | |
public: | |
int z; | |
}; | |
class D: public B, public C{ | |
public: | |
int t; | |
}; | |
int main() | |
{ | |
D d; | |
B &b=d; | |
C &c=d; | |
A &a=c; | |
A &a_1=c; | |
d.B::x = 1; | |
d.C::x = 3; | |
cout << d.B::x << " " << d.C::x << endl; | |
cout << &a << " " << &a_1 << endl; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class rational { | |
private: | |
long long nom; | |
unsigned long long denom; | |
public: | |
rational() : nom(0), denom(1) {} | |
rational(long long n, unsigned long long d) : nom(n), denom(d) {} | |
rational(long long n): nom(n), denom(1); | |
} | |
int main() | |
{ | |
rational r; | |
rational r=3; | |
rational r(-2, 3); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Progression { | |
public: | |
virtual long long first()=0; | |
virtual long long next()=0; | |
}; | |
class ArithmeticProgression: public Progression { | |
public: | |
long long x; | |
long long y; | |
long long _first; | |
ArithmeticProgression(long long _x, long long _y) : x(_x), y(_y), _first(_x) {} | |
long long first() { | |
return x = _first; | |
} | |
long long next() { | |
return x += y; | |
} | |
}; | |
class GeometricProgression: public Progression { | |
public: | |
long long x; | |
long long y; | |
long long _first; | |
GeometricProgression(long long _x, long long _y) : x(_x), y(_y), _first(_x) {} | |
long long first() { | |
return x = _first; | |
} | |
long long next() { | |
return x *= y; | |
} | |
}; | |
class FibonacciProgression: public Progression { | |
public: | |
long long x; | |
long long y; | |
long long res; | |
long long _first; | |
long long _second; | |
FibonacciProgression(long long _x, long long _y) : x(_x), y(_y), | |
_first(_x), _second(_y) {} | |
long long first() { | |
x = _first; | |
y = _second; | |
return x; | |
} | |
long long next() { | |
res = x + y; | |
x = y; | |
y = res; | |
return x; | |
} | |
}; | |
int main() | |
{ | |
Progression *p[3]; | |
p[0] = new ArithmeticProgression(1, 2); | |
p[1] = new GeometricProgression(1, 2); | |
p[2] = new FibonacciProgression(1, 1); | |
for (int i = 0; i < 3; i++) { | |
for (auto x:p) { | |
cout << x->first(); | |
for (int j = 0; j < 10; j++) { | |
cout<< " " << x->next(); | |
} | |
cout << endl; | |
} | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Progression: | |
def first() : pass | |
def second() : pass | |
class ArithmeticProgression (Progression): | |
def __init__(self, _x, _y): | |
self.x = _x | |
self.y = _y | |
self.xFirst = _x | |
def first(self): | |
self.x = self.xFirst | |
return self.x | |
def next(self): | |
self.x += self.y | |
return self.x | |
class GeometricProgression (Progression): | |
def __init__(self, _x, _y): | |
self.x = _x | |
self.y = _y | |
self.xFirst = _x | |
def first(self): | |
self.x = self.xFirst | |
return self.x | |
def next(self): | |
self.x *= self.y | |
return self.x | |
class FibonacciProgression (Progression): | |
def __init__(self, _x, _y): | |
self.x = _x | |
self.y = _y | |
self.xFirst = _x | |
self.yFirst = _y | |
self.res = 0 | |
def first(self): | |
self.x = self.xFirst | |
self.y = self.yFirst | |
return self.x | |
def next(self): | |
self.res = self.x + self.y | |
self.x = self.y | |
self.y = self.res | |
return self.x | |
def main(): | |
p = [ArithmeticProgression(1, 2), | |
GeometricProgression(1, 2), | |
FibonacciProgression(1, 1)] | |
for i in range(3): | |
for x in p: | |
print(x.first(), end = " ") | |
for j in range(10): | |
print(x.next(), end = " ") | |
print() | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
class foo { | |
private: | |
int x; | |
public: | |
int y; | |
foo(int _x, int _y) : x(_x), y(_y) {} | |
foo() : x(0), y(0) {} | |
string to_string() { | |
return std::to_string(x); | |
} | |
double to_float(){ | |
return (double)x; | |
} | |
int get_x() { | |
return x; | |
} | |
int get_y() { | |
return y; | |
} | |
void set_x(int _x) { | |
x = _x; | |
} | |
void set_y(int _y) { | |
y = _y; | |
} | |
}; | |
int main() | |
{ | |
foo a; | |
cout << sizeof(a); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
class foo { | |
private: | |
int x; | |
public: | |
int y; | |
foo(int _x, int _y) : x(_x), y(_y) {} | |
foo() : x(0), y(0) {} | |
string to_string() { | |
return std::to_string(x); | |
} | |
double to_float(){ | |
return (double)x; | |
} | |
int get_x() { | |
return x; | |
} | |
int get_y() { | |
return y; | |
} | |
void set_x(int _x) { | |
x = _x; | |
} | |
void set_y(int _y) { | |
y = _y; | |
} | |
}; | |
class bar : public foo{ | |
public: | |
int z; | |
string to_string(){ | |
return std::to_string(z); | |
} | |
double to_float(){ | |
return (double)z; | |
} | |
}; | |
int main() | |
{ | |
foo a; | |
bar b; | |
cout << sizeof(b); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment