C++ class help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CodecSmash49
    New Member
    • Oct 2008
    • 8

    C++ class help

    New D.I.C Head
    *

    Joined: 9 Dec, 2008
    Posts: 12


    I am currently working on an assignment where we use classes to create a program to allow info about a book be entered.

    //title, up to four authors, publisher, ISBN, price and number of copies in stock.

    I'm having a problem getting my main.cpp to read my "book."


    MAIN
    Code:
    #include <cstdlib>
    #include <iostream>
    #include "book.h"
    
    using namespace std;
    
    int menu(int);
    
    
    
    
    int main(int argc, char *argv[])
    {
        Book b;
            int year;
            int copies;
            double price;
            string title;
            string author;
            string publisher;
            string isbn;
       
        menu();
    
       
       
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    int(int choice)
    {
         cout << "Make a selection from the menu to continue." << endl;
         cout << "Enter a new book." << endl;
         cout << "Display titles of current books." << endl;
         cout << "Edit information about a current book." << endl;
         cout << "Search for a book." << endl;
         cout << "Exit." << endl;
         
         
         return choice;
         
    }
    
    void menuOpt()
    {
        if( choice = 1)
            {
             //create    
            }
        else if(choice = 2)
            {
            //display    
            }
        else if(choice = 3)
            {
                //edit
            }
        else if(choice = 4)
        {
            //search    
        }
        else
            {
                exit;
            }
             
    }
    
    void create(string, int, array[])
    {
        cout << "Enter book title: ";
        cin >> t;
        b.setTitle(t);
       
        cout << "Enter the authors name: ";
        cin >> a;
        b.setAuthor(a);
       
        cout << "Enter the publisher: ";
        cin >> pu;
        b.setPublisher(pu);
       
        cout << "Enter the isbn: ";
        cin >> i;
        b.setisbn(i);
       
        cout << "Enter the price: ";
        cin >> pi;
        b.setPrice(pi);
       
        cout << "Enter the year: ";
        cin >> y;
        b.setYear(y);
       
    }
    book.cpp
    Code:
    #include <iostream>
    #include "bookType.h"
    
    using namespace std;
    
       
             
    void  book::setTitle(string t)
    {
        title = t;
    }
    
    void book::setAuthor(string a)
    {
        author = a;
    }
    
    void book::setPublisher(string pu)
    {
        publisher = pu;
    }
    
    int book::setISBN(string i)
    {
            isbn = i;
    }
    
    double book::setPrice(double price)
    {
    
        price = pi;
    }
    
    int book::setYear(int year)
    {
        year = y;
    }
    
    int book::setCopies(int copies)
    {
        copies = c;
    }
    
    void book::display()
    {
       
    }
    
    void book::search()
    {
       
    }
    Code:
    class book
    {
    private:
    int year;
    int copies;
    double price;
    char title;
    char author;
    char publisher;
    int isbn;
    //string array[];
    
    public:
    char getTitle(string title) const;
    char getAuthor(string author) const;
    char getPublisher(string publisher) const;
    string getISBN(string isbn) const;
    double getPrice(double price) const;
    int getYear(int year) const;
    int getCopies(int copies) const;
    void display();
    void search();
    
    
    };
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    What error u are getting?
    R u getting compilation error or its not working properly?
    i see this line
    int(int choice)

    which in no way compile.


    Raghu

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      book.cpp defines a load of setter functions but book.h declares a load of getter functions.

      Comment

      Working...