33,311
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<string>
using namespace std;
class Stock
{
public:
Stock(const char na[20],int q=1000,double p=8.98);
void print();
private:
char stockcode[20];
int quan;
double price;
};
Stock::Stock(const char na[20],int q,double p)
{
stockcode[20] = na[20];
quan = q;
price = p;
}
void Stock::print()
{
cout << this->stockcode[20] << this->quan << this->print << endl;
}
int main()
{
Stock S1("600001", 3000, 5.67);
S1.print();
Stock S2("600002");
S2.print();
return 0;
}
#include<iostream>
#include<string>
using namespace std;
class Stock
{
public:
Stock(const char na[20],int q=1000,double p=8.98);
void print();
private:
char stockcode[20];
int quan;
double price;
};
Stock::Stock(const char na[20],int q,double p)
{
strcpy(stockcode, na);
quan = q;
price = p;
}
void Stock::print()
{
cout << this->stockcode << this->quan << this->price << endl;
}
int main(int argc, char* argv[])
{
Stock S1("600001", 3000, 5.67);
S1.print();
Stock S2("600002");
S2.print();
return 0;
}