#include<iostream>
using std::cout;
using std::cin;
using std::endl;
#include<string>
using std::string;
#include<stdlib.h>
class Invoice
{
private:
string NO;
string description;
int count;
int price;
public:
Invoice(string NO, string description, int count, int price);
void setNOOfGood(string NO1)
{
NO = NO1;
}
string getNOOfGood()
{
return NO;
}
void setDescriptionOfGood(string description1)
{
description = description1;
}
string getDescription()
{
return description;
}
void setCount(int count1)
{
if (count1 <= 0)
{
count = 0;
cout << "無效" << endl;
}
else
count = count1;
}
int getCount()
{
return count;
}
void setPrice(int price1)
{
if (price1 <= 0)
{
price = 0;
cout << "無效" << endl;
}
else
price = price1;
}
int getPrice()
{
return price;
}
int getInvoiceAmount()
{
return getCount() * getPrice();
}
};
int main()
{
Invoice invoice("15", "food", 30, 2);
cout << "NO:" << invoice.getNOOfGood() << endl;
cout << "description:" << invoice.getDescription() << endl;
cout << "count:" << invoice.getCount() << endl;
cout << "price:" << invoice.getPrice() << endl;
cout << "InvoiceAmount:" << invoice.getInvoiceAmount() << endl;
system("pause");
return 0;
}
uj5u.com熱心網友回復:
教教我
uj5u.com熱心網友回復:
Invoice(string NO, string description, int count, int price);這個沒實作
uj5u.com熱心網友回復:
從你的代碼分析,應該不是空的實作,最起碼需要初始化幾個成員變數,比如Invoice(string NO, string description, int count, int price): m_NO(NO) {}
這里我把成員變數改成m_NO,你原來的命名會有沖突
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/113048.html
標籤:基礎類
