Hi,
I have to write an airline ticket program for my class. My instructor gave us an example of a similar program so I thought I would build and run it to help me understand it better but he seems to have given us code for a program that doesn't even build right. I can usually fix build errors by reading the build report but I've not been able to understand just what it wants from me. Can anyone help me out so I can move on to my actual assignment? Here's the code my instructor provided that I can't get to build.
/**
* BookRecord.h
*/
#ifndef _BOOK_RECORD_H_
#define _BOOK_RECORD_H_
#include <iostream>
#include <string>
using namespace std;
class BookRecord
{
public:
BookRecord();
BookRecord(const BookRecord &bookRecord);
~BookRecord();
void setIsbn(string isbn);
string getIsbn() const;
void setAuthor(string author);
string getAuthor() const;
void setTitle(string title);
string getTitle() const;
void setYear(string year);
string getYear() const;
void setPublisher(string publisher);
string getPublisher() const;
private:
string isbn;
string author;
string title;
string year;
string publisher;
};
#endif
/**
* BookRecord.cpp
*/
#include "BookRecord.h"
BookRecord::BookRecord()
{
// Currently does nothing ...
}
// Copy constructor
BookRecord::BookRecord(const BookRecord &bookRecord)
{
isbn = bookRecord.isbn;
author = bookRecord.author;
title = bookRecord.title;
year = bookRecord.year;
publisher = bookRecord.publisher;
}
BookRecord::~BookRecord()
{
// Currently does nothing ...
}
void BookRecord::setIsbn(string isbn)
{
this->isbn = isbn;
}
string BookRecord::getIsbn() const
{
return isbn;
}
void BookRecord::setAuthor(string author)
{
this->author = author;
}
string BookRecord::getAuthor() const
{
return author;
}
void BookRecord::setTitle(string title)
{
this->title = title;
}
string BookRecord::getTitle() const
{
return title;
}
void BookRecord::setYear(string year)
{
this->year = year;
}
string BookRecord::getYear() const
{
return year;
}
void BookRecord::setPublisher(string publisher)
{
this->publisher = publisher;
}
string BookRecord::getPublisher() const
{
return publisher;
}
/**
* Main.cpp
*/
#include <fstream>
#include <iostream>
#include <list>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "BookRecord.h"
using namespace std;
//
// Prototype declarations
//
void menu();
void add_book();
void delete_book();
void display_book_inventory();
//
// Declare the book list and an STL linked list variable
// list <BookRecord> book_list;
// Main program. Calls the functions to load the address book into
// memory then launches the user menu.
//
int main(int argc, char **argv)
{
menu();
return 0;
}
//
// This function adds a record to the linked list.
//
void add_book()
{
BookRecord book_record;
string tmpstr;
cout << endl << "** ADD BOOK TO INVENTORY **" << endl << endl;
getline(cin, tmpstr); // Ignore the first CR
cout << "ISBN> ";
getline(cin, tmpstr, '\n');
book_record.setIsbn(tmpstr);
cout << "Author> ";
getline(cin, tmpstr, '\n');
book_record.setAuthor(tmpstr);
cout << "Title> ";
getline(cin, tmpstr, '\n');
book_record.setTitle(tmpstr);
cout << "Year> ";
getline(cin, tmpstr, '\n');
book_record.setYear(tmpstr);
cout << "Publisher> ";
getline(cin, tmpstr, '\n');
book_record.setPublisher(tmpstr);
// Add to the linked list
book_list.push_back(book_record);
return;
}
//
// This function deletes a book from the linked list based on the given
// ISBN.
//
void delete_book()
{
cout << endl << "** DELETE BOOK FROM INVENTORY **" << endl << endl;
string tmp_isbn_str;
bool found_entry = false;
BookRecord book_record;
cout << "ISBN> ";
cin >> tmp_isbn_str;
list<BookRecord>::iterator i;
for (i = book_list.begin(); i != book_list.end(); ++i)
{
book_record = *i;
if (book_record.getIsbn() == tmp_isbn_str)
{
found_entry = true;
i = book_list.erase(i);
}
}
if (found_entry)
cout << "Entry deleted." << endl;
else
cout << "Entry not found." << endl;
return;
}
//
// This function displays all of the books that are contained in the
// linked list.
//
void display_book_inventory()
{
cout << endl << "** DISPLAY BOOK INVENTORY **" << endl << endl;
string continue_display;
BookRecord book_record;
list<BookRecord>::iterator i;
int j=0;
for (i = book_list.begin(); i != book_list.end(); ++i, j++)
{
book_record = *i;
cout << "ISBN: " << book_record.getIsbn() << endl;
cout << "Author: " << book_record.getAuthor() << endl;
cout << "Title: " << book_record.getTitle() << endl;
cout << "Publisher: " << book_record.getPublisher() << endl;
cout << "---------------------------------------------" << endl;
// Print the first 10 record, then ask the user if he/she wants
// to continue displaying ...
if (j != 0 && j % 10 == 0 )
{
cout << "Continue Display? (y,n) ";
cin >> continue_display;
if (strncmp(continue_display.c_str(), "y", 2))
{
return;
}
// Print the separator bar again
cout << "---------------------------------------------" << endl;
}
}
return;
}
//
// This function provides the main menu for the user, and display the // options and accepts user input.
//
void menu()
{
char option[3];
bool exit_program = false;
while (!exit_program)
{
// Allow the user to select options to add, delete, modify, and
// list all data in the address book.
cout << endl << "** BOOK INVENTORY V1.0 MAIN MENU **" << endl << endl;
cout << " 1. Add entry" << endl;
cout << " 2. Delete entry" << endl;
cout << " 3. Display entries" << endl;
cout << endl << " 99. Exit program" << endl << endl;
cout << "Option> ";
cin >> option;
// Process user entry
switch (atoi(option))
{
case 1:
add_book();
break;
case 2:
delete_book();
break;
case 3:
display_book_inventory();
break;
// Save address book and then exit program
case 99:
exit_program = true;
break;
default:
cerr << "Error: unknown option!" << endl;
break;
}
}
return;
}
Here's the build report if that might make things any clearer:
1>------ Build started: Project: Book Program, Configuration: Debug Win32 ------
1>Compiling...
1>Main.cpp
1>c:\users\bj\school\data structures and algorithms\book program\book program\main.cpp(74) : error C2065: 'book_list' : undeclared identifier
1>c:\users\bj\school\data structures and algorithms\book program\book program\main.cpp(74) : error C2228: left of '.push_back' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\bj\school\data structures and algorithms\book program\book program\main.cpp(95) : error C2065: 'book_list' : undeclared identifier
1>c:\users\bj\school\data structures and algorithms\book program\book program\main.cpp(95) : error C2228: left of '.begin' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\bj\school\data structures and algorithms\book program\book program\main.cpp(95) : error C2065: 'book_list' : undeclared identifier
1>c:\users\bj\school\data structures and algorithms\book program\book program\main.cpp(95) : error C2228: left of '.end' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\bj\school\data structures and algorithms\book program\book program\main.cpp(102) : error C2065: 'book_list' : undeclared identifier
1>c:\users\bj\school\data structures and algorithms\book program\book program\main.cpp(102) : error C2228: left of '.erase' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\bj\school\data structures and algorithms\book program\book program\main.cpp(127) : error C2065: 'book_list' : undeclared identifier
1>c:\users\bj\school\data structures and algorithms\book program\book program\main.cpp(127) : error C2228: left of '.begin' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\bj\school\data structures and algorithms\book program\book program\main.cpp(127) : error C2065: 'book_list' : undeclared identifier
1>c:\users\bj\school\data structures and algorithms\book program\book program\main.cpp(127) : error C2228: left of '.end' must have class/struct/union
1> type is ''unknown-type''
1>Build log was saved at "file://c:\Users\BJ\School\Data Structures and Algorithms\Book Program\Book Program\Debug\BuildLog.htm"
1>Book Program - 12 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========