#include<iostream>
#include<cstring>
using namespace std;
class Stock
{
private:
char S_name[100];
int S_num;
double S_price;
double S_total_value;
public:
//void acquire(char name[],int num,double price);
void buy(int num,double price);
void sell(int num,double price);
void update_price(double price);
void update_tt_value();
void show();
Stock(char name[],int num,double price);
Stock(Stock& st);
~Stock();
};
void Stock::update_tt_value()
{
S_total_value=S_num*S_price;
}
/*
void Stock::void acquire(char name[],int num,double price)
{
strcpy(S_name,name);
S_num=num;
S_price=price;
update_tt_value();
}
*/
void Stock::buy(int num,double price)
{
S_num+=num;
S_price=price;
update_tt_value();
}
void Stock::sell(int num,double price)
{
S_num-=num;
S_price=price;
update_tt_value();
}
void Stock::update_price(double price)
{
S_price=price;
update_tt_value();
}
void Stock::show()
{
cout<<"Name: "<<S_name<<endl;
cout<<"Num: "<<S_num<<endl;
cout<<"Price: "<<S_price<<endl;
cout<<"Total Value: "<<S_total_value<<endl<<endl;
}
Stock::Stock(char name[],int num,double price)
{
strcpy(S_name,name);
S_num=num;
S_price=price;
update_tt_value();
}
Stock::Stock(Stock& st)
{
strcpy(S_name,st.S_name);
S_num=st.S_num;
S_price=st.S_price;
S_total_value=st.S_total_value;
cout <<"Calling the copy constructor"<<endl;
}
Stock::~Stock()
{
}
int main()
{
Stock st("tx",100,3.5);
Stock st2 = st;
st.buy(200,4);
st.show();
st.sell(150,3.8);
st.show();
st.update_price(5);
st.show();
return 0;
}
股票系统
最新推荐文章于 2024-10-04 10:22:58 发布
本文探讨了股票交易系统的架构,包括实时行情获取、订单处理、风险管理及交易数据分析等方面,旨在实现高效、安全的证券交易。内容涉及技术选型、并发处理、数据存储和实时计算等关键问题。
摘要由CSDN通过智能技术生成