Hi guys, this program is suppose to ask user input for up to 10 book titles and date published using classes. However im having trouble with a certain part of the output. My coding as follows
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class bookInput
{
private:
string title;
double date;
public:
void setTitle(string);
void setDate(double);
void displaybook();
};
void bookInput::setTitle(string booktitle)
{
title = booktitle;
}
void bookInput::setDate(double pDate)
{
date = pDate;
}
void bookInput::displaybook()
{
cout<< "\tName:"<< title << " \t\t\tDate Published: " << date<< endl;
}
void printbook();
int main()
{
char selection =0;
char ans;
do
{
system("cls");
cout<< "1. Insert booktitle and dates"<<endl;
cout<< "2. Exit"<<endl;
cout<<" Please enter selection:"<<endl;
cin>>selection;
if(selection=='1')
printbook();
else if(selection=='2')
{
cout<<"Exiting program"<<endl;
system("pause");
return 0;
}
else
cout<<"Invalid selection"<<endl;
cout<<"Do you wish to continue? Please enter Y/N"<<endl;
cin>>ans;
}while((ans!='N')&& (ans!='n'));
return 0;
system("pause");
return 0;
}
void printbook()
{
const int MAX=3;
bookInput myFav[MAX];
int x;
string Title,mystr;
double date;
for(x=0; x < MAX; ++x)
{
cout<< "Enter book title#" << (x+1) << " ";
getline (cin, Title);
cout << " Enter the published date" ;
getline (cin, mystr);
stringstream(mystr) >> date;
myFav[x].setTitle(Title);
myFav[x].setDate(date);
}
cout<<endl<< " Book list:"<<endl;
for (x=0; x<MAX; ++x)
myFav[x].displaybook();
}
My trouble is with the first book title input. It prints out both booktitle and date published on the same line. It doesnt happen for the rest of the titles though. any help is much appreciated
secondly, i would like to implement a calendar class for the input of the dates. Can anyone guide me in the direction? thanks