Hi there!
So, my assignment is to make a book inventory from a file that gets read by the program and put into a linked list. All of the classes, members, constructors and functions seen below are required to be in the program. The only added constructed I add is
Date(unsigned int, unsigned int, unsigned int);
What I have tried:
The error I'm getting just says "warning: unused variable 'published'.
I don't think I'm using
Date *published
correctly in
class Book
. I tried to make a struct in
class Date
out of the variables in there, but that seemed to only make my problems worse.
I would appreciate any nudge in the right direction. Thanks! In the name of saving space, I've left out some stuff that I think is working fine, but I can add back in here if it would be helpful.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Date{
public:
unsigned int day;
unsigned int month;
unsigned int year;
Date(void);
Date(unsigned int, unsigned int, unsigned int);
~Date(void);
};
Date::Date(void){
day = 0;
month = 0;
year = 0;
}
Date::Date(unsigned int day, unsigned int month, unsigned int year){
day = day;
month = month;
year = year;
}
Date::~Date(void){
}
class Book{
public:
string title;
string author;
Date *published;
string publisher;
float price;
string isbn;
unsigned int pages;
unsigned int copies;
Book(void);
Book(string, string, Date, string, float, string, unsigned int, unsigned int );
~Book(void);
};
Book::Book(void){
title = "";
author = "";
Date *published = NULL;
publisher = "";
price = 0;
isbn = "";
pages = 0;
copies = 0;
}
Book::Book( string title, string author, Date published, string publisher,
float price, string isbn, unsigned int pages, unsigned int copies){
title = title;
author = author;
published = published;
publisher = publisher;
price = price;
isbn = isbn;
pages = pages;
copies = copies;
}
void LinkedList::print_list(void){
Node *temp = head;
while( temp != NULL ){
cout << temp->book->title << endl;
cout << temp->book->author << endl;
cout << temp->book->published << endl;
cout << temp->book->publisher << endl;
cout << temp->book->price << endl;
cout << temp->book->isbn << endl;
cout << temp->book->pages << endl;
cout << temp->book->copies << endl;
temp = temp->next;
cout << endl;
}
}
int main()
{
LinkedList myList;
ifstream myfile("booklist.txt");
string title;
string author;
Date published;
string publisher;
float price;
string isbn;
unsigned int pages;
unsigned int copies;
while( myfile ){
myList.insert_front( new Book(title, author, published, publisher,
price, isbn, pages, copies));
myfile >> title;
myfile >> author;
myfile >> publisher;
myfile >> price;
myfile >> isbn;
myfile >> pages;
myfile >> copies;
}
myList.print_list();
return 0;
}