This commit is contained in:
2025-06-23 21:09:25 +09:00
commit 32cd5b9be8
50 changed files with 59220 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
#include <iostream>
class Animal
{
private:
int food;
int weight;
public:
void setAnimal(int _food, int _weight)
{
food = _food;
weight = _weight;
}
void increaseFood(int inc)
{
food += inc;
weight += inc / 3;
}
void viewStat()
{
std::cout << "이 동물의 Food : " << food << std::endl;
std::cout << "이 동물의 Weight : " << weight << std::endl;
}
};
int main()
{
Animal animal;
animal.setAnimal(100, 50);
animal.increaseFood(30);
animal.viewStat();
return 0;
}

View File

@@ -0,0 +1,56 @@
#include <string>
#include <iostream>
class Test
{
std::string str;
public:
Test(std::string _str)
{
str = _str;
std::cout << "생성자 호출! " << str << std::endl;
}
~Test()
{
std::cout << "소멸자 호출! " << str << std::endl;
}
};
class Foo
{
int number;
public:
Foo(int inp) : number(inp) {}
int& accessNumber() { return number; }
int getNumber() { return number; }
void showNumber() { std::cout << number << std::endl; }
};
void simpleFunction()
{
Test B("B Class");
}
int main()
{
// Test A("A Class");
// simpleFunction();
Foo a(5);
a.showNumber();
int& c = a.accessNumber();
c = 4;
a.showNumber();
int d = a.accessNumber();
d = 3;
a.showNumber();
int f = a.getNumber();
f = 1;
a.showNumber();
}

View File

@@ -0,0 +1,31 @@
#include <iostream>
class A {
int x;
public:
A(int c) : x(c) {}
A(const A &a) {
x = a.x;
std::cout << "복사 생성" << std::endl;
}
};
class B {
A a;
public:
B(int c) : a(c) {}
B(const B &b) : a(b.a) {}
A get_A() {
A temp(a);
return temp;
}
};
int main() {
B b(10);
std::cout << "---------" << std::endl;
A a1 = b.get_A();
}

View File

@@ -0,0 +1,80 @@
#include <iostream>
class Date
{
private:
int year_, month_, day_;
int getMonthsMaxDay(int year, int month)
{
int months[12] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (month == 2)
{
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
months[1] = 29;
else months[1] = 28;
}
return months[month - 1];
}
public:
Date();
Date(int year, int month, int day);
void addDay(int inc);
void addMonth(int inc);
void addYear(int inc);
void showDate();
};
Date::Date()
: year_(2004), month_(01), day_(01) {}
Date::Date(int year, int month, int day)
: year_(year), month_(month), day_(day) {}
void Date::addDay(int inc)
{
day_ += inc;
for (; day_ > getMonthsMaxDay(year_, month_);)
{
day_ -= getMonthsMaxDay(year_, month_);
addMonth(1);
}
}
void Date::addMonth(int inc)
{
month_ += inc;
for (; month_ > 12;)
{
month_ -= 12;
addYear(1);
}
}
void Date::addYear(int inc)
{
year_ += inc;
}
void Date::showDate()
{
if (month_ < 10 && day_ < 10)
std::cout << "Now Date() : " << year_ << "-0" << month_ << "-0" << day_ << std::endl;
else if (month_ < 10 && day_ > 9)
std::cout << "Now Date() : " << year_ << "-0" << month_ << "-" << day_ << std::endl;
else if (month_ > 9 && day_ < 10)
std::cout << "Now Date() : " << year_ << "-" << month_ << "-0" << day_ << std::endl;
else
std::cout << "Now Date() : " << year_ << "-" << month_ << "-" << day_ << std::endl;
}
int main()
{
Date date(2020, 10, 10);
date.showDate();
}

View File

@@ -0,0 +1,15 @@
#include <iostream>
namespace header1
{
int foo()
{
std::cout << "This is H1 - foo()" << std::endl;
return 0;
}
void bar()
{
std::cout << "This is H1 - bar()" << std::endl;
}
}

View File

@@ -0,0 +1,15 @@
#include <iostream>
namespace header2
{
int foo()
{
std::cout << "This is H2 - foo()" << std::endl;
return 0;
}
void bar()
{
std::cout << "This is H2 - bar()" << std::endl;
}
}

View File

@@ -0,0 +1,62 @@
#include <cstdio>
class legend
{
private:
/* data */
public:
legend();
~legend();
void q1();
void q2();
};
legend::legend()
{
printf("default create function call\n");
}
legend::~legend()
{
printf("default delete function call");
}
// 1번 문제
void legend::q1()
{
for (int i = 4; i >= 0; --i)
{
for (int j = 0; j < i; ++j)
{
printf(" ");
}
for (int k = 0; k < 9 - (i * 2); ++k)
{
printf("*");
}
printf("\n");
}
printf(" ||| \n");
}
// 2번 문제
void legend::q2()
{
double scoreAvg;
printf("이번 학기에 받고 싶은 전과목 평균 점수가 무엇인고?\n");
scanf("%lf", &scoreAvg);
printf("너의 이번 학기 전과목 평균 점수는 %.1lf점이 될 것이니라~\n", scoreAvg);
}
int main()
{
legend legeno;
legeno.q1();
legeno.q2();
}

View File

@@ -0,0 +1,11 @@
#include <iostream>
#include "header1.h"
#include "header2.h"
using namespace header1;
int main()
{
foo();
header2::foo();
}