C++改错啊……error: expected primary-expression before '.' token
#include<iostream>#include<string>usingnamespacestd;classInvoice{public:explicitInvoi...
#include<iostream>
#include<string>
using namespace std;
class Invoice
{
public:
explicit Invoice(int amount)
{
amount=p*q;
}
string partnumber(string number)
{
return number ; }
string partdescription(string description)
{
return description;
}
void perchased(int quantity)
{
q=quantity;
}
void priceperitem(int price)
{
p=price;
}
int getInvoiceAmount()
{ if (q<0)q=0;
if (p<0)p=0;
cout<<"the amount is:"<<amount1;
return amount1;}
private:
int q;
int p;
int amount1;
};
int main()
{
int q;
int p;
int number;
int description;
cout<<"please enter the part number,the part description,the quantity of the items and the price per item:"<<endl;
cin>>number>>Invoice.description>>q>>p;
cout<<"your part number is:"<<Invoice.partnumber(number);
cout<<"your part description is:"<<Invoice.partdescription(description);
Invoice.getInvoiceAmount();
} 展开
#include<string>
using namespace std;
class Invoice
{
public:
explicit Invoice(int amount)
{
amount=p*q;
}
string partnumber(string number)
{
return number ; }
string partdescription(string description)
{
return description;
}
void perchased(int quantity)
{
q=quantity;
}
void priceperitem(int price)
{
p=price;
}
int getInvoiceAmount()
{ if (q<0)q=0;
if (p<0)p=0;
cout<<"the amount is:"<<amount1;
return amount1;}
private:
int q;
int p;
int amount1;
};
int main()
{
int q;
int p;
int number;
int description;
cout<<"please enter the part number,the part description,the quantity of the items and the price per item:"<<endl;
cin>>number>>Invoice.description>>q>>p;
cout<<"your part number is:"<<Invoice.partnumber(number);
cout<<"your part description is:"<<Invoice.partdescription(description);
Invoice.getInvoiceAmount();
} 展开
3个回答
展开全部
#include<iostream>
#include<string>
using namespace std;
class Invoice
{
public:
explicit Invoice(int amount)
{
amount=p*q;
}
string partnumber(string number)
{
return number ;
}
string partdescription(string description)
{
return description;
}
void perchased(int quantity)
{
q=quantity;
}
void priceperitem(int price)
{
p=price;
}
int getInvoiceAmount()
{
if (q<0)
q=0;
if (p<0)
p=0;
cout<<"the amount is:"<<amount1;
return amount1;
}
private:
int q;
int p;
int amount1;
};
int main()
{
int q;
int p;
string number; //注意参数类型
string description;//注意参数类型
Invoice aa(1);//需要定义Invoice的一个对象aa
cout<<"please enter the part number,the part description,the quantity of the items and the price per item:"<<endl;
cin>>number>>description>>q>>p; //改成description
cout<<"your part number is:"<<aa.partnumber(number); //用对象.方法,而不是类名.方法;下同
cout<<"your part description is:"<<aa.partdescription(description);
aa.getInvoiceAmount();
}
注释已经写了,感觉对象和类傻傻分不清楚的样子啊!
追问
谢谢~不过我刚学……确实分不太清对象和类啊……我连概念都稀里糊涂的
追答
是刚学就好,要是学了一段时间还这样就悲剧了。。。
展开全部
cout<<"your part number is:"<<Invoice::partnumber(number);
追问
不对啊……can not call member function
追答
那你定义一个对象调用吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
main函数
>>Invoice.XXXXX
<<Invoice.XXXXX
这里必须先定义对象再使用
main()
{
Invoice invObj;
>>invObj.XXXXX
}
>>Invoice.XXXXX
<<Invoice.XXXXX
这里必须先定义对象再使用
main()
{
Invoice invObj;
>>invObj.XXXXX
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询