我收到的错误是C3867 'Member::getMN': non-standard syntax; use '&' to create a pointer to member'
。getID、nBks、cost 和 tcost 的错误相同。
询问客户的姓氏和身份证号码,然后询问他们想要的书籍数量并询问该书籍的费用。必须显示所有信息。不知道我的错误到底在哪里。
#ifndef MEMBER_H
#define MEMBER_H
#include <string>
#include <iostream>
using namespace std;
// define the class members and member function prototypes here
class Member
{
private:
string MemberName;//customer name
string MemberID;//customer id
int numBooks=0;//number of books
double PurchaseAmt=0;//cost of books
public:
void setMN(string);
void setmID(string);
void setnBks(int);
void setcost(double);
string getMN() const;
string getID()const;
int nBks()const;
double cost()const;//cost of a book
double tcost()const;
};
#endif
#include "member.h" // Needed for the member class
#include <iostream> // Needed for cout
#include <cstdlib> // Needed for the exit function
using namespace std;
void Member::setMN(string name)//string size for membername
{ if (name.size() < 12)
MemberName = name.substr(0, 12);
else
{
cout << "Invalid Member ID\n";
system("pause");
exit(EXIT_FAILURE);
}
}
void Member::setmID(string ID)//string size for MemberID
{ if (ID.size() < 5)
MemberID = ID.substr(0,5);
else
{
cout << "Invalid Member ID\n";
system("pause");
exit(EXIT_FAILURE);
}
}
void Member::setnBks(int num)//check for number of books
{ if (num > 0)
numBooks = num;
else
{
cout << "Invalid book count, must be over 0.\n";
system("pause");
exit(EXIT_FAILURE);
}
}
void Member::setcost(double amount)//check for cost of the book.
{ if (amount > 0)
PurchaseAmt = amount;
else
{
cout << "Invalid cost, can not be less then 0.\n";
system("pause");
exit(EXIT_FAILURE);
}
}
string Member::getMN() const
{ return MemberName;
}
string Member::getID() const
{ return MemberID;
}
int Member::nBks() const
{ return numBooks;
}
double Member::cost() const
{ return PurchaseAmt;
}
double Member::tcost() const//getting the total cost of the book(s)
{ return numBooks * numBooks;
}
#include <iostream>
#include <string>
#include <iomanip>
#include "member.h" // Needed for Member class
using namespace std;
void getinfo(Member&);
void display(Member);
int main()
{
Member books;
system("pause");
return 0;
} // end main
//this function returns member name and id, also number of books and the cost.
// this function displays the book store's data.
void getinfo(Member& x)
{
string MemberName, MemberID;
int numBooks;
double PurchaseAmt;
cout << fixed << showpoint << setprecision(2);
cout << "What is the members last name, must be under 12 char?\n";
cin >> MemberName;
x.setMN(MemberName);
cout << "What is the members ID, must be under 5 int?\n";
cin >> MemberID;
x.setmID(MemberID);
cout << "How many books?\n";
cin >> numBooks;
x.setnBks(numBooks);
cout << "How much does each book cost?\n";
cin >> PurchaseAmt;
x.setcost(PurchaseAmt);
} // end getting information.
void display(Member x)
{
cout << fixed << showpoint << setprecision(2);
cout << "The member's last name is : " << x.getMN << endl;
cout << "The member's ID is : " << x.getID << endl;
cout << "The number of books bought are : " << x.nBks << endl;
cout << "The cost per book is : " << x.cost << endl;
cout << "The total is : " << x.tcost << endl;
}