?? usestock2.cpp
字號:
// 3.重新編寫程序清單10.7和10.8描述的Stock類,使之使用動態分配
// 的內存,而不是string類對象來存股票名稱.另外,使用重載的operator<<()
// 定義來代替show()成員函數.然后使用程序清單10.9測試新的定義程序.
// usestock2.cpp -- using the Stock class
// complie with stock2.cpp
#include <iostream>
#include "stock2.h"
const int STKS = 4;
int main()
{
using std::cout;
using std::ios_base;
// create an array of initialized objects
Stock stocks[STKS] = {
Stock("NanoSmart",12, 20.0),
Stock("Boffo objects",200,2.0),
Stock("Monolithic obelisks", 130, 3.25),
Stock("Fleep Enterprises", 60, 6.5)
};
cout.precision(2); // #.## format
cout.setf(ios_base::fixed, ios_base::floatfield); // #.## format
cout.setf(ios_base::showpoint); // #.## format
cout<< "Stock holdings:\n";
int st;
for(st = 0; st < STKS; st++)
cout<<stocks[st];
Stock top = stocks[0];
for(st = 1; st < STKS; st++)
top = top.topval(stocks[st]);
cout<<"\nMost valuable holding:\n";
cout<<top;
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -