【发布时间】:2015-01-21 20:34:48
【问题描述】:
奇怪的是,当我输入要存储的成员的标题时,它并没有存储它有什么问题。我不知道问题是什么我已经尝试了很多东西。我知道中值变量可以正常工作,但实际的类成员函数存储不起作用请帮忙。
class BookType
{
private:
string Bookinfo;
string BookTitle;
string publisher;
double price;
int ISBN;
string authors[4];
int tracka;
int copy;
int Booktracker;
public:
BookType()
{
}
void setpub(const std::string &pr)
{
publisher = pr;
}
string getpub()
{
return publisher;
}
void setcopy(int c)
{
int copy = c;
}
int getcopy()
{
return copy;
}
void setprice(double p)
{
double price = p;
}
double getprice()
{
return price;
}
void SetBookTitle(const std::string &BT)
{
BookTitle = BT;
}
string GetBookTitle()
{
return BookTitle;
}
void SetISBN(int I)
{
ISBN = I;
}
int GetISBN()
{
return ISBN;
}
void setnumAuthor(int a)
{
tracka = a;
}
void setauthor(const std::string &a, int tracka)
{
for (int tracka; tracka<4; tracka++)
{
authors[tracka] = a;
}
}
void setTBook(int T)
{
Booktracker = T;
}
string getauthor()
{
for (int i = 0; i < 4; i++)
{
return authors[i];
}
}
};
int main()
{
optionmenu();
system("pause");
return 0;
}
void optionmenu()
{
BookType Book[10];
int a = 0;
string title;
int isbn;
int i = 0;
string nu;
string author;
char choice;
string pub;
double price;
int copy;
int ch;
string srch;
bool found = false;
cout << "Hello welcome to the Bookinfo site please select an option." << endl;
cout << " do you wish to continue the book info program? 1 for yes any key for no!" ; cin >> ch;
while (ch == 1)
{
MenuOptions();
cin >> choice;
switch (choice)
{
case '1':
while (i >= 10)
{
cout << "you have reached he book limit, choose another menu option!"; cin >> choice;
}
cout << i << endl;
cout << i << endl;
cout << "=====================" << endl;
getline(cin, nu);
cout << "Please enter book title" << endl;
getline(cin,title);
Book[i].SetBookTitle(title);
if (choice = '1')
{
i++;
}
cout << "please enter the author(s) name(s), if less then 4 authors leave (NA) in the leftover blanks." << endl;
for (int ai = 0; ai < 4; ai++)
{
getline(cin, author);
Book[i].setnumAuthor(ai);
}
cout << "=======================================================" << endl;
cout << "please enter the books ISBN Number." << endl;
cin >> isbn;
Book[i].SetISBN(isbn);
cout << "what is the publisher of the book?" << endl;
getline(cin, nu);
getline(cin, pub);
Book[i].setpub(pub);
【问题讨论】:
-
string BookTitle = BT;这是创建一个与您的成员变量同名的变量并将 BT 分配给它。删除类型:BookTitle = BT; -
请看一本好书(涵盖C/C++)
标签: c++ arrays string class variables