I want to add an array of titles for 10 books, that the user can add/input on a "string value" on each title that may contain more than one word. I tried to replace the "char" with "string" but it doesn't work correctly when running the program!
#include <iostream>
using namespace std;
class Book {
int year;
char Title[10]; // the problem with in here
int bookno;
int copyno;
int price;
public:
void Creatdata() // Statement 1 : Defining Creatdata()
{
cout << "\n\tEnter Book published year : ";
cin >> year;
cout << "\n\tEnter Book title : ";
cin >> Title;
cout << "\n\tEnter Book number: ";
cin >> bookno;
cout << "\n\tEnter Copy number: ";
cin >> copyno;
cout << "\n\tEnter Employee Salary : ";
cin >> price;
}
void DisplayData() // Statement 2 : Defining DisplayData()
{
cout << "\n" << year << "\t" << Title << "\t" << bookno << "\t" << copyno
<< "\t" << price;
}
};
int main() {
int i;
Book B[10]; // Statement 3 : Creating Array of 10 books
for (i = 0; i <= 10; i++) {
cout << "\nEnter details of " << i + 1 << " Book";
B[i].Creatdata();
}
cout << "\nDetails of Book";
for (i = 0; i <= 10; i++)
B[i].DisplayData();
return 0;
}