반응형

문제 3, 4번에 적용되는 2차원 상의 한 점을 표현하는 Point 클래스가 있다.

class Point {
	int x, y;
public:
	Point(int x, int y) { this->x = x; this->y = y; }
	int getX() { return x; }
	int getY() { return y; }
protected:
	void move(int x, int y) {
		this->x = x; this->y = y;
	}
};

 

문제

다음 main() 함수가 실행되도록 Point 클래스를 상속받은 ColorPoint 클래스를 작성하고, 전체 프로그램을 완성하라.

int main() {
	ColorPoint cp(5, 5, "RED");
	cp.setPoint(10, 20);
	cp.setColor("BLUE");
	cp.show();
}

 

결과

BLUE색으로 ( 10, 20 )에 위치한 점입니다.

 

소스코드

#include<iostream>
#include<string>
using namespace std;
class Point {
	int x, y;
public:
	Point(int x, int y) { this->x = x; this->y = y; }
	int getX() { return x; }
	int getY() { return y; }
protected:
	void move(int x, int y) {
		this->x = x; this->y = y;
	}
};
class ColorPoint : public Point {
	string color;
public:
	ColorPoint(int x, int y, string color);
	void setPoint(int x, int y);
	void setColor(string color);
	void show();
};
ColorPoint::ColorPoint(int x, int y, string color) : Point(x, y) {
	this->color = color;
}
void ColorPoint::setPoint(int x, int y)
{
	move(x, y);
}
void ColorPoint::setColor(string color)
{
	this->color = color;
}
void ColorPoint::show() {
	cout << color << "색으로 ( " << getX() << ", " << getY() << " )에 위치한 점입니다." << endl;
}
int main() {
	ColorPoint cp(5, 5, "RED");
	cp.setPoint(10, 20);
	cp.setColor("BLUE");
	cp.show();
}

설명

원칙적으로 파생 클래스의 생성자를 작성할 떄, 기본 클래스의 생성자 중 하나를 선택해야 한다. 하지만 선택하지 않을 경우 컴파일러가 암묵적으로 기본 클래스의 기본 생성자를 호출하도록 컴파일한다. 그러므로 ColorPoint의 생성자를 선언 할 때 : Point(x, y) 을 선언해 주지 않으면 기본 생성자를 호출하려고 하며, Point의 기본생성자가 존재하지 않으므로 컴파일 오류가 난다. 

반응형
반응형

문제 1, 2번에 적용도는 원을 추상화한 Circle 클래스가 있다.

class Circle {
	int radius;
public:
	Circle(int radius = 0) { this->radius = radius; }
	int getRadius() { return radius;}
	void setRadius(int radius) { this->radius = radius; }
	double getArea() { return 3.14 * radius * radius; }
};

 

문제

다음과 같이 배열을 선언하여 다음 실행 결과가 나오도록 Circle을 상속받은 NamedCircle 클래스와 main() 함수 등 필요한 함수를 작성하라.

NamedCircle pizza[5];

 

결과

5 개의 정수 반지름과 원의 이름을 입력하세요

1>> 5 크림피자

2>> 8 치즈피자

3>> 25 대왕피자

4>> 30 블랙홀피자

5>> 15 마늘피자

 

소스코드

#include<iostream>
#include<string>
using namespace std;
class Circle {
	int radius;
public:
	Circle(int radius = 0) { this->radius = radius; }
	int getRadius() { return radius; }
	void setRadius(int radius) { this->radius = radius; }
	double getArea() { return 3.14 * radius * radius; }
};
class NamedCircle : public Circle {
	string name;
public:
	NamedCircle() {};
	string getName() { return name; }
	void setName(string name) { this->name = name; }
};
int main()
{
	NamedCircle pizza[5];
	int r;
	string name;
	int count = 0;
	cout << "5 개의 정수 반지름과 원의 이름을 입력하세요" << endl;
	for (int i = 0; i < 5; i++)
	{
		cout << i + 1 << ">>";
		cin >> r >> name;
		pizza[i].setRadius(r);
		pizza[i].setName(name);
	}
	for (int i = 0; i < 4; i++)
	{
		if (pizza[i].getRadius() < pizza[i + 1].getRadius())
			count = i + 1;
	}
	cout << "가장 면적이 큰 피자는 " << pizza[count].getName() << "입니다." << endl;
}

