목록C++ (45)
printf("ho_tari\n");
#include #include "rational.h" using iot::Rational; int main() { Rational r1; // 0/1 Rational r2 = 1; // 1/1 //Rational r2(1); Rational r3(3, 4); // 3/4 Rational r4 = r3; //r1.setNum(r3.getNum()); //r1.setNum(r3.getNum()); r1 = r3; if (r1 == r3) { std::cout
#include #include "complex.h" using iot::Complex; int main() { Complex c1(3.0, 4.0); // (3.0, 4.0i) Complex c2(3.0); // (3.0, 0.0i) //Complex c2 = 3.0; // implicit conversion good! Complex c3; // (0.0, 0.0i) const Complex c4 = c1; c2 = c1; c2.real(c1.real()); c2.imag(c1.imag()); std::cout
#include #include "complex.h" int main() { Complex c1(3.0, 4.0); // (3.0, 4.0i) Complex c2(3.0); // (3.0, 0.0i) //Complex c2 = 3.0; // implicit conversion good! Complex c3; // (0.0, 0.0i) const Complex c4 = c1; c2 = c1; c2.real(c1.real()); c2.imag(c1.imag()); std::cout
#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
#include #include "shape.h" #include "rectangle.h" #include "circle.h" #include void printArea(const Shape *ps) { std::cout
#include int main(void) { int a = 0x12345678; //int *p; char *p; //p = static_cast(&a); p = reinterpret_cast(&a); printf("*p : 0x%x\n", *p); return 0; }
#include int main(void) { int man, woman; printf("Man: "); scanf("%d", &man); printf("Woman: "); scanf("%d", &woman); double manratio, womanratio; manratio = static_cast(man) / (man + woman) * 100; womanratio = static_cast(woman) / (man + woman) * 100; printf("----------------------------\n"); printf("Ratio of Man : %.2f%%\nRatio of Woman : %.2f%%\n", manratio, womanratio); return 0; }