<code>

 

#include <iostream>
#include <string>
using namespace std;
class Circle
{
int radius;
public:
Circle(int r) { radius = r; };
int getRadius() { return radius; }
void setRadius(int r) { radius = r; }
void show() { cout << "반지름이 " << radius << "인 원" << endl; }
};
void increaseBy(Circle& a, Circle& b) {
int r = a.getRadius() + b.getRadius();
a.setRadius(r);
}
int main()
{
Circle x(10), y(5);
increaseBy(x, y);
x.show();
}
view raw cp5_5.cpp hosted with ❤ by GitHub

 

<code>

 

#include <iostream>
#include <string>
using namespace std;
bool bigger(int a, int b, int& big) {
if (a == b) return true;
else {
if (a > b)
big = a;
else
big = b;
return false;
}
}
int main() {
int a, b, big;
cin >> a >> b;
bigger(a, b, big);
cout << big;
}
view raw cp5_4.cpp hosted with ❤ by GitHub

 

<code>

 

#include <iostream>
#include <string>
using namespace std;
string combine(string& a, string& b, string& c)
{
c = a +" "+ b; //문자열 중간에 공백을 주기 위해 띄어쓰기 설정도 해줌
return c;
}
int main() {
string text1("I love you"), text2("very much");
string text3;
combine(text1, text2, text3);
cout << text3;
}
view raw cp5_3.cpp hosted with ❤ by GitHub

<code>

#include <iostream>
#include <string>
using namespace std;
double half(double &n) // 참조연산자로 값을 받아와야함
{
n = n / 2;
return n;
}
int main() {
double n = 30;
half(n);
cout << n;
}
view raw cp5_2.cpp hosted with ❤ by GitHub

<문제>

두 개의 Circle 객체를 교환하는 swap() 함수를 '참조에 의한 호출, 이 되도록 작성 하고 호출하는 프로그램을 작성하라.

 

 

<code>

 

#include <iostream>
#include <string>
using namespace std;
class Circle
{
int radius;
public:
Circle() { radius = 1; };
Circle(int radius) { this->radius = radius; }
void setRadius(int radius) { this->radius = radius; }
double getArea() { return 3.14 * radius * radius; }
double getRadius() { return radius; }
void swap(Circle& a, Circle& b);
};
void Circle::swap(Circle& a, Circle& b)
{
Circle tmp;
tmp = a;
a = b;
b = tmp;
}
int main() {
Circle a, b(10);
cout << "a의 반지름 : " << a.getRadius() << " b의 반지름 : " << b.getRadius() << endl;
cout << "swap 후 >>"<<endl;
swap(a, b);
cout << "a의 반지름 : " << a.getRadius() << " b의 반지름 : " << b.getRadius() << endl;
}
view raw cp5_1.cpp hosted with ❤ by GitHub

 

 

 

업데이트 하지 않은 라즈베리 파이의 파이썬 버전은 2.*.. 버전이거나 3.* 버전이기에 최신 버전으로 업그레이드 해야한다. 

 

방법은 아래와 같다. 

 

 

Opencv 4.x 를 python3 설치 과정

 

1.

sudo pip3 install opencv-contrib-python

2

sudo apt install libqt4-test libhdf5-dev libatlas-base-dev libjasper-dev libqtgui4

3

sudo apt-get update

4.

wget https://github.com/dltpdn/opencv-for-rpi/releases/download/4.2.0_buster_pi3b/opencv4.2.0.deb.tar

5.

tar -xvf opencv4.2.0.deb.tar

6.

sudo apt-get install -y ./OpenCV*.deb

7.

pkg-config --modversion opencv4

8.

python3

>>import cv2

>>print(cv2.__version__)

아래와 같이 결과가 나오면 정상적으로 설치되었음을 확인할 수 있다.

 

 

 

'openCV' 카테고리의 다른 글

opencv c++ 특정 객체의 위치를 구하는 방법  (0) 2020.06.24
histogram 히스토그램 평준화  (0) 2020.06.23

 

 