설명

Circle과 같은 원리인 함수 NamedCircle클래스에 선언해 준 후 Circle의 멤버 함수와 NamedCircle의 멤버 함수를 이용하여 값들을 저장하고 반지름의 크기만 비교하여 가장 큰 곳의 인덱스를 기억하여 출력한다.

반응형
반응형

문제 1, 2번에 적용도는 원을 추상화한 Circle 클래스가 있다.

class Circle {
	int radius;
public:
	Circle(int radius = 0) { this->radius = radius; }
	int getRadius() { return radius;}
	void setRadius(int radius) { this->radius = radius; }
	double getArea() { return 3.14 * radius * radius; }
};

 

문제

다음 코드가 실행되도록 Circle을 상속받는 NamedCircle 클래스를 작성하고 전체 프로그램을 완성하라.

int main()
{
	NamedCircle waffle(3, "waffle"); //반지름이 3이고 이름이 waffle인 원
	waffle.show();
}

 

결과

반지름이 3인 waffle

 

소스코드

#include<iostream>
#include<string>
using namespace std;
class Circle {
	int radius;
public:
	Circle(int radius = 0) { this->radius = radius; }
	int getRadius() { return radius;}
	void setRadius(int radius) { this->radius = radius; }
	double getArea() { return 3.14 * radius * radius; }
};
class NamedCircle : public Circle {
	string name;
public:
	NamedCircle(int r, string name);
	void show();
};
NamedCircle::NamedCircle(int r, string name)
{
	setRadius(r);
	this->name = name;
}
void NamedCircle::show()
{
	cout << "반지름이 " << getRadius() << "인 " << name << endl;
}
int main()
{
	NamedCircle waffle(3, "waffle"); //반지름이 3이고 이름이 waffle인 원
	waffle.show();
}

설명

Circle을 상속받으므로 Circle에 존재하는 반지름 설정함수 setRadius(), 반지름 출력함수 getRadius()을 사용할 수 있다.

반응형
반응형

바로 그제 2021 05 19 암호화폐 하락장 중 저녁쯤에 대 폭락이 뜨면서 난리가 났었죠.

4월부터 각종 악재 속에 계속된 하락을 보여주면서 어제 새로운 저점을 보여주었습니다.

하지막 금방 회복하면서 현재 업비트 기준 5000 초반에서 4900후반대를 보여주고 바이낸스 기준 4400 후반을 보여주고 있네요.

 

하지만!

알트코인들은 그대로 회복도 못하고 사망했죠...(저도 알트..)

그래서인지 메이저 코인기반 비트코인, 이더리움, 클레이튼 으로 만들어진 코인들이 각광 받고 있습니다.

그 중 클레이튼 기반으로 만들어진 CowCow코인을 알아볼까 합니다.

 

일단 어제 핫빗 코리아에 상장되었는데..

24시간 고가 140.0 저가 20.2 현재가 50.1 거래량 530만 총발행량 2,000,000,000 Cow

역시 처음 상장되서 그런지 변동폭이 심하네요...

20원대에 들어갔으면..ㅎㅎ

하지만 다른 코인과 똑같이 처음 상장되서 아마 계속 하락세를 보일 듯 합니다.

그래도 장기로 본다면 최근에 저점을 찍고 온거 보면 상승 할지도...

 

또, 이 코인은 채굴도 가능합니다!

솔직히 요즘 스캠사기도 많고 불안하기도 했지만...

시스템 관리도 하고 다운로드 수도 많고 하는 거 보니 살짝 안심이 되기도 합니다.

 

https://play.google.com/store/apps/details?id=site.cowcow 추천인 코드 : 3KEDWT

 

CowCow | 카우카우 Crypto Mining - Google Play 앱

