consolidate all repos to one for archive

This commit is contained in:
2025-01-28 13:46:42 +01:00
commit a6610fbc7a
5350 changed files with 2705721 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
#include <iostream>
#include "Complex.h"
Complex::Complex() : real(0), imag(0) {
}
Complex::Complex(double r, double i): real(r), imag(i) {
}
//Complex::Complex(const Complex& c) : real(c.real), imag(c.imag) {
//}
//Complex::~Complex() {
//}
void Complex::print() {
std::cout << "(" << real << ", " << imag << "i)" << std::endl;
}
//Complex Complex::plus(Complex c) {
Complex Complex::plus(Complex& c) {
Complex temp(real+c.real, imag+c.imag);
//c.imag=0;
return temp;
}

View File

@@ -0,0 +1,20 @@
#ifndef EXAMPLE03_COMPLEX_H
#define EXAMPLE03_COMPLEX_H
class Complex {
private:
double real, imag;
public:
Complex(); // default constructor
// conversion constructor with default arguments
Complex(double r, double i = 0);
//Complex(const Complex& c); // copy constructor
//~Complex(); // destructor
void print();
//Complex plus(Complex c);
Complex plus(Complex& c);
};
#endif //EXAMPLE03_COMPLEX_H

View File

@@ -0,0 +1,30 @@
#include <iostream>
#include "Complex.h"
int main() {
Complex c1(1,1), c2(1), i(0,1);
//Complex c3(c1);
c1.print();
c2.print();
i.print();
//c3.print();
std::cout << "----------" << std::endl;
//c1.plus(5).print(); // doesn't work with Complex& as argument
c1.plus(i).print();
std::cout << "----------" << std::endl;
c1.print();
i.print();
/*
std::cout << "Dynamic allocation" << std::endl;
Complex* p_c = new Complex(4,2);
p_c->print();
c1.plus(*p_c).print();
Complex c3(c1.plus(*p_c));
c3.print();
Complex* p_c1 = new Complex(c1.plus(i));
p_c1->print();
delete p_c;
delete p_c1;
*/
return 0;
}