<code>

 

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
class Player
{
string name;
public:
Player() { name = " "; };
~Player() {};
void setName(string name) { this->name = name; }
string getName() { return name; }
};
class GamblingGame
{
Player* p;
string name;
public:
GamblingGame() {
p = new Player[2]; //클래스 동적 생성
srand((unsigned)time(0)); //랜덤하게 숫자 생성 코드
cout << "**** 갬블링 게임을 시작합니다. ****" << endl;
};
~GamblingGame() { delete[]p; }; //동적 생성 해제
void setPlayer() {
cout << "첫번째 선수 이름>>";
cin >> name;
p[0].setName(name);
cout << "두번째 선수 이름>>";
cin >> name;
p[1].setName(name);
} //멤버 입력 함수
string rand_num (string n) {
int r[3]; //숫자 배열 생성
cout << "\t\t";
for (int i = 0; i < 3; i++) {
r[i] = rand() % 3; //랜덤하게 생성된 숫자를 3으로 나누면 나머지 숫자는 0,1,2가 됨
cout << r[i] << '\t';
}
if (r[0] == r[1] &&r[0]==r[2]) {
n += "님 승리!!";
return n;
} //숫자 3개가 동일하다면 게임의 승리
else
return "아쉽군요!";
}
void game_start() {
string n;
int i = 0;
while (true)
{
string m;
cout << p[i % 2].getName() << ":\n"; //플레이어도 i를 2로 나눈 나머지는 0,1밖에 없으니 이런 식으로 표현
getline(cin, n); //엔터값 입력받는 함수
m = p[i % 2].getName(); //이름 받는 스트링 함수
n = rand_num(n); //랜덤 숫자 받는 함수
if (n == "님 승리!!") {
cout << m + n;
break;
}
else
cout << n << endl;
i++; //플레이어 나타내기 위해서 i값 증가
}
}
};
int main()
{
GamblingGame game;
game.setPlayer();
game.game_start();
}
view raw cp4_14.cpp hosted with ❤ by GitHub

 

 

<code>

#include <iostream>
#include <string>
using namespace std;
class Histogram
{
string str;
public:
Histogram(string str)
{
this->str = str;
cout << str << endl; //입력받은 문자열 출력
};
~Histogram() {};
void put(string n)
{
this->str += n; //원하는 문자열 추가하기
cout << n;
}
void putc(char a)
{
this->str += a; //char도 추가해주는 함수
cout << a;
}
void print(void)
{
int num = 0; //문자열에 사용된 알파벳 수 세어주는 변수
int alphabet[26] = { 0 }; //알파벳에 맞게 배열 생성
for (int i = 0; i < str.length(); ++i) {
if (isalpha(tolower(str[i])) != 0) { //알파벳이고, 대문자가 아닌 소문자로 변환해주고 문자열 값이 있을 경우
++num; //num을 증가시켜주고
alphabet[(int)(tolower(str[i]) - 97)]++; //대문자 그대로 하면 값이 달라지기에 소문자로 변환한 후, 아스키 코드값을 밴 배열만 값을 증가
}
}
cout << endl << endl;
cout << "총 알파벳 수 " << num;
cout << endl << endl;
for (int i = 0; i < 26; ++i) {
char c = 'a' + i;
cout << c << " (" << alphabet[i] << ")\t: "; // 배열의 숫자 출력
for (int j = 0; j < alphabet[i]; ++j) {
cout << "*"; // 배열 숫자만큼 "*" 출력해주는 부분
}
cout << endl;
}
}
};
int main() {
Histogram elvisHisto("Wise men say, only fools rush in But I can't help, ");
elvisHisto.put("falling in love with you");
elvisHisto.putc('-');
elvisHisto.put("Elvis Presley");
elvisHisto.print();
}
view raw cp4_13.cpp hosted with ❤ by GitHub

+ Recent posts