귀여운 COW와 함께 즐거운 블록체인 마이닝을 시작하세요. 카우카우 공지는 트위터로 확인하세요.

play.google.com

구글로만 로그인이 가능합니다!

 

게임화면

귀엽습니다.. ㅎㅎ

저는 컴퓨터로 다운받아서 그냥 켜놓고 다른거 합니다.

시간날때마다 보고...

오늘 시작했는데 다른코인에 비해 빠르긴하네요.

  

여물받기도 광고를 보면 하나씩 줍니다.

(1분의 지연시간 있습니다.)

여물로 캐셔야지 두배줍니다!!

 

여물로 보너스 게임도 가능 한데

도박입니다.

저는 5원까지 나와봤네요.. ㅎㅎ

나머지는 다 0.몇원대...

 

하루에 Level 1 기준 500,000 Cow 채굴 가능하며 누적된 창출의 채굴수가 일 정량 도달하면

Level이 상승된다고 하네요.

공급 제한 => 가치 상승

을 유도하는 것 같네요.

 

게임내에서 사용된다고 하는 Cow코인 가상농장 게임이라고 하는데

요즘 롤, 피파, 오버워치, 서든, 배그 등

대표적인 게임 제외하고 성공하는 게임들이 별로 보이지 않는 것 같아요.

너무 오래된 게임들인데...

 

그래서 많은 가상게임들이 준비 중인 것 같습니다. 

성공사례로는 포켓몬 고가 있죠.

 

사실상 게임이 성공해야 그 곳에서 쓰이는 코인이 대박납니다.

 

그나마 회복장인 지금 다들 성투하시길 바랍니다.

 

핫빗코리아 링크 입니다. https://www.hotbit.co.kr/

 

핫빗코리아

비트코인, 이더리움, 비트코인캐시, 리플, 이오스, 앞서가는 디지털 자산 거래소

www.hotbit.co.kr

 

반응형

'암호화폐' 카테고리의 다른 글

아모(AMO)코인 아모랩스(AMO Laps)  (0) 2021.05.24
클레이튼(Klaytn) 코인  (0) 2021.05.24
반응형

문제

정수 배열을 항상 증가 순으로 유지하는 SortedArray 클래스를 작성하려고 한다. 아래의 main() 함수가 작동할 만큼만 SortedArray 클래스를 작성하고 +와 = 연산자도 작성하라

class SortedArray {
	int size; //현재 배열의 크기
	int* p;
	void sort();
public:
	SortedArray(); //p는 NULL로 size는 0으로 초기화
	SortedArray(SortedArray& src); //복사 생성자
	SortedArray(int p[], int size); //생성자, 정수 배열과 크기를 전달받음
	~SortedArray(); //소멸자
	SortedArray operator +(SortedArray& op2); //현재 배열에 op2 배열 추가
	SortedArray& operator = (const SortedArray& op2); //현재 배열에 op2 배열 복사
	void show(); //배열의 원소 출력
};

int main()
{
	int n[] = { 2,20,6 };
	int m[] = { 10,7,8,30 };
	SortedArray a(n, 3), b(m, 4), c;

	c = a + b; // +, = 연산자 작성 필요
	// + 연산자가 SortedArray 객체를 리턴하므로 복사 생성자 필요

	a.show();
	b.show();
	c.show();
}

 

결과

배열 출력 : 2 6 20

배열 출력 : 7 8 10 30

배열 출력 : 2 6 7 8 10 20 30

 

소스코드

