简介
使用方法很简单,其实只要看看代码就会了
代码
#include <bits/stdc++.h>
using namespace std;
class Stock
{
private:
string name;
string ID;
double price;
public:
Stock():name(""),ID("000000"),price(0.0){}
Stock(string n):name(n),ID("000000"),price(0.0){}
Stock(double p):name(""),ID("000000"),price(p){}
Stock(string i,double p):name(""),ID(i),price(p){}
Stock(string n,string i):name(n),ID(i),price(0.0){}
Stock(string n,string i,double p):name(n),ID(i),price(p){}
Stock(Stock& s):name(s.name),ID(s.ID),price(s.price){}
string GetName()
{
return name;
}
string GetID()
{
return ID;
}
double GetPrice()
{
return price;
}
void menu()
{
cout<<"------Stock------"<<endl;
cout<<"The stock\'s name:"<<name<<endl;
cout<<"The stock\'s ID:"<<ID<<endl;
cout<<"The stock\'s price:"<<price<<endl;
}
friend ostream& operator<<(ostream& os,Stock& s);
};
ostream& operator<<(ostream& os,Stock& s)
{
os<<"\""<<s.name<<"\"\'s ID is \""<<s.ID<<"\",and now,the price is:";
printf("¥%.3lf.",s.price);
return os;
}
int main()
{
Stock p("中国石油","09A011",102.357);
cout<<p<<endl;
p.menu();
return 0;
}