목록C++ (45)
printf("ho_tari\n");
#include #include "employee.h" int main() { //Employee e; //Employee e = e1; //e = e1; //Employee employee[5]; Employee *pEmployees[5]; pEmployees[0] = new Employee(1, "hotari", 0); pEmployees[1] = new Employee(2, "c++", pEmployees[0]); pEmployees[2] = new Employee(3, "python", pEmployees[0]); pEmployees[3] = new Employee(4, "matlab", pEmployees[2]); pEmployees[4] = new Employee(5, "arduino", pE..
#include #include "complex.h" #include int main() { Complex c1; Complex c2 = 3.0; // Complex c2(3.0) Complex c3(3.0, 4.0); const Complex c4 = c3; // const Complex c4(c3) c1.real(c3.real()); c1.imag(c3.imag()); c1 = c3; if (c1 == c3) { std::cout
#include #include "rational.h" int main() { Rational r1; // 0 Rational r2(3); // 3/1 Rational r3(3,4); // 3/4 std::cout den * rhs.num; int den1 = this->den * rhs.den; int gcd = GCD(num1,den1); return Rational(num1/gcd,den1/gcd); } Rational Rational::operator-(const Rational &rhs) { int num1 = this->num * rhs.den - this->den * rhs.num; int den1 = this->den * rhs.den; int gcd = GCD(num1,den1); ret..
#include #include "rational.h" int main() { Rational r1(3,4); Rational r2(3); Rational r3; r3 = r1; if (r1 == r3) { std::cout den * rhs.den); result.num = (this->num * rhs.den - rhs.num * this->den)/gcd; result.den = (this->den * rhs.den)/gcd; return result; } Rational Rational::operator*(const Rational &rhs) { Rational result(this->num * rhs.num,this->den * rhs.den); int gcd = GCD(this->num * r..
#include #include "complex.h" int main() { Complex c1(3.0,4.0); // 3.0 + 4.0i Complex c2(3.0); // 3.0 + 0i Complex c3; // 0 + 0i //c3.real(c1.real()); //c3.imag(c1.imag()); c3 = c1; c2 = c1-c3; if (c1 == c3) { std::cout real()-rhs.re, this->imag()-rhs.im); return result; }
#include #include "complex.h" int main() { Complex c1(3.0,4.0); // 3.0 + 4.0i Complex c2(3.0); // 3.0 + 0i Complex c3; // 0 + 0i c3.real(c1.real()); c3.imag(c1.imag()); std::cout
#include #include "empty.h" int main() { Empty e1; const Empty e2 = e1; e1 = e2; Empty *p1 = &e1; // e1.operator&() const Empty *p2 = &e2; // e2.operator&() return 0; } #ifndef EMPTY_H #define EMPTY_H class Empty { public: //Empty() { } //Empty(const Empty& rhs) { /* memberwise copy */ } //~Empty() { } //Empty& operator=(const Empty& rhs) { /* memberwise copy */ } //Empty *operator&() { return t..
#include #include "string.h" int main() { String s1; String s2 = "hello, world"; // String s2("hello, world"); //String s2 = 0; String s3 = s2; // String s3(s2); s1 = s2; // s1 = s1; // self assignment?? s1 = "hello, "; // String tmp("hello, "); s1 = tmp; tmp.~String(); String s4 = " IoT"; s1 = s2 + s4; if (s1 == s2) { std::cout str, rhs.str) == 0; } bool String::operator!=(const String& rhs) co..