목록C++ (74)
일상 코딩
https://m.blog.naver.com/PostList.naver?blogId=tipsware 지식나눔으로 누구에게나 따뜻한 블로그 : 네이버 블로그 안녕하세요 김성엽입니다. : Do it! C언어 입문의 저자 : Microsoft MVP (2012-) : Tipssoft.com 운영 m.blog.naver.com
#include using namespace std; class Mother { public: int m_i; Mother() : m_i(1) { cout
1. main.cpp #include "Student.h" #include "Teacher.h" using namespace std; int main() { Student std("Jack Jack"); std.setName("Jack Jack 2"); std.getName(); Teacher teacher1("Dr. H"); teacher1.setName("Dr. K"); cout
#include using namespace std; class Mother { private: int m_i; public: Mother(const int & i_in = 0) : m_i(i_in) { cout
1. main.cpp #include "Worker.h" // using namespace std; int main() { Worker().doSomething(); return 0; } 2. Timer.h #pragma once #include #include #include #include #include class Timer { private: using clock_t = std::chrono::high_resolution_clock; using second_t = std::chrono::duration; std::chrono::time_point start_time = clock_t::now(); public: void elapsed() { std::chrono::time_point end_tim..
#include #include #include using namespace std; class Doctor; // forward declaration class Patient { private: string m_name; vector m_doctors; public: Patient(string name_in) : m_name(name_in) { } void addDoctor(Doctor *new_doctor) { m_doctors.push_back(new_doctor); } void meetDoctors(); friend class Doctor; }; class Doctor { private: string m_name; vector m_patients; public: Doctor(string name_..
1. main #include #include #include "Lecture.h" int main() { using namespace std; std::string lec_title1("Introduction to Computer Programming"); std::string lec_title2("Computational Thinking"); Student *std1 = new Student("Jack Jack", 0); Student *std2 = new Student("Dash", 1); Student *std3 = new Student("Violet", 2); Teacher *teacher1 = new Teacher("Prof. Hong"); Teacher *teacher2 = new Teach..
1. main.cpp 최대한 클래스 작동 부분이 안 나타나는게 좋다. 세부적인 구현은 header file에서 전부 구현하고 함수만 쓸 수 있도록 한다. #include "Monster.h" using namespace std; int main() { Monster mon1("Sanson", Position2D(0,0)); // mon1.m_location; cout
#include #include #include using namespace std; class IntArray { private: unsigned m_length = 0; int *m_data = nullptr; // 동적할당 public: IntArray(unsigned length) : m_length(length) { m_data = new int[length]; } // initialize_list 생성자. IntArray(const std::initializer_list &list) : IntArray(list.size()) { int count = 0; for(auto & element : list) { m_data[count] = element; ++count; } // for (unsig..
#include #include using namespace std; class MyString { //private: public: char *m_data = nullptr; int m_length = 0; public: // 문자열 받고 있는 생성자 MyString(const char *source = "") { assert(source); // 문자열 길이 함수 // +1 을 한 이유는 문자열 끝에 문자열 끝을 나타내기 위한 '\0'을 넣기 위함. m_length = std::strlen(source) + 1; // 동적할당 메모리 m_data = new char[m_length]; // 깊은 복사 for (int i = 0; i < m_length; ++i) m_data[i] = source[i]..