분할컴파일 LNK2019 오류 관련 질문

조회수 380회

분할 컴파일 관련해서 코드를 만들고 있었습니다.

처음에 cpp 파일 하나로 먼저 완성한 후에

헤더파일 cpp, main 따로 나눈후에 컴파일하니까 LNK2019라는 오류가 계속 뜹니다.

( 나누기 전에 한 파일로 실행 했을 때는 오류 없이 원하는 대로 실행됐었습니다.)

인터넷을 찾아봐도 마땅한 해결 방법이 없다 라고만 나오고...

몇시간동안 눈 시퍼렇게 뜨고 한줄 한줄 잘못 쓴거 있나 찾아봤는데 못 찾았습니다.

중요한 건데 제가 공부를 덜해서 모르고 있는 규칙이 있는 거 같은데...

답이 아니 라도 이럴 때 확인할만한 거 힌트라도 하나 던져주시면 정말 감사할 것 같습니다.

오류는 stockname 파일 에서만 뜨는데 혹시 몰라서 두 개다 올렸습니다.

오류 메시지입니다. 이미지

header.h

#ifndef HEADER_H
#define HEADER_H
#include <iostream>
#include <string>
#include <time.h>
#include <cstdlib>
using namespace std;
class stockname {
public:
    string name;
    int curprice;
    int prevprice[15][15];
    int a, b, loc;
    void init(string stockname, int startprice);
    void pricechange(int randN, int changerate);
    void printinfo();
};
class portfolio {
private:
    string stocknames[15];
    string input;
    int currentN[15], currentbalance;
    int boughtprice[15];
    int gainorloss, a, inputN;
public:
    portfolio(string arr[]);
    void printstatus(stockname arr[]);
    void buystock(string arr[], stockname arr2[]);
    void sellstock(string arr[], stockname arr2[]);
    void banking();
};

stockname.h

#include "header.h"
void stockname::init(string stockname, int startprice) {
    name = stockname;
    curprice = startprice;
    for (a = 0; a < 15; a++) {
        for (b = 0; b < 15; b++) {
            prevprice[a][b] = 0;
        }
    }
}
void stockname::pricechange(int randN, int changerate) {
    int prevN = 7;
    for (a = 0; a < 14; a++) {
        for (b = 0; b < 15; b++) {
            if (prevprice[a + 1][b] != 0) {
                prevprice[a + 1][b] = 0;
                prevprice[a][b] = 1;
                prevN = b;
                break;
            }
        }
    }
    if (randN % 2 == 0)
        randN = -randN;
    curprice += randN;
    if (curprice <= 0)
        curprice = 0;
    if (changerate == 2)
        prevprice[14][prevN + 2] = 1;
    else if (changerate == 1)
        prevprice[14][prevN + 1] = 1;
    else if (changerate == 0)
        prevprice[14][prevN] = 1;
    else if (changerate == -1)
        prevprice[14][prevN - 1] = 1;
    else
        prevprice[14][prevN - 2] = 1;
}
void stockname::printinfo() {
    cout << "Stock Name : " << name << endl;
    cout << "Current Price : " << curprice << endl;
    cout << "Price Chart : " << endl;
    b = 0;
    for (a = 0; a < 15; a++) {
        if (prevprice[a][b] != 0)
            loc = a;
    }
    for (b = 0; b < 15; b++) {
        for (a = 0; a < 15; a++) {
            if (prevprice[a][b] == 0) {
                cout << 0;
            }
            else
                cout << "1";
        }
        cout << ':';
        if (b == loc) {
            cout << curprice;
        }
        cout << endl;
    }
}

portfolio.h

