Skip to content

Commit 4a00845

Browse files
committed
SOE ProgNyelvek1 Excercises
1 parent cdb2d74 commit 4a00845

5 files changed

Lines changed: 192 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
Irj egy Sierpinsky fuggvenyt, ami megadott melysegben kirajzolja a Sierpinsky haromszoget.
3+
(Ez alatt most az ertendo, hogy a Pascal haromszoget n melysegig, es akkor annak paritasa alapjan # vagy szokoz.)
4+
A main-ben pedig beolvas egy egesz szamot, es olyan meglysegben rajzol ki.
5+
*/
6+
7+
8+
void drawSierpinsky(int depth) {
9+
10+
}
11+
12+
13+
int main(){
14+
15+
return 0;
16+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
#include "complex.hpp"
3+
4+
Complex::Complex( double real, double imaginary)
5+
: _real(real), _imag(imaginary) {}
6+
7+
double Complex::real() const { return _real; }
8+
double Complex::imaginary() const { return _imag; }
9+
Complex Complex::conjugate() const { return Complex( _real,- _imag ); }
10+
11+
Complex Complex::operator - () const { return Complex( - _real, - _imag ); }
12+
13+
Complex Complex::operator + ( double r ) const {return Complex(*this)+=r; }
14+
Complex Complex::operator - ( double r ) const {return Complex(*this)-=r; }
15+
Complex Complex::operator * ( double r ) cs << c.real() onst {return Complex(*this)*=r; }
16+
Complex Complex::operator / ( double r ) const {return Complex(*this)/=r; }
17+
18+
Complex Complex::operator + ( const Complex& c ) const {
19+
return Complex( _real + c._real , _imag + c._imag );
20+
}
21+
Complex Complex::operator - ( const Complex& c ) const {
22+
return Complex( _real - c._real , _imag - c._imag );
23+
}
24+
Complex Complex::operator * ( const Complex& c ) const {
25+
return Complex( _real * c._real - _imag * c._imag, _real * c._imag + _imag * c._real );
26+
}
27+
Complex Complex::operator / ( const Complex& c ) const {
28+
const double denominator = c._real * c._real + c._imag * c._imag;
29+
return (*this) * c.conjugate() / denominator;
30+
}
31+
32+
Complex& Complex::operator += ( double r ) {
33+
_real += r;
34+
return *this;
35+
};
36+
Complex& Complex::operator -= ( double r ) {
37+
_real -= r;
38+
return *this;
39+
}
40+
Complex& Complex::operator *= ( double r ) {
41+
_real *= r;
42+
_imag *= r;
43+
return *this;
44+
}
45+
Complex& Complex::operator /= ( double r ) {
46+
_real /= r;
47+
_imag /= r;
48+
return *this;
49+
}
50+
51+
Complex& Complex::operator += ( const Complex& c ) { return *this = *this + c; }
52+
Complex& Complex::operator -= ( const Complex& c ) { return *this = *this - c; }
53+
Complex& Complex::operator *= ( const Complex& c ) { return *this = *this * c; }
54+
Complex& Complex::operator /= ( const Complex& c ) { return *this = *this / c; }
55+
56+
bool Complex::operator == (const Complex& c ) {
57+
return _real == c._real && _imag == c._imag;
58+
}
59+
60+
Complex operator + ( double r, const Complex& c ) { return c + r; };
61+
Complex operator - ( double r, const Complex& c ) { return c - r; };
62+
Complex operator * ( double r, const Complex& c ) { return c * r; };
63+
Complex operator / ( double r, const Complex& c ) { return c / r; };
64+
65+
std::ostream& operator << (std::ostream& s, const Complex& c ) {
66+
if ( c.real() == 0 && c.imaginary() == 0 ) {
67+
s << "0";
68+
} else if ( c.real() == 0 ) {
69+
s << c.imaginary() << "i";
70+
} else if ( c.imaginary() == 0 ) {
71+
s << c.real();
72+
} else {
73+
s << c.real();
74+
if (c.imaginary() > 0) {
75+
s << " + " << c.imaginary() << "i";
76+
} else {
77+
s << " - " << -c.imaginary() << "i";
78+
};
79+
}
80+
return s;
81+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef COMPLEX_HPP
2+
#define COMPLEX_HPP
3+
4+
#include <iostream>
5+
6+
class Complex {
7+
double _real;
8+
double _imag;
9+
10+
public:
11+
Complex( double real = 0, double imaginary = 0);
12+
13+
double real() const;
14+
double imaginary() const;
15+
Complex conjugate() const;
16+
17+
18+
Complex operator - () const;
19+
20+
Complex operator + ( double r ) const;
21+
Complex operator - ( double r ) const;
22+
Complex operator * ( double r ) const;
23+
Complex operator / ( double r ) const;
24+
25+
Complex operator + ( const Complex& c ) const;
26+
Complex operator - ( const Complex& c ) const;
27+
Complex operator * ( const Complex& c ) const;
28+
Complex operator / ( const Complex& c ) const;
29+
30+
Complex& operator += ( double r );
31+
Complex& operator -= ( double r );
32+
Complex& operator *= ( double r );
33+
Complex& operator /= ( double r );
34+
35+
Complex& operator += ( const Complex& c );
36+
Complex& operator -= ( const Complex& c );
37+
Complex& operator *= ( const Complex& c );
38+
Complex& operator /= ( const Complex& c );
39+
40+
bool operator == (const Complex& c );
41+
};
42+
43+
44+
Complex operator + ( double r, const Complex& c ) ;
45+
Complex operator - ( double r, const Complex& c ) ;
46+
Complex operator * ( double r, const Complex& c ) ;
47+
Complex operator / ( double r, const Complex& c ) ;
48+
49+
50+
std::ostream& operator << (std::ostream& s, const Complex& c );
51+
52+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Irj meg egy Complex nevu osztalyt, amiben complex szamokat lehet tarolni, es tudunk azzal szamolni. Az alabbi main forduljon le vele.
3+
*/
4+
5+
#include <iostream>
6+
using namespace std;
7+
#include "complex.hpp"
8+
9+
int main() {
10+
Complex c1(2,-3);
11+
Complex c2(3);
12+
13+
Complex c3 = c2;
14+
15+
double real, imaginary;
16+
cin >> real >> imaginary;
17+
Complex c4(real,imaginary);
18+
19+
if (c1 == c4) {
20+
cout << "Yeppee\n";
21+
}
22+
23+
cout << c1 + c2 * (c2 - 3*c3 ) << "\n";
24+
return 0;
25+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Csinalj egy Polynom osztalyt, mely egy polinom fuggvenyt ir le.
3+
Mukodjon vele minden az alabbi main-bol:
4+
*/
5+
6+
int main() {
7+
Polynom f(3, {1,2,3}); // 3x^2 + 2x + 1
8+
Polynom g(2, {0,1}); // x^2
9+
10+
Polynom h = f*g;
11+
Polynom dh = h.derivate();
12+
13+
14+
std::cout << dh.at(5);
15+
// advanced:
16+
std::cout << dh(5);
17+
return 0;
18+
}

0 commit comments

Comments
 (0)