해결된 질문
작성
·
185
2
#include <iostream>
using namespace std;
class Stock
{
public:
void acquire(string&, int, float); //string뒤에 엠퍼센드가 붙으면 오류가 뜨네요.. 엠퍼센드가 붙은 이유가 뭔가요??
void buy(int, float);
void sell(int, float);
void updata(float);
void show();
Stock();
~Stock();
private:
string name;
int shares;
float share_val;
double total_val;
void set_total() { total_val = shares*share_val; }
};
void Stock::acquire(string& co, int n, float pr)
{
name = co;
shares = n;
share_val = pr;
}
void Stock::buy(int n, float pr)
{
shares += n;
share_val = pr;
set_total();
}
void Stock::sell(int n, float pr)
{
shares -= n;
share_val = pr;
set_total();
}
void Stock::updata(float pr)
{
share_val = pr;
set_total();
}
void Stock::show()
{
cout << "회사 명 :" << name << endl;
cout << "주식 수 :" << shares << endl;
cout << "주가 :" << share_val << endl;
cout << "주식 총 가치 :" << total_val << endl;
}
Stock::Stock()
{
}
Stock::~Stock()
{
}
int main() {
Stock temp;
temp.acquire("Panda", 100, 1000);
temp.show(); //이 부분 출력 될 때 주식 총 가치 :-9.25596e+61 라고 출력이 되는데 이유를 모르겠습니다.
temp.buy(10, 1200);
temp.show();
temp.sell(5, 800);
temp.show();
return 0;
}
추상화와 클래스 강의입니다.