Thread: getting massive compile errors, need help

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    41

    Exclamation getting massive compile errors, need help

    I need help getting my program to work.. When i compile, i get over 102 errors. I don't know why.
    Can someone look over what I have and give me some feedback as of what looks wrong so that I can
    fix it? For the set function in the book.h file, I don't know how i would set up the definition for it. Would I use cout and cin statements? Problem is at the end of code. i hope my cold tags work!

    menu.cpp file
    [\code]
    #include <cctype> // for toupper
    #include <iostream> // for cin, cout
    #include "store.h" // for class Directory

    using namespace std;

    void DisplayMenu()
    // Display the main program menu.
    {
    cout << "\n\t\t*** Bookstore Menu ***";
    cout << "\n\tA \tAdd book to inventory";
    cout << "\n\tF \tFind a book form inventory";
    cout << "\n\tS \tSell a book";
    cout << "\n\tD \tDisplay the inventory list";
    cout << "\n\tG \tGenre summary";
    cout << "\n\tM\tShow this Menu";
    cout << "\n\tX \tExit the Program";
    }

    char GetAChar(char* promptString)
    // Prompt the user and get a single character,
    // discarding the Return character.
    // Used in GetCommand.
    {
    char response; // the char to be returned

    cout << promptString; // Prompt the user
    cin >> response; // Get a char,
    response = toupper(response); // and convert it to uppercase
    cin.get(); // Discard newline char from input.
    return response;
    }

    char Legal(char c)
    // Determine if a particular character, c, corresponds
    // to a legal menu command. Returns 1 if legal, 0 if not.
    // Used in GetCommand.
    {
    return ((c == 'A') || (c == 'F') || (c == 'S') || (c == 'D') ||
    (c == 'G') || (c == 'M') || (c == 'X'));
    }

    char GetCommand()
    // Prompts the user for a menu command until a legal
    // command character is entered. Return the command character.
    // Calls GetAChar, Legal, ShowMenu.
    {
    char cmd = GetAChar("\n\n>"); // Get a command character.

    while (!Legal(cmd)) // As long as it's not a legal command,
    { // display menu and try again.
    cout << "\nIllegal command, please try again . . .";
    ShowMenu();
    cmd = GetAChar("\n\n>");
    }
    return cmd;
    }

    int main()
    {
    Menu m; // Create and initialize a new directory.

    ShowMenu(); // Display the menu.

    char command; // menu command entered by user
    do
    {
    command = GetCommand(); // Retrieve a command.
    switch (command)
    {
    case 'A': m.Addt(); break;
    case 'F': m.Find(); break;
    case 'S': m.Sell(); break;
    case 'D': m.Display(); break;
    case 'G': m.genre(); break;
    case 'M': ShowMenu(); break;
    case 'X': break;
    }
    } while (command != 'X');
    }
    [code]



    [\code]

    //Given by instructor, must not be modified
    // book.h -- header file for the Book class
    //
    // An object of type Book will store information about a single
    // book. The variable "type" stores the category of the book
    // (one of the four items in the enumerated type Genre).

    #ifndef _BOOK_H
    #define _BOOK_H

    #include <iostream>

    using namespace std;

    enum Genre {FICTION, MYSTERY, SCIFI, COMPUTER};

    class Book
    {
    public:
    Book(); // default constructor, sets up blank book object

    void Set(char* t, char* a, Genre g, double p);

    // the Set function should allow incoming data to be received through
    // parameters and loaded into the member data of the object. (i.e.
    // this function "sets" the state of the object to the data passed in).
    // The parameters t, a, g, and p represent the title, author, genre,
    // and price of the book, respectively.

    const char* GetTitle(); // returns the title stored in the object
    const char* GetAuthor(); // returns the author
    double GetPrice(); // returns the price
    Genre GetGenre(); // returns the genre

    void Display(); // described below

    private:
    char title[31]; // may assume title is 30 characters or less
    char author[21]; // may assume author name is 20 characters or less
    Genre type;
    double price;
    };

    /* Display() function

    The member function Display() should print out a Book object on one line
    as follows, in an organized manner. (Monetary output should be in dollars
    and cents notation, to two decimal places):
    Title Author Genre Price

    Examples:
    Programming for Dummies Marvin Dipwart Computer $ 24.95
    Mutant Space Weasels Bob Myers Sci-Fi $ 5.95

    */

    #endif
    [code]

    book.cpp file
    [\code]

    #include <iostream>
    #include <cstring> // for strlen, strcpy
    #include "book.h" // for class Entry

    using namespace std;


    Book::Book()
    {
    strcpy(title, " ");
    strcpy(author, " ");
    strcpy(type, " ");
    strcpy(price, " ");
    }

    void Book::Set(char* t ,char* a, Genre g, double p)
    // allows us to read in the data from the keyboard
    {
    cout << "\nType name of book, followed by RETURN or ENTER: ";
    cin.getline(title, 31);

    cout << "\nType name of author, followed by RETURN or ENTER: ";
    cin.getline(author, 21);

    cout << "\nType genre of book, followed by RETURN or ENTER: ";
    cin.getline(type, 20);

    char*Book::GetTitle() const
    {
    return title;
    }

    char*Book::GetAuthor() const
    {
    return author;
    }

    double Book::GetPrice()
    {
    return Price;
    }

    Genre Book::GetGenre()
    {
    return type;
    }

    void Book:isplay()
    {
    int i;

    cout << '\t' << Title;
    for (i = strlen(title) + 1; i < 31; i++)
    cout.put(' ');

    cout << '\t' << Author;
    for (i = strlen(author) + 1; i < 21; i++)
    cout.put(' ');

    cout << '\t' << Genre;
    cout << '\n';

    cout<<'\t'<<Price;
    cout<<'\n';
    }
    [code]



    store class

    [\code]

    #ifndef _STORE_H
    #define _STORE_H

    #include "book.h"

    class Store
    {
    public:
    Store();
    ~Store();
    void Add();
    void Find();
    void Sell();
    void Display();
    void Genre(); /
    void ShowMenu();
    void Exit();

    private:
    int maxSize, // the maximum allowable number of entries
    currentSize; // the current number of entries
    Entry* entryList; // pointer to the list of entries
    void Grow(); // Increase maximum size, when required.
    int FindBook(char* aBook); // Return index of an entry, given a name.
    };

    [code]


    store.cpp file

    [\code]

    #include <iostream>
    #include <cstring>
    #include "book.h"

    using std::cout;
    using std::cin;

    Store::Store()

    {
    maxSize = 20;
    currentSize = 0;
    entryList = new Entry[maxSize];
    }

    Store::~Store()
    // This destructor function for class Store
    // deallocates the menu's list of Entry objects.
    {
    delete [] entryList;
    }

    void Store::Add()
    // Insert a new entry into the store.
    {
    if (currentSize == maxSize) // If the directory is full, grow it.
    Grow();
    entryList[currentSize++].Load(); // read new entry.
    }

    void Store::Find()
    {

    char aBook[20];
    cout << "\tType the title of the book to be looked up, followed by <Enter>: ";
    cin.getline(aBook, 31);

    int thisEntry = FindBook(aBook);

    if (thisEntry == -1)
    cout << aBook << " not found in current menu\n";
    else
    {
    cout << "\nEntry found: ";
    entryList[thisEntry].Show(); // display entry.
    }
    }

    void Store::Sell()

    {

    char aBook[31];
    cout << "\nType title to be removed, followed by <Enter>: ";
    cin.getline(aBook, 31);

    int thisEntry = FindBook(aBook);

    if (thisEntry == -1)
    cout << aBook << " not found in directory";
    else
    {
    // Shift each succeding element "down" one position in the
    // Entry array, thereby deleting the desired entry.
    for (int j = thisEntry + 1; j < currentSize; j++)
    entryList[j - 1] = entryList[j];

    currentSize--; // Decrement the current number of entries.
    cout << "Entry removed.\n";
    }
    }

    void Store:isplay()

    {
    if (currentSize == 0)
    {
    cout << "\nStore is currently empty.\n";
    return;
    }

    // Display a header.
    cout << "\n\t***Title***\t\t***Author***\t\t***Genre***\t\ t***Price***\n\n";

    for (int i = 0; i < currentSize; i++) // For each entry,
    entryList[i].Show(); // send it to output
    }

    void Store::Grow()
    // Double the size of the store's entry list
    // by creating a new, larger array of entries
    // and changing the store's pointer to refer to
    // this new array.
    {
    maxSize = currentSize + 5; // Determine a new size.
    Entry* newList = new Entry[maxSize]; // Allocate a new array.

    for (int i = 0; i < currentSize; i++) // Copy each entry into
    newList[i] = entryList[i]; // the new array.

    delete [] entryList; // Remove the old array
    entryList = newList; // Point old name to new array.
    }

    int Store::FindBook(char* aBook)
    // Locate a book in the store. Returns the
    // position of the entry list as an integer if found.
    // and returns -1 if the entry is not found in the directory.
    {
    for (int i = 0; i < currentSize; i++) // Look at each entry.
    if (strcmp(entryList[i].GetTitle(), aBook) == 0)
    return i; // If found, return position and exit.

    return -1; // Return -1 if never found.
    }

    [code]

    Task: You will be writing classes that implement an inventory list simulation for a bookstore. The list will be a dynamic array of Book objects, each of which stores several pieces of information about a book. You will need to finish the writing of two classes: Book and Store. The full header file for the Book class has been provided in a file called book.h. You can get a copy of it here.

    Program Details and Requirements:

    1) Using the Book class declaration, write the book.cpp file and define all of the member functions that are declared in the file book.h. (Do not change book.h in any way. Just take the existing class interface and fill in the function definitions). Notice that there are only four genres of books in this class: FICTION, MYSTERY, SCIFI, and COMPUTER. The expected functions behaviors are described in the comments of this header file.

    2) Write a class called Store (filenames are store.h and store.cpp). A Store object should contain at least the following information: the amount of money in the store cash register and a book inventory list. There is no size limit to the inventory list, so it should be implemented with a dynamically allocated array. (This means you'll need an array of Book objects). You can add any public or private functions into the Store class that you feel are helpful. In addition to the Store class itself, you will also create a menu program to manage the inventory of books. However, the Store class will be able to do much of the work, as the Store member functions will be the interface between the menu program and the internally stored data (cash register and list of books).

    Rules for the Store class:

    All member data of class Store must be private
    There should be no cin statements inside the Store class member functions. To ensure the class is more versatile, any user input (i.e. keyboard) described in the menu program below should be done in the menu program itself. Design the Store class interface so that any items of outside information are received through parameters of the public member functions.
    The list of Books must be implemented with a dynamically allocated array. There should never be more than 5 unused slots in this array (i.e. the number of allocated spaces may be at most 5 larger than the number of slots that are actually filled with real data). This means that you will need to ensure that the array allocation expands or shrinks at appropriate times. Whenever the array is resized, print a message (for testing purposes) that states that the array is being resized, and what the new size is. Example: "** Array being resized to 10 allocated slots".
    Since dynamic allocation is being used inside the Store class, an appropriate destructor must be defined, to clean up memory. The class must not allow any memory leaks
    3) Write a main program (filename menu.cpp) that creates a single Store object and then implements a menu interface to allow interaction with the object. The program should begin by asking the user to input the starting amount of money in the store's cash register (as a double). This should be stored in the Store object. Your main program should implement the following menu loop (any single letter options should work on both lower and upper case inputs):

    A: Add a book to inventory
    F: Find a book from inventory
    S: Sell a book
    D: Display the inventory list
    G: Genre summary
    M: Show this Menu
    X: eXit the program

    Behavior of menu selections:

    Always ask for user input in the order specified. Remember, all user inputs described in the menu options below should be done by the menu program (not inside the Store class). (And remember, while the user input is done in the menu program, you will probably find that it is easiest to send this information into the Store class and let the Store member functions do most of the actual work, since they will have access to the book list and cash register). For all user inputs, assume the following:

    a book title and author will always be input as strings, of maximum lengths 30 and 20, respectively. You may assume that the user will not enter more characters than the stated limits for these inputs.
    when asking for the genre, user entry should always be a single character. The correct values are F, M, S, and C - for fiction, mystery, sci-fi, and computer, respectively. Uppercase and lowercase inputs should both be accepted. Whenever the user enters any other character for the genre, this is an error -- print an error message and prompt the user to enter the data again (Example error message: "Invalid genre entry. Please re-enter: ").
    user input of the price should be a positive double. You may assume that the user will enter a double. Whenever the user enters a number that is not positive, it is considered an error -- so an error message should be printed and the user should be prompted to re-enter the price. (Example: "Must enter a positive price. Please re-enter: ").
    User input of menu options are letters, and both upper and lower case entries should be allowed.
    A: This menu option should allow the adding of a book to the inventory list. The user will need to type in the book's information. Prompt and allow the user to enter the information in the following order: title, author, genre, price. The information should be sent into the Store object and stored in the list of books.
    F: This option should allow the user to search for a book in the inventory list by title or by author. When this option is selected, ask the user to enter a search string (may assume user entry will be a string 30 characters or less). If the search string matches a book title, display the information for that book (output format is described in the Display function of the Book class). If the search string matches an author in the list, display the information for all books by that author. If no matching books are found, display an appropriate message informing the user.

    S: This option should allow a sale to be made. When this option is selected, ask the user to type in the title of the book (you may assume that book titles in the list will be unique). Remove this book from the inventory list, and since it is being purchased, add the purchase price into the store's cash register. If there is no such title, inform the user and return to the menu.

    D: This option should simply display the entire inventory list, one line per book, in an organized manner (like a table). Each line should contain one book's information, as described in the book.h file. Also, display the total number of books in the inventory list, as well as the current amount of money in the store cash register.

    G: This option should list the inventory contents for one specific genre. When this option is selected, ask the user to input a genre. For the category selected, print out the contents of the inventory list, as in the Display option, but for the books matching the selected genre only. (e.g. list all of the Mystery books). After this, also display the total quantity, as well as the total cost (the sum of the prices), of the books in this genre.

    M: Re-display the menu.
    X: Exit the menu program. Upon exiting, print out the final amount of money in the store cash register.


    5) General Requirements:

    An invalid menu selection should produce an appropriate output message to the user, like "Not a valid option, choose again."
    For all of these options, any output to the screen should be user-friendly. By this, assume that the user of the program has never seen it before. All output should clearly indicate what information is being presented, and the user should always be told what is expected in terms of input.
    Adhere to the good programming practices discussed in class. (No global variables, other than constants or enumerations. Don't #include .cpp files. Document your code. etc).
    You may use the following libraries: iostream.h, iomanip.h, string.h, ctype.h
    All monetary output to the screen should be in dollars and cents notation, with the $. (Example: $ 20.50). Hint: For printing out money values in dollars and cents, you'll need to print out to two decimal places. You can use the setprecision and setiosflags functions from the iomanip library for this. The following is an example that illustrates the use of these functions.
    double amount = 34.6751
    cout << setprecision(2) << setiosflags(ios::fixed) << amount;
    // x will now print to two decimal places: 34.68

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    You probably don't really have 100 errors!

    Sorry, but this is going to be a vague-general suggestion...

    Compilers can easily get confused. You probably don't have 100 errors! One misplaced bracket or missing semicolon can generate 100 error messages. (Usually the line indicated in the first error is "close" to the actual first error.)

    Write small sections of code. Compile and test as you add sections. This way you can locate the errors before your program grows too big.

    It takes a bit of practice to learn how to do this... where to start... what small section will compile correctly, and which sections / functions should be added next.

    It also helps to add some extra cout statements to display some variables, or some messages saying "where you are". As each section / function of code is completed and is working, you can take-out the extra cout statements.

    Sometimes I start with an "empty" function that may return some constant number (return 1;). And/or it will have cout << "In FunctionOne"; Then, when everything compiles correctly, and I know I'm actually calling the function, I'll add the real body to the function.

    These techniques are NOT 100% foolproof. I've been burned by a simple little cut-and-paste edit which caused a misplaced bracket and hundreds of reported errors! I had to go back to a previously saved version start-over from there.


    P.S.
    You're close with the code tags:

    [ code ] // No slash at the start

    Your program..
    I added spaces before and after the brackets so you could see them. Leave out the spaces when you use 'em for real.

    [ /code ] // Forward slash at the end

    [EDIT]
    When you're posting code, click the checkbox under "options" that says "Disable smilies in this post". That way you wont get unexpected faces in your code! :) See... no Smiley faces! :)
    Last edited by DougDbug; 03-20-2003 at 01:20 AM.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    41

    Unhappy i need help badly

    Okay, i tried going through class by class and cpp file by cpp file to catch errors but i'm still geting a few and i don't know what to do. the book.h file was given my the professor so it should be correct. Some questions: How do I set up the definition for the void Set funtion in the book.h file? How would I use the price function? Like, is it correct how I have it. Can someone just take a look at my code please and try to tell me what I'm doing wrong without doing the work for me?

    The problem statement is in the previous post.

    Here's my code with code tags (hopefully they work this time)



    book.h file given by professor
    Code:
    #ifndef _BOOK_H
    #define _BOOK_H
    
    #include <iostream>
    
    using namespace std;
    
    enum Genre {FICTION, MYSTERY, SCIFI, COMPUTER};
    
    class Book
    {
    public:
      Book();		// default constructor, sets up blank book object
    
    #ifndef _BOOK_H
    #define _BOOK_H
    
    #include <iostream>
    
    using namespace std;
    
    enum Genre {FICTION, MYSTERY, SCIFI, COMPUTER};
    
    class Book
    {
    public:
      Book();		// default constructor, sets up blank book object
    
      void Set(char* t, char* a, Genre g, double p);
    
      // the Set function should allow incoming data to be received through
      //  parameters and loaded into the member data of the object.  (i.e.
      //  this function "sets" the state of the object to the data passed in).
      //  The parameters t, a, g, and p represent the title, author, genre, 
      //  and price of the book, respectively.
    
      const char* GetTitle();	// returns the title stored in the object
      const char* GetAuthor();	// returns the author
      double GetPrice();		// returns the price
      Genre GetGenre();		// returns the genre
    
      void Display();		// described below
    
    private:
      char title[31];	// may assume title is 30 characters or less
      char author[21];	// may assume author name is 20 characters or less
      Genre type;
      double price;
    };
    
    /* Display() function
    
    The member function Display() should print out a Book object on one line 
    as follows, in an organized manner. (Monetary output should be in dollars
    and cents notation, to two decimal places):
    Title		              Author		  Genre		Price
    
    Examples:
    Programming for Dummies       Marvin Dipwart      Computer   $  24.95
    Mutant Space Weasels          Bob Myers           Sci-Fi     $   5.95
    
    */ 
    
    #endif
    store.h file
    Code:
    #ifndef _STORE_H
    #define _STORE_H
    //#include "book.h"
    #include "menu.cpp"
    
    class Store
    {
    public:
       Store();			
       ~Store();		
       void Add();		
       void Find();		
       void Sell();		
       void Display();		
       void Genre();	
       void ShowMenu();
       void Exit();
    
    private:
       int	maxSize,		
    	currentSize;		
       Entry* entryList;		
       void Grow();			
       int FindBook(char* aBook);	
    };
    #endif

    menu.cpp file
    Code:
    #include <cctype>			// for toupper
    #include <iostream>		// for cin, cout
    #include "store.h"		// for class Directory
    
    using namespace std;
    
    void DisplayMenu()
    // Display the main program menu.
    {
       cout << "\n\t\t*** Bookstore Menu ***";
       cout << "\n\tA \tAdd book to inventory";
       cout << "\n\tF \tFind a book form inventory";
       cout << "\n\tS \tSell a book";
       cout << "\n\tD \tDisplay the inventory list";
       cout << "\n\tG \tGenre summary";
       cout << "\n\tM\tShow this Menu";
       cout << "\n\tX \tExit the Program";
    }
    
    char GetAChar(char* promptString)
    // Prompt the user and get a single character,
    // discarding the Return character.
    // Used in GetCommand.
    {
       char response;			// the char to be returned
    	
       cout << promptString;		// Prompt the user
       cin >> response;			// Get a char,
       response = toupper(response);	// and convert it to uppercase
       cin.get();				// Discard newline char from input.
       return response;
    }
    
    char Legal(char c)
    // Determine if a particular character, c, corresponds
    // to a legal menu command.  Returns 1 if legal, 0 if not.
    // Used in GetCommand.
    {
    	return	((c == 'A') || (c == 'F') || (c == 'S') || (c == 'D') ||
    			 (c == 'G') || (c == 'M') || (c == 'X'));
    }
    
    char GetCommand()
    // Prompts the user for a menu command until a legal 
    // command character is entered.  Return the command character.
    // Calls GetAChar, Legal, ShowMenu.
    {
       char cmd = GetAChar("\n\n>");	// Get a command character.
    	
       while (!Legal(cmd))		// As long as it's not a legal command,
       {				// display menu and try again.
    	cout << "\nIllegal command, please try again . . .";
    	ShowMenu();
    	cmd = GetAChar("\n\n>");
       }
       return cmd;
    }
    
    void main()
    {
       Menu m;			// Create and initialize a new directory.
    	
       ShowMenu();				// Display the menu.
    	
       char command;			// menu command entered by user
       do
       {
    	command = GetCommand();		// Retrieve a command.
    	switch (command)
    	{
    		case 'A': m.Add();				break;
    		case 'F': m.Find();				break;
    		case 'S': m.Sell();				break;
    		case 'D': m.Display();				break;
    		case 'G': m.genre();	break;
    	    case 'M': ShowMenu();				break;
    		case 'X':					break;
    	}
       } while (command != 'X');
    }
    Store.cpp
    Code:
    #include <iostream>
    #include <cstring>		
    //#include "book.h"
    #include "store.h"
    
    using namespace std;
    Store::Store()			
    
    { 
       maxSize = 20; 
       currentSize = 0; 
       entryList = new Entry[maxSize];
    }
    
    Store::~Store()
    // This destructor function for class Store
    // deallocates the menu's list of Entry objects.
    {
       delete [] entryList;
    }
    
    void Store::Add()
    // Insert a new entry into the store.
    {
       if (currentSize == maxSize)		// If the directory is full, grow it.
     Grow();
       entryList[currentSize++].Load();	// read new entry.
    }
    
    void Store::Find()
    {
       
       char aBook[20];
       cout << "\tType the title of the book to be looked up, followed by <Enter>: ";
       cin.getline(aBook, 31);
    	
       int thisEntry = FindBook(aBook);	
    	
       if (thisEntry == -1)
    	cout << aBook << " not found in current menu\n";
       else
       {
    	cout << "\nEntry found: ";
    	entryList[thisEntry].Show();	// display entry.
       }
    }
    
    void Store::Sell()
    
    {
      
       char aBook[31];
       cout << "\nType title to be removed, followed by <Enter>: ";
       cin.getline(aBook, 31);
    	
       int thisEntry = FindBook(aBook);	
    	
       if (thisEntry == -1)
    	cout << aBook << " not found in directory";
       else
       {
    	// Shift each succeding element "down" one position in the
    	// Entry array, thereby deleting the desired entry.
    	for (int j = thisEntry + 1; j < currentSize; j++)
    		entryList[j - 1] = entryList[j];
    			
    	currentSize--;		// Decrement the current number of entries.
    	cout << "Entry removed.\n";
       }
    }
    
    void Store::Display()
    
    {
       if (currentSize == 0)
       {
    	cout << "\nStore is currently empty.\n";
    	return;
       }
    	
       // Display a header.
       cout << "\n\t***Title***\t\t***Author***\t\t***Genre***\t\t***Price***\n\n";
    	
       for (int i = 0; i < currentSize; i++)	// For each entry,
    	entryList[i].Show();			// send it to output
    }
    
    void Store::Grow()
    // Double the size of the store's entry list
    // by creating a new, larger array of entries
    // and changing the store's pointer to refer to
    // this new array.
    {
       maxSize = currentSize + 5;			// Determine a new size.
       Entry* newList = new Entry[maxSize];		// Allocate a new array.
    	
       for (int i = 0; i < currentSize; i++)	// Copy each entry into
    	newList[i] = entryList[i];		// the new array.
    		
       delete [] entryList;			// Remove the old array
       entryList = newList;			// Point old name to new array.
    }
    
    int Store::FindBook(char* aBook)
    // Locate a book in the store.  Returns the
    // position of the entry list as an integer if found.
    // and returns -1 if the entry is not found in the directory.
    {
       for (int i = 0; i < currentSize; i++)	// Look at each entry.
    	if (strcmp(entryList[i].GetTitle(), aBook) == 0)
    		return i;		// If found, return position and exit.
    			
       return -1;				// Return -1 if never found.
    }
    Book.cpp file

    Code:
    #include <iostream>
    #include <cstring>			// for strlen, strcpy
    //#include "book.h"			// for class Entry
    using namespace std;
    
    
    
    Book::Book()
    // This constructor for class Entry initializes the name, phone number,
    // and room number to be blank strings.
    {
       strcpy(title, " ");
       strcpy(author, " ");
       strcpy(type, " ");
       //strcpy(price, " ");
    }
    
    void Book::Set( char* t, char* a, Genre g, double p )
    // allows us to read in the data from the keyboard
    {
       cout << "\nType title, followed by RETURN or ENTER: ";
       cin.getline(t, 31);		
    
       cout << "\nType name of author, followed by RETURN or ENTER: ";
       cin.getline(a, 21);	
    
       cout << "\nType price of book, followed by RETURN or ENTER: ";
       cin.getline(p);		
    }
    
    char*Book::GetTitle() const
    {
    return title;
    }
    
    char*Book::GetAuthor() const
    {
    return author;
    }
    
    double Book::GetPrice()
    {
    return price;
    }
    
    enum Book::GetGenre() 
    {
    return type;
    }
    
    void Book::Display()
    {
       int i;
    	
       cout << '\t' << Title;		// Display name (after tabbing).
       // Display remaining blanks, so that data lines up on screen.
       for (i = strlen(title) + 1; i < 31; i++)
    	cout.put(' ');
    	
       cout << '\t' << Author;		// Display phone number.
       for (i = strlen(author) + 1; i < 20; i++)
    	cout.put(' ');
    	
       cout << '\t' << Genre;	
       cout << '\n';
    
       cout<<'\t'<<Price;
      cout<<'\n';
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange compile errors
    By csonx_p in forum C++ Programming
    Replies: 10
    Last Post: 07-28-2008, 11:41 AM
  2. compile once, compile twice ...error
    By Benzakhar in forum Windows Programming
    Replies: 6
    Last Post: 12-28-2003, 06:00 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM