我正在创建一个项目,该项目应该接收用户对图书库的输入。我们还应该使用私有和公共类。我下课了。在我的无效Book :: enterInfo()中,是用于收集和存储数据的代码。在下面的主窗口中,我有一个for循环,询问您要创建多少本书。我的问题是,例如,当我输入4时,它不会分隔“输入书名”和“输入书名”。
------输入您的图书信息------ 输入书名: 输入图书作者: 要求用户输入 输入书籍格式(精装书,平装书,电子书,有声书): 要求用户输入 按照格式MM / DD / YY输入书籍出版日期: 要求用户输入 按照0.0格式输入图书价格: 要求用户输入
另外,当您输入第一本书的信息后,它会立即打印:
------输入您的图书信息------ 输入书名: 输入图书作者: 输入书籍格式(精装书,平装书,电子书,有声书): 按照格式MM / DD / YY输入书籍出版日期: 按照0.0格式输入图书价格:
对于第一本之后要创建的所有书籍。感谢您的帮助。代码:
#include <iostream>
#include <string>
#include "CoultersBookProject.h"
using namespace std;
//BOOK CLASS SECTION
class Book
{
// PRIVATE
private:
string title;
string author;
string format;
string publishDate;
double price;
// PUBLIC
public:
void enterInfo();
//-----------------------------------------------------------\\
// Title void get/set
void setTitle(string title)
{
this->title = title;
}
string getTitle()
{
return title;
}
//------------------------------------------------------------\\
// Author void get/set
void setAuther(string author)
{
this->author = author;
}
string getAuthor()
{
return author;
}
//-----------------------------------------------------------\\
// Format void get/set
void setFormat(string format)
{
this->format = format;
}
string getFormat()
{
return format;
}
//-----------------------------------------------------------\\
// Publish date void get/set
void setPublishDate(string publishDate)
{
this->publishDate = publishDate;
}
string getPublishDate() {
return publishDate;
}
//-----------------------------------------------------------\\
// Price void get/set
void setPrice(double price)
{
this->price = price;
}
double getPrice()
{
return price;
}
};
// Void area that asks for book information
void Book::enterInfo()
{
cout << "------Enter Your Book Information------" << endl;
cout << "Enter book title: " << endl;
getline(cin, title);
cout << "Enter book author: " << endl;
getline(cin, author);
cout << "Enter book format (Hardcover, Paperback, Ebook, Audiobook): " << endl;
getline(cin, format);
cout << "Enter book published date following the format MM/DD/YY: " << endl;
getline(cin, publishDate);
cout << "Enter book price following the format 0.0: " << endl;
cin >> price;
}
// COUSTOMER CLASS SECTION W/ SHOPPING CART
class Coustomer
{
// Private
private:
string enterName;
string addBook;
string displayBooks;
Book shoppingCart[5];
// Public
public:
//-----------------------------------------------------------\\
// Enter Name void get/set
void setEnterName(string enterName)
{
this->enterName = enterName;
}
string getEnterName()
{
return enterName;
}
//-----------------------------------------------------------\\
// Add Book void get/set
void setAddBook(string addBook)
{
this->addBook = addBook;
}
string getAddBook()
{
return addBook;
}
//-----------------------------------------------------------\\
// Display Books void get/set
void setDisplayBooks(string displayBooks)
{
this->displayBooks = displayBooks;
}
string getDisplayBooks()
{
return displayBooks;
}
};
// MISC FUNCTIONS
// MAIN AREA STARTS
int main()
{
int totalAmmountOfBooks;
cout << "How many books would you like to create?" << endl;
cin >> totalAmmountOfBooks;
Book * Inventory = new Book[totalAmmountOfBooks];
for (int i = 0; i < totalAmmountOfBooks; i++)
{
Book bo;
bo.enterInfo();
Inventory[i] = bo;
}