(二)若 C++程式包含下列宣告:
class Automobile {
public:
void setPrice(double newPrice);
void setProfit(double newProfit);
double getPrice();
private:
double price;
double profit;
double getProfit(); }
且主程式(main function)包含下列宣告,並設定完成其 member 變 數中的值。
Automobile Toyota, Nissan;
下列那些指令敘述(statements)在主程式中是合法的(legal),那些 是不合法的(illegal)?(10 分)
Toyota.price = 5233.99;
Nissan.setPrice(4000.24);
double aPrice, aProfit;
aPrice = Nissan.getPrice();
aProfit= Nissan.getProfit();
aProfit= Toyota.getProfit();
Toyota = Nissan;