#include<iostream>
using namespace std;
class SortedArray {
	int size; //현재 배열의 크기
	int* p;
	void sort();
public:
	SortedArray(); //p는 NULL로 size는 0으로 초기화
	SortedArray(SortedArray& src); //복사 생성자
	SortedArray(int p[], int size); //생성자, 정수 배열과 크기를 전달받음
	~SortedArray(); //소멸자
	SortedArray operator +(SortedArray& op2); //현재 배열에 op2 배열 추가
	SortedArray& operator = (const SortedArray& op2); //현재 배열에 op2 배열 복사
	void show(); //배열의 원소 출력
};
void SortedArray::sort() //정렬함수
{
	int temp;
	for (int i = 0; i < this->size - 1; i++)
	{
		for (int j = i + 1; j < this->size; j++)
		{
			if (p[i] > p[j]) {
				temp = p[i];
				p[i] = p[j];
				p[j] = temp;
			}
		}
	}
}
SortedArray::SortedArray() //생성자
{
	p = nullptr;
	size = 0;
}
SortedArray::SortedArray(SortedArray& src) //복사생성자
{
	this->size = src.size;
	this->p = new int[this->size];
	for (int i = 0; i < this->size; i++)
		this->p[i] = src.p[i];
}
SortedArray::SortedArray(int p[], int size) //매개변수 생성자
{
	this->size = size;
	this->p = new int[size];
	for (int i = 0; i < size; i++)
		this->p[i] = p[i];
}
SortedArray::~SortedArray() //소멸자
{
	delete[] p;
}
SortedArray SortedArray::operator+(SortedArray& op2)
{
	SortedArray op3;
	op3.size = this->size + op2.size;
	op3.p = new int[op3.size];
	for (int i = 0; i < op3.size; i++)
	{
		if (i < this->size)
			op3.p[i] = this->p[i];
		else
			op3.p[i] = op2.p[i - this->size];
	}
	return op3;
}
SortedArray& SortedArray::operator=(const SortedArray& op2)
{
	this->size = op2.size;
	this->p = new int[this->size];
	for (int i = 0; i < this->size; i++)
	{
		this->p[i] = op2.p[i];
	}
	return *this;
}
void SortedArray::show()
{
	this->sort(); //정렬
	cout << "배열 출력 : ";
	for (int i = 0; i < this->size; i++)
		cout << this->p[i] << ' ';
	cout << endl;
}
int main()
{
	int n[] = { 2,20,6 };
	int m[] = { 10,7,8,30 };
	SortedArray a(n, 3), b(m, 4), c;

	c = a + b; // +, = 연산자 작성 필요
	// + 연산자가 SortedArray 객체를 리턴하므로 복사 생성자 필요

	a.show();
	b.show();
	c.show();
}
반응형
반응형

문제

스택 클래스 Stack을 만들고 푸시(push)용으로 << 연산자를, 팝(pop)을 위해 >> 연산자를, 비어 있는 스택인지를 알기 위해 ! 연산자를 작성하라. 다음 코드를 main()으로 작성하라.

int main()
{
	Stack stack;
	stack << 3 << 5 << 10; // 3, 5, 10을 순서대로 푸시
	while (true) {
		if (!stack)break; // 스택 empty
		int x;
		stack >> x; // 스택의 탑에 있는 정수 팝
		cout << x << ' ';
	}
	cout << endl;
}

 

결과

10 5 3

 

스택이란?

스택은 자료구조 중에 하나로서, 후입선출(LIFO : Last-In First-Out)구조이다. 데이터가 들어간 순서의 역순이 나오는 순서이다.

하나의 스택 스택 입력(B) 스택 입력(C) 스택 삭제(C)
    C  
  B B B
A A A A

 

 

소스코드(friend 함수 구현)

#include<iostream>
using namespace std;
class Stack {
	int stack[10];
	int top;
public:
	Stack() { top = -1; }
	friend bool operator!(Stack& sta);
	friend Stack& operator<<(Stack& sta, int n);
	friend void operator>>(Stack& sta, int& n);
};
bool operator!(Stack& sta)
{
	if (sta.top == -1)
		return true;
	return false;
}
Stack& operator<<(Stack& sta, int n)
{
	sta.stack[++sta.top] = n;
	return sta;
}
void operator>>(Stack& sta, int& n)
{
	n = sta.stack[sta.top--];
}
int main()
{
	Stack stack;
	stack << 3 << 5 << 10; // 3, 5, 10을 순서대로 푸시
	while (true) {
		if (!stack)break; // 스택 empty
		int x;
		stack >> x; // 스택의 탑에 있는 정수 팝
		cout << x << ' ';
	}
	cout << endl;
}

 

 

반응형
반응형

문제

통계를 내는 Statistics 클래스를 만들려고 한다. 데이터는 Statistics 클래스 내부에 int 배열을 동적으로 할당받아 유지한다. 다음과 같은 연산이 잘 이루어지도록 Statistics 클래스와 !, >>, <<, ~연산자 함수를 작성하라.

int main()
{
	Statistics stat;
	if (!stat) cout << "현재 통계 데이타가 없습니다." << endl;

	int x[5];
	cout << "5 개의 정수를 입력하라>>";
	for (int i = 0; i < 5; i++)cin >> x[i];

	for (int i = 0; i < 5; i++)stat << x[i];
	stat << 100 << 200;
	~stat;

	int avg;
	stat >> avg;
	cout << "avg=" << avg << endl;
}

결과

현재 통계 데이타가 없습니다.

5 개의 정수를 입력하라 >> 1 2 3 4 5

1 2 3 4 5 100 200

avg=45

 

소스코드

#include<iostream>
using namespace std;
class Statistics {
	int* a;
	int size=0;
public:
	Statistics() { a = new int[10]; size = 0; }
	friend bool operator!(Statistics& stat);
	friend Statistics& operator<<(Statistics& stat,int x);
	friend void operator>>(Statistics& stat,int& avg);
	friend void operator~(Statistics& stat);
	~Statistics() { delete[]a; }
};
bool operator!(Statistics& stat)
{
	if (stat.size == 0) return true;
	return false;
}
Statistics& operator<<(Statistics& stat,int x)
{
	stat.a[stat.size++] = x;
	return stat;
}
void operator>>(Statistics& stat,int& avg)
{
	avg = 0;
	for (int i = 0; i < stat.size; i++)
		avg += stat.a[i];
	avg /= stat.size;
}
void operator~(Statistics& stat)
{
	for (int i = 0; i < stat.size; i++)
		cout << stat.a[i] << ' ';
	cout << endl;
}
int main()
{
	Statistics stat;
	if (!stat) cout << "현재 통계 데이타가 없습니다." << endl;

	int x[5];
	cout << "5 개의 정수를 입력하라>>";
	for (int i = 0; i < 5; i++)cin >> x[i];

	for (int i = 0; i < 5; i++)stat << x[i];
	stat << 100 << 200;
	~stat;

	int avg;
	stat >> avg;
	cout << "avg=" << avg << endl;
}
반응형
반응형

문제

문제 7번의 Circle 객체에 대해 다음 연산이 가능하도록 연산자를 구현하라. 

int main()
{
	Circle a(5), b(4);
	b = 1 + a;
	a.show();
	b.show();
}

 

결과

radius = 5 인 원

radius = 6 인 원

 

소스코드(friend 함수 구현)

#include<iostream>
using namespace std;
class Circle {
	int radius;
public:
	Circle(int radius = 0) { this->radius = radius; }
	void show() { cout << "radius = " << radius << " 인 원" << endl; }
	friend Circle operator+(int n,Circle a);
};
Circle operator+(int n, Circle a)
{
	a.radius += n;
	return a;
}

int main()
{
	Circle a(5), b(4);
	b = 1 + a;
	a.show();
	b.show();
}

 

 

반응형
반응형

문제

원을 추상화한 Circle 클래스는 간단히 아래와 같다.

class Circle {
	int radius;
public:
	Circle(int radius = 0) { this->radius = radius; }
	void show() { cout << "radius = " << radius << " 인 원" << endl; }
};

 

다음 연산이 가능하도록 연산자를 프렌드 함수로 작성하라

int main()
{
	Circle a(5), b(4);
	++a;
	b = a++;
	a.show();
	b.show();
}

 

결과

radius = 7 인 원

radius = 6 인 원

 

소스코드

#include<iostream>
using namespace std;
class Circle {
	int radius;
public:
	Circle(int radius = 0) { this->radius = radius; }
	void show() { cout << "radius = " << radius << " 인 원" << endl; }
	friend void operator++(Circle& a);
	friend Circle& operator++(Circle& a, int b);
};

void operator++(Circle& a)
{
	++a.radius;
}
Circle& operator++(Circle& a,int b)
{
	Circle temp = a;
	a.radius++;
	return temp;
}
int main()
{
	Circle a(5), b(4);
	++a;
	b = a++;
	a.show();
	b.show();
}

설명 : 전위, 후위 연산자 모두 참조 매개변수를 사용한다. 전위 연산자인 ++a 의 경우 리턴 값이 필요없으므로 참조매개변수로 a.radius값을 1증가시킨다. 후위 연산자인 경우 매개 변수를 가지도록 선언이 되며, 후위 연산자는 그 줄의 코드가 실행된 후 증가를 시키기 때문에 참조매개변수를 이용해 a.radius의 값은 증가시켜주지만 temp의 이전의 상태를 삽입하여 리턴한다. 이 때 매개변수는 사용되지 않으므로 무시해도 된다. 단지, 전위인지 후위인지 구분하는 매개 변수이다. 

 

오류 또는 수정 사항 궁금한 점 있으시면 댓글로 남겨주세요.

반응형
반응형

문제

2차원 행렬을 추상화한 Matrix 클래스를 활용하는 다음 코드가 있다.

int main()
{
	Matrix a(4, 3, 2, 1), b;
	int x[4], y[4] = { 1,2,3,4 };
	a >> x;
	b << y;
	for (int i = 0; i < 4; i++)cout << x[i] << ' ';
	cout << endl;
	b.show();
}

 

결과

4 3 2 1

Matrix = { 1 2 3 4 }

 

1. <<, >> 연사자 함수를 Matrix 멤버 함수로 구현하라.

#include<iostream>
using namespace std;

class Matrix {
	int a[4];
public:
	Matrix() {};
	Matrix(int a, int b, int c, int d) {
		this->a[0] = a;
		this->a[1] = b;
		this->a[2] = c;
		this->a[3] = d;
	}
	void show();
	void operator>>(int x[]);
	void operator<<(int y[]);
};
void Matrix::show()
{
	cout << "Matrix = { " << a[0] << ' ' << a[1] << ' ' << a[2] << ' ' << a[3] << " }" << endl;
}
void Matrix::operator>>(int x[])
{
for(int i =0;i<4;i++)
	x[i] = a[i];
}
void Matrix::operator<<(int y[])
{
for(int i= 0 ;i<4;i++)
	a[i] = y[i];
}
int main()
{
	Matrix a(4, 3, 2, 1), b;
	int x[4], y[4] = { 1,2,3,4 };
	a >> x;
	b << y;
	for (int i = 0; i < 4; i++)cout << x[i] << ' ';
	cout << endl;
	b.show();
}

 

2. <<, >> 연산자 함수를 Matrix의 프렌드 함수로 구현하라.

#include<iostream>
using namespace std;

class Matrix {
	int a[4];
public:
	Matrix() {};
	Matrix(int a, int b, int c, int d) {
		this->a[0] = a;
		this->a[1] = b;
		this->a[2] = c;
		this->a[3] = d;
	}
	void show();
	friend void operator>>(Matrix a, int x[]);
	friend void operator<<(Matrix& b,int y[]);
};
void Matrix::show()
{
	cout << "Matrix = { " << a[0] << ' ' << a[1] << ' ' << a[2] << ' ' << a[3] << " }" << endl;
}
void operator>>(Matrix a,int x[])
{
	for (int i = 0; i < 4; i++)
		x[i] = a.a[i];
}
void operator<<(Matrix& b, int y[])
{
	for (int i = 0; i < 4; i++)
		b.a[i] = y[i];
}
int main()
{
	Matrix a(4, 3, 2, 1), b;
	int x[4], y[4] = { 1,2,3,4 };
	a >> x;
	b << y;
	for (int i = 0; i < 4; i++)cout << x[i] << ' ';
	cout << endl;
	b.show();
}

 

오류 또는 수정 사항 궁금한 점 있으시면 댓글로 남겨주세요.

반응형

+ Recent posts