본문 바로가기
카테고리 없음

C++ 6주차

by sophia02 2021. 10. 12.

#이 글은 인덕대학교 한성현 교수님의 자료를 변형한 자료임을 알립니다

#include <iostream>
using namespace std;
void meet()
{
cout << "반가워";
}
int main()
{
meet();
return 0;
}
#include <iostream>
using namespace std;
void display();
int main()
{
display();
return 0;
}
void display()
{
cout << "안녕";
}
#include <iostream>
using namespace std;
void double_number(double x)
{
cout << x * 2;
}
int main()
{
double_number(3);
return 0;
}
#include <iostream>
using namespace std;
void double_number(double x);
int main()
{
double_number(3);
return 0;
}
void double_number(double x)
{
cout << x * 2;
}
#include <iostream>
using namespace std;
int double_number(double x)
{
return x * 2;
}
int main()
{
int x;
double_number(3);
x = double_number(3);
cout << x << endl; //6
cout << double_number(3) << endl; //6
return 0;
}
#include <iostream>
using namespace std;
int double_number(double x);
int main()
{
cout << double_number(3);
return 0;
}
int double_number(int x)
{
return x * 2;
}
#include <iostream>
using namespace std;
int add(int x, int y)
{
return x + y;
}
int main()
{
int a;
a = add(3, 3);
cout << a;
return 0;
}
#include <iostream>
using namespace std;
int add(int x, int y);
int main()
{
int a;
a = add(3, 3);
cout << a;
return 0;
}
int add(int x, int y)
{
return x + y;
}
#include <iostream>
using namespace std;
char vending(double x)
{
if (x == 1.5) return 'A';
else return 'B';
}
int main()
{
char x;
x = vending(1.5);
cout << x;
return 0;
}
#include <iostream>
using namespace std;
char vending(double x);
int main()
{
char x;
x = vending(1.5);
cout << x;
return 0;
}
char vending(double x)
{
if (x == 1.5) return 'A';
else return 'B';
}
#include <iostream>
using namespace std;
const char* vending(double x)
{
if (x == 1.5) return "코코아";
else return "유자차";
}
int main()
{
cout << vending(1.5);
return 0;
}
#include <iostream>
using namespace std;
char vending(int y)
{
if (y == 2) return 'A';
else return 'B';
}
int main()
{
cout << vending(1);
return 0;
}
#include <iostream>
using namespace std;
const char* vending(int x)
{
if (x == 1) return "코코아";
else return "유자차";
}
int main()
{
cout << vending(2);
return 0;
}
#include <iostream>
#include <string>
using namespace std;
string vending(int x)
{
if (x == 1) return "코코아";
else return "율무차";
}
int main()
{
cout << vending(2);
return 0;
}
#include <iostream>
using namespace std;
class Integer {
private:
int val;
public:
int getVal()
{
return val;
}
void setVal(int ii)
{
val = ii;
}
};
int main()
{
Integer val;
val.setVal(10);
cout << val.getVal() << endl;
}

#include <iostream>

using namespace std;

class Dog {

private:

int age;

 

public:

int getAge();

void setAge(int a);

};

int Dog::getAge()

{

return age;

}

void Dog :: setAge(int a)

{

age = a;

}

int main()

{

Dog happy;

happy.setAge(3);

cout << happy.getAge();

return 0;

}

 

나로 클래스 만들어 보기

#include <iostream>

using namespace std;

class Person {

private:

string name;

int age;

double weight;

public:

string getName()

{

return name;

}

void setName(string a)

{

name = a;

}

int getAge()

{

return age;

}

void setAge(int a)

{

age = a;

}

double getWeight();

void setWeight(double a);

};

 

double Person::getWeight()

{

return weight;

}

void Person::setWeight(double a)

{

weight = a;

}

int main()

{

Person hyo;

hyo.setAge(20);

hyo.setName("hyoeun");

hyo.setWeight(55);

cout << hyo.getAge() << endl;

cout << hyo.getName() << endl;

cout << hyo.getWeight() << endl;

return 0;

}