/*
* book.cpp
*
*Simple program for storing array of book titles and published dates
*
* Created on: Oct 9, 2010
* Author: Alpha
*/
#include <iostream>
#include <string>
usingnamespace std;
//declaration section
class book
{
private:
string bookTitle;
string publishedDate;
public:
void booktitles (string);
void date (string);
void printbook ();
};
void book::booktitles(string bookName)
{
bookTitle = bookName;
cout << "You have entered " << bookTitle << " as your book title" << endl;
}
void book::date(string date)
{
publishedDate = date;
cout << "You have entered " << publishedDate << " as your book published date" << endl;
}
void book::printbook()
{
//cout << bookTitle << "published in " << publishedDate << endl;
}
int main ()
{
constint SIZE = 10;
string titles[SIZE];
string dates[SIZE];
int x;
book publishedTitle;
for (x = 0; x < SIZE; ++x)
{
cout << "Please enter the book title, press 99 to print previous records or type exit to quit ";
getline (cin, titles[x]);
if (titles == 00)
{
cout << "Bye Bye";
}
else
publishedTitle.booktitles (titles[x]);
cout << "Please enter published date in DD/MM/YYYY format " << endl;
getline (cin, dates[x]);
publishedTitle.date (dates[x]);
}
return 0;
}
What do you mean by titles == 00? On a separate note, remember that 00 means 0 in octal. In that case, it means the same number, but if you said 010, for instance, it would actually mean decimal 8.
titles is a pointer to the first element of the array. You probably mean titles[x].
It will keep going in a for loop till 10 titles / dates is entered.
Yes, but you're overwriting them all because you only have one book object to store them in. You should be using a container or an array of book objects.
You only instantiate one object of type book (publishedTitle). Then you repeatedly fill the same object ten times with different values. Each time around, you just overwrite what was previously stored in publishedTitle.