목록C++ (74)
일상 코딩
#include #include using namespace std; class Student { private: int m_id; string m_name; public: Student(const string& name_in) // : m_id(0) 이렇게 중구난방으로 초기화하기 보다는 아래 생성자를 갖다 쓴다. // , m_name(name_in) // : Student(0,name_in) { init(0,name_in); } Student(const int& id_in, const string& name_in) // : m_id(id_in) // , m_name(name_in) { init(id_in,name_in); } // 만능 초기화 함수를 생성 후 생성자에서 직접 초기화하지 않고 초기화 함수..
#include using namespace std; class B { private: int m_b; public: B(const int& m_b_in) : m_b(m_b_in) {} }; class Something { private: int m_i = 100; double m_d = 100.0; char m_c = 'F'; int m_arr[5] = {100, 200, 300, 400, 500}; B m_b{ 1024 }; // 여기서 초기화를 하더라도 생성자가 우선이라 생성자에서 대입한 값으로 출력됨. public: Something() // '{}'를 쓰면 자동으로 형변환이 안되어 좀 더 엄격해진다. : m_i{1}, m_d{3.14}, m_c{'a'}, m_arr{1,2,3,4,5}, m_b(..
https://www.cplusplus.com/ cplusplus.com - The C++ Resources Network www.cplusplus.com 쓰고 싶은 라이브러리가 있다면 검색해서 사용하면 된다.
#include using namespace std; class Fraction { private: int m_numerator; int m_denominator; public: Fraction(const int& num_in = 1, const int& den_in = 1) // 생성자, 외부 호출 아님. { m_numerator = num_in; m_denominator = den_in; cout
#include #include #include using namespace std; class Date { // 기본이 private으로 설정되어있음. 안적어도 무방함. private: // access specifier int m_month; int m_day; int m_year; public: void setDate(const int& day_input, const int& year_input) { m_day = day_input; m_year = year_input; } void setMonth(const int& month_input) { m_month = month_input; } const int& getDay() // const로 수정을 막아준다. { return m_day; } void..
#include #include #include using namespace std; // Object(객체) - 코드로 구현한 단어를 class라 부른다. // class Friend{ //sturct는 아 코드가 안들감. public: // access specifier (public, private, protected(상속 단원)) string m_name; string m_address; int m_age; double m_height; double m_weight; void print(){ cout
#include using namespace std; // int main(){ // freopen("./06_extract_number/input.txt","rt",stdin); int main(int argc, char* argv[]){ freopen(argv[1], "rt", stdin); freopen(argv[2], "w", stdout); char a[100]; int res = 0, cnt = 0, i; cin >> a; for(i=0; a[i] != '\0';i++){ if(a[i] >= 48 && a[i]
#include using namespace std; int main(){ freopen("./05_age_calcul/input.txt","rt",stdin); // 채점 프로그램 돌릴때 사용(mac 사용자 기준) // int main(int argc, char* argv[]){ // freopen(argv[1], "rt", stdin); // freopen(argv[2], "w", stdout); int age,year; char cnum[20],sex; // 주민등록번호 저장 cin >> cnum; if(cnum[7] == '1' || cnum[7] == '2'){ year = 1900 + ((cnum[0]-48)*10+(cnum[1]-48));} else{ year = 2000 + ((cnum[0..
1.출처 https://www.inflearn.com/questions/322413 맥북(mac os) 자동 채점 방법을 고민해보았습니다. - 인프런 | 질문 & 답변 출력값이 긴 파일은 하나씩 눈으로 보고 체크하기가 어려워서 방법을 찾아보았습니다. 별다른 설치 파일 필요 없이 그냥 리눅스 명령어로 만들어진 쉘 스크립트만 생성해주면 되므로 간단합니 www.inflearn.com 2. 쉘 스크립트 생성 #!/bin/bash g++ code.cpp -o code "./code" "./test/in1.txt" "./test/result1.txt" "./code" "./test/in2.txt" "./test/result2.txt" "./code" "./test/in3.txt" "./test/result3.txt..
#include using namespace std; int main(){ // input.txt 파일로 데이터를 받는다. freopen("input.txt", "rt", stdin); int N, i, age, max = -2147000000, min = 2147000000; cin >> N; for(i = 0; i > age; if( age > max){ max = age;} if( age < min){ min = age;} } cout