본문 바로가기

전체 글326

C++ coding training function, array, class[c++ 코딩연습: 함수, 배열, 클래스, 프로토타입 헤더 분리] 문제(요구사항):메시지를 3개 정도 입력해서 연결이 된 상태(connect) 에서 play()로 메시지 출력 play(2) 해당 위치의 메시지movePos 출력할 위치 옮기기, msgdelete() 해당 위치 메시지 제거 disconnect() 시 play()호출 하면 출력 불가 메시지-제시된 main 함수는 기본적인 테스트 용 이므로, 메인 문 추가코드 작성 aam.h#include using namespace std; class AAM {string text; public:void connect();void record();int play();int play(int n);int getMsgNum();void movePos(int n);void msgdelete();void disconnect();};.. 2019. 1. 12.
C++ account BankAccount class deposit, withdraw, 계좌 이체 #include #include using namespace std; class BankAccount { // 은행 계좌 private: int accountNumber; // 계좌 번호 string owner; // 예금주 int balance; // 잔액을 표시하는 변수 public: void setAccountNumber(int aNumber); void setOwner(string myowner); void setBalance(int amount); // balance에 대한 설정자 int getBalance(); // balance에 대한 접근자 void deposit(int amount); // 입금 함수 void withdraw(int amount); // 인출 함수 void print();.. 2019. 1. 10.
C++ powerC++ p404 LAB box 클래스 setter getter 함수 #include #include using namespace std; class Box {private:int width, length, height;int v;public:void setwidth(int w);int getwidth(); //접근자void setlength(int l);int getlength(); //접근자void setheight(int h);int getheight(); //접근자 int getVolume();void get_input();void print();}; void Box::setwidth(int w){width = w;}int Box::getwidth(){return width;}void Box::setlength(int l){length = l;}int Box::ge.. 2019. 1. 9.
C++ string 함수 문자 변경 getline(cin,s) , find, length, replace #include#includeusing namespace std; int main(){string s;string changed, changing;cout 2019. 1. 9.
C++기초 배열 원소들의 순서를 역순서로 Reverse Array function, 동적 메모리 할당 Power C++ p294 5 //Poewr C++ p294 5.//동적으로 순서 반대로 void reverse(int *data, int n);void initialize(int *data, int n);void printdata(int *data, int n); int main() { int *data = new int[10]; initialize(data, 10); printdata(data, 10); cout 2019. 1. 9.
C++기초 연산과 횟수[static] 정적 변수 지역 변수는 속하는 함수가 종료될 때 파괴되는 것이 일반적이다.지역 변수에 static 을 붙이게 되면, 전역 변수와 같은 기억수명을 가지게 된다. #include using namespace std; // 함수 프로토타입void add(int x, int y);void rhq(int x, int y); //곱셈 static int count1 = 0, count2 = 0; //정적 변수 int main(void) { int x, y;char z; do {cout > x >> z >> y; if (z == '+'){add(x, y);}else if (z == '*'){rhq(x, y);}} while (true); return 0;} void add(int x, int y){count1++; cout 2019. 1. 9.
C++ 다이아몬드 출력하기 C++을 몇 일 접하지 않은 상태에서는 꽤나 까다로울 수 있을 것이다. Tip은 중간의 별의 갯수를 지정한다.size와 blank(공백)을while문 안에서 for문을 2개 돌린다. 여기서 while문을 2개 돌리는데 하나는 별이 늘어나도록나머지 하나는 별이 줄어들도록 돌리는 것이다. int main(){int size;int blank;int star = 1; cout > size; // 중간의 별 갯수blank = size / 2; while (1) //위쪽 별 갯수 늘어나도록{for (int x = 0; x < blank; x++){cout 2019. 1. 9.
C++기초 함수 활용 3의 제곱수 #include using namespace std; double ipower(int n, int k) { double result = 1; for (int i = 1; i 2019. 1. 8.
C++기초 함수호출 int get_max(int x, int y)// 정수 2개 입력후 큰 값의 제곱값 출력{if (x > y)return (x);else return (y);} int square(int n){return(n*n);} int main(){int z, r;cout > r; int max = get_max(z, r);//get_max의 함수 결과값을 max에 저장cout 2019. 1. 8.
C++기초 알파벳 대문자를 소문자로 소문자를 대문자로 변환 / 반복문 #include using namespace std;int main(){char z; cout > z; if (z >= 'a' && z = 'A' && z 2019. 1. 8.
C++기초 세 개의 정수 중 가장 작은 값(최솟값) 구하기 #include using namespace std;int main(){ int num1, num2, num3; cout > num1 >> num2 >> num3; if(num1 < num2 && num1 < num3) { cout 2019. 1. 8.
C++기초 Variable sizeof, int double char int main(){int a; cout 2019. 1. 8.