用c++ 定义一个类Stock,记录一支股票交易的基本信息。

2024-05-17 05:40

1. 用c++ 定义一个类Stock,记录一支股票交易的基本信息。

你是不愿意写代码吧,这个不难啊,基本学过类的都会
定义类Stock,里面有上述的私有成员变量,以及各个成员变量的公有set 和 get方法

再在main函数中创建连个变量
Stock todayStock;
Stock yesterdayStock;
再分别调用set函数,然后再计算涨幅、输出,很简单啊

用c++ 定义一个类Stock,记录一支股票交易的基本信息。

2. c++程序设计题:定义一个股票类(stock)对象数组,存放连续5个交易日的股票信息,计算股票涨幅。

#include using namespace std;int main(){    double stock[5]; // 定义长度为5的数组存放用户输入的股票价格    for(int i = 0;i > stock[i];    } // 循环读入用户输入的股价    double percent = (stock[4] - stock[0]) * 100;    cout << "涨幅:" << percent << "%" << endl;    return 0;}

3. 超级难的C++难题,求高手帮忙

#include  
#include 
using namespace std; 
class book 
{ 
public: 
book(); 
book(int i); //重载构造函数 
~book(); 
private: 
int qu; 
int price; 
public: 
void print() const 
{ 
cout<<qu*price<<endl; 
} 
}; 
book::book() 
{ 
qu = 0; 
price = 0; 
} 
book::book(int i) 
{ 
qu = i; 
price = i*10; 
} 
book::~book() 
{ 
} 

int main() 
{ 
book *p[5] = {0}; 
for(int i=0;i<5;i++) 
{ 
p[i] = new book(i+1); 
} 
for(int i=4;i>=0;i--) 
{ 
p[i]->print(); 
} 
for(int i=0;i<5;i++) 
{ 
delete p[i]; 
} 
system("PAUSE");
return 0; 
}

超级难的C++难题,求高手帮忙

4. 高分求助C++超难题

#include  
#include 
using namespace std; 
class book 
{ 
public: 
book(); 
book(int i); //重载构造函数 
~book(); 
private: 
int qu; 
int price; 
public: 
void print() const 
{ 
cout<<qu*price<<endl; 
} 
}; 
book::book() 
{ 
qu = 0; 
price = 0; 
} 
book::book(int i) 
{ 
qu = i; 
price = i*10; 
} 
book::~book() 
{ 
} 

int main() 
{ 
book *p[5] = {0}; 
for(int i=0;i<5;i++) 
{ 
p[i] = new book(i+1); 
} 
for(int i=4;i>=0;i--) 
{ 
p[i]->print(); 
} 
for(int i=0;i<5;i++) 
{ 
delete p[i]; 
} 
system("PAUSE");
return 0; 
}

5. 求解c++:构建一个类Stock,含字符数组stockcode[]及整型数据成员quan、双精度型数据成员price。

#include 
// const unsigned MAX_LEN = 256;
class Stock
{
public:
    // 这里用的初始化形参列表
    Stock(char na[], int q=1000, double p=8.98) : stockcode(na), quan(q), price(p)
    {}
    void print(void)
    {
        std::cout stockcode << " " << quan << " " << price << std::endl;
    }
private:
    char *stockcode;        // 或改为 char stockcode[MAX_LEN];
                                       // 其中 MAX_LEN 定义在前为一常量: const unsigned MAX_LEN = 256;
    int quan;
    double price;
};
// main function
int main(int argc, char *argv[])
{
    char szTestString[] = "600001";   // It's terminated with '\0'
    int iTestInteger = 3000;
    double dTestDouble = 5.67;
    Stock stObj1(szTestString, iTestInteger, dTestDouble);
    Stock stObj2(szTestString);
    stObj1.print();
    stObj2.print();
    return 0;
} // end main
// gcc - g++ 4.5 下编译通过
// 结果如图

求解c++:构建一个类Stock,含字符数组stockcode[]及整型数据成员quan、双精度型数据成员price。

6. 在c++中创建了类,但在创建新对象时,编译显示:不存在默认构造函数

在c++中,如果你没有自定义构造函数,那么系统会给你的类提供一个默认的无参数的构造函数,你现在已经自定义了一个有参数的构造函数:Stock(char[] );
有两种解决办法:
一:你再显式定义一个无参数的构造函数,比如 
Stock::Stock()
{
        Symbol  = "默认股票名";

        price  =  0.0;

}

二、你按照正确的格式使用你自定义的构造函数,即 Stock(char[]) (要带一个字符串参数):

把主函数中的  Stock mystock;
改为  Stock mystock("我的股票");

7. 请求高手,帮帮我解决一道C++题

怎么觉得好像在哪儿看过??
你以前问过?

请求高手,帮帮我解决一道C++题

8. 用c++ 定义一个类Stock,记录一支股票交易的基本信息。

#include
#include

class Stock{
public:
Stock(int o,int h,int l,int c)
{
    close=c;
    open=o;
    low=l;
    high=h;
}

private:
int high;
int low;
int open;
int close;
};

int main()
{
 Stock st(5,5.5,5,5.5); 
Stock yesterday;
drawline(st);  //未定义实现
yesterday=st;//有待您改进ing。
return 0;
}
最新文章
热门文章
推荐阅读