#include "header.h"
portfolio::portfolio(string arr[]) {
    for (int a = 0; a < 15; a++) {
        stocknames[a] = arr[a];
        currentN[a] = 0;
        boughtprice[a] = 0;
    }
    currentbalance = 1000000;
    gainorloss = 0;
}
void portfolio::printstatus(stockname arr[]) {
    int count = 0;
    cout << "Your Portfolio : " << endl;
    for (int a = 0; a < 15; a++) {
        if (currentN[a] != 0) {
            cout << "Name : " << stocknames[a] << "  " << currentN[a] << " Stock(s)" << endl << "Price Difference : " << (arr[a].curprice * currentN[a]) - (boughtprice[a] * currentN[a]) << endl;
            cout << "Current Price : " << arr[a].curprice << "  Your Average Price : " << boughtprice[a] << endl;
            count++;
        }
    }
    if (count == 0) {
        cout << "Your Portfolio is Empty" << endl;
    }
    cout << "Your Current Balance : " << currentbalance << endl;
    return;
}
void portfolio::buystock(string arr[], stockname arr2[]) {
    cout << "Type the name of the stock you want to buy : ";
    cin >> input;
    for (a = 0; a < 15; a++) {
        if (input == arr[a]) {
            cout << "Type the amount of the stock you want to buy : ";
            cin >> inputN;
            if (arr2[a].curprice * inputN > currentbalance) {
                cout << "Not Enough Balance in your account" << endl;
            }
            else {
                currentbalance -= arr2[a].curprice * inputN;
                currentN[a] += inputN;
                boughtprice[a] = ((boughtprice[a] * currentN[a]) + (arr2[a].curprice * inputN)) / currentN[a];
                cout << "Purchase Confirmed" << endl;
            }
        }
    }
    return;
}
void portfolio::sellstock(string arr[], stockname arr2[]) {
    cout << "Type the name of the stock you want to sell : ";
    cin >> input;
    for (a = 0; a < 15; a++) {
        if (input == arr[a]) {
            cout << "Type the amount of the stock you want to sell : ";
            cin >> inputN;
            if (currentN[a] < inputN)
                cout << "Not Enough Stocks to sell" << endl;
            else {
                currentbalance += arr2[a].curprice * inputN;
                currentN[a] -= inputN;
                cout << "Sell Confirmed" << endl;
            }
        }
    }
    return;
}
void portfolio::banking() {
    cout << "1. Deposit 2. Withdraw " << endl;
    cin >> inputN;
    if (inputN == 1) {
        cout << "Type the Amount of Money you wish to Deposit : ";
        cin >> inputN;
        currentbalance += inputN;
        cout << "Deposit Confirmed" << endl;
    }
    else if (inputN == 2) {
        cout << "Type the Amount of Money you with to Withdraw : ";
        cin >> inputN;
        if (currentbalance >= inputN) {
            currentbalance -= inputN;
            cout << "Withdraw Confirmed" << endl;
        }
        else {
            cout << "Not Enough Balance" << endl;
        }
    }
    return;
}

main.cpp

#include "header.h"
void changeprice(stockname arr[], int N) {
    int randN = rand() % 5, changerate;
    if (randN == 0)
        changerate = -2;
    else if (randN == 1)
        changerate = -1;
    else if (randN == 2)
        changerate = 0;
    else if (randN == 3)
        changerate = 1;
    else
        changerate = 2;
    if (changerate == 2 || changerate == -2) {
        randN = rand() % (60 + 1 - 40) + 40;
    }
    else if (changerate == 1 || changerate == -1) {
        randN = rand() % (40 + 1 - 20) + 20;
    }
    else
        randN = rand() % 20 + 1;
    arr[N].pricechange(randN, changerate);
    return;
}
int main() {
    srand(time(NULL));
    stockname stocks[15];
    string name[15] = { "SAMSUNG","SK", "LG",  "KAKAO", "POSCO", "KB" ,"KIA", "LOTTE", "KT", "HANHWA", "HYUNDAI", "CJ", "GS", "CU" },inputstr;
    int a, input=0,b;
    portfolio myfot(name);
    for (a = 0; a < 15; a++) {
        stocks[a].init(name[a],10000);
    }

    while (input != 4) {
        cout << "Choose the function you with to perform " << endl;
        cout << "1. Check the Market 2. See your Portfolio 3. Buy or Sell 4.deposit or withdraw 5. exit" <<endl;
        cin >> input;
        if (input == 1) {
            for (b = 0; b < 15; b++) {
                changeprice(stocks,b);
            }
            cout << "Type name of the stock you want to see" << endl;
            cin >> inputstr;
            for (a = 0; a < 15; a++) {
                if (name[a] == inputstr) {
                    stocks[a].printinfo();
                    break;
                }
            }
            if (a == 15)
                cout << "There is no such stock" << endl;
        }
        else if (input == 2) {
            for (b = 0; b < 15; b++) {
                changeprice(stocks,b);
            }
            myfot.printstatus(stocks);
        }
        else if (input == 3) {
            for (b = 0; b < 15; b++) {
                changeprice(stocks, b);
            }
            cout << "1.Buy 2.Sell" << endl;
            cin >> input;
            if (input == 1) {
                myfot.buystock(name,stocks);
            }
            else if (input == 2) {
                myfot.sellstock(name, stocks);
            }
        }
        else if (input == 4) {
            for (b = 0; b < 15; b++) {
                changeprice(stocks, b);
            }
            myfot.banking();
        }
        else if (input == 5) {
            break;
        }
    }
    return 0;
}

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)