labs 1-6: init

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-12-24 14:03:08 +05:30
commit ad185c994e
26 changed files with 2250 additions and 0 deletions

45
lab3/8.cpp Normal file
View File

@@ -0,0 +1,45 @@
#include <iostream>
using namespace std;
class Complex {
private:
int r, i;
public:
Complex() = default;
Complex(int);
Complex(int, int);
Complex operator+(Complex);
void display();
};
Complex::Complex(int a) { this->r = this->i = a; }
Complex::Complex(int r, int i) {
this->r = r;
this->i = i;
}
Complex Complex::operator+(Complex op) {
return Complex(this->r + op.r, this->i + op.i);
}
void Complex::display() {
if (this->r)
cout << this->r;
if (this-> r && this->i > 0)
cout << '+';
if (this->i)
cout << this->i << 'i';
cout << endl;
}
int main() {
Complex c;
Complex a(4), b(34, -2124);
c = a + b;
c.display();
}