본문 바로가기

cpp18

C++ 오류 : 여러 번 정의된 기호가 있습니다. 상속생성.obj에 이미 정의되어 있습니다. 오류 : 여러 번 정의된 기호가 있습니다. xxx.obj에 이미 정의되어 있습니다. LNK1169 LNK2005 자바를 해보니 프로젝트가 패키지 의미 인줄 알았다. C++에서는 한 프로젝트안에 파일 분할의 개념으로 헤더파일, cpp파일 등으로 나눌 수 있다. 그렇지만 한 프로제트 내에 main 문을 2개 이상 두면 위와 같은 오류 발생 int main(), void main() 2019. 1. 25.
C++ 상속inheritance, derived class, 오버라이드(overriding) - Power C++ p565 LAB 상속inheritancederived class 선언class 파생 클래스 명 : 접근 지정자 기본 클래스 명{파생 클래스에 추가할 멤버 선언}; 클래스의 큰 장점인 '상속(inheritance)' '캡슐화(Encapsulation)' '다형성' protected : 파생클래스의 함수에서 기본 클래스의 protected멤버에 접근할 수 있다. 상속방법:class Student : public Human 기본 클래스의 public 멤버 -> 파생 클래스의 public 멤버기본 클래스의 protected멤버 -> 파생 클래스의 protected멤버기본 클래스의 private멤버 -> 파생 클래스의 private멤버 멤버 함수 오버라이드오버라이드(overriding) : 파생 클래스의 함수가 기본 클래스의 함.. 2019. 1. 17.
C++ operator+ 연산자 오버로드(operator overloading) ,friend ostream& operator / friend istream& operator (스트림) 1. operator overloading 객체간의 연산을 위한 기능연산자 오버로드(operator overloading) 이라고 한다. 경우 1) 인수가 한 개리턴 값의 형 operator 연산자(인수);Complex operator+(Complex c); //이항 연산자를 멤버 함수로 오버로드 연산결과 +연산자의 왼쪽변수 오른쪽 변수Complex Complex::operator+(Complex c); //코드{Complex com(0,0);com.real = real + c.real;com.imag = imag + c.imag;return com;} 경우 2) 인수가 두 개friend 리턴 값의 형 operator 연산자 (인수1, 인수2);friend Complex operator+ (int c1,.. 2019. 1. 16.
C++ 기초 static변수 최다 최소 구하기 / 여러 번 정의된 기호가 있습니다.LNK1169 LNK2005 Student.h #pragma once#include #include using namespace std; class Student { string name; int kor, math, eng, avr; public:static int count;Student();double getAvr();string getName();static int getcount() { return count; }~Student() {}}; Student.cpp #include "Student.h"#include using namespace std; Student ::Student(){cout > name;cout > kor;cout > math;cout > eng;++count;//생성시 증가} double Student .. 2019. 1. 16.
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.