Creating a class book

Hi, everyone I am working on this question.
Booker University maintains an inventory of books. The list includes the details: Author,price,title,book_number and number of copies of each book. Whenever new books are purchased the librarian adds the book details into the database.The chief librarian occasionally requests for a list of all books in the database.
REQUIRED:
Construct a simple class book with suitable data members and member functions to:
1.Insert a new book record into the database.
2.Display a list of all books in the database.
3.Write a main function to test the program.

This is my code for question 1.


1.#include <iostream>
2.using namespace std;
3.int main()
4.Class book;
5.{
6.
7.public
8.char author,title;
9.int price,booknumber,number of cars;
10.
11.cout<<"Enter the new book record in the database"endl;
12.cin>>author>>title;
13.cout<<"The new book record in the database you have inserted is"<<author<<title<<endl;
14.}

15.return 0;

The errors am getting are shown as below.Any help would be highly appreciated.

line3 [Error] expected initializer before 'Class'

line 5 [Error] expected unqualified-id before '{' token
1ine 14 [Error] expected unqualified-id before 'return'
C++ is case sensitive and the keyword "class" is all lower case.

Line 4 should not have a ;

Line 8: author and title only hold a single character.

Line 9: numbor of cars. You can't have spaces in a variable name. Use _.
What does number_of_cars have to do with a library system?

Line 10: You missing a }; to terminate your class.

Lines 4-10: It's conventional to place your class declaration before main.

Line 11: You need to instantiate your class.

Line 13-14: You need to reference your class instance:

Line 16: You're missing a } to terminate main.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

class Book
{
public:
    char author[20], title[20];
    int price, booknumber, number_of_cars;
};

int main()
{   Book    book;

    cout << "Enter the new book record in the database" << endl;
    cin >> book.author >> book.title;
    cout << "The new book record in the database you have inserted is" << book.author << book.title << endl;
}


PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
Do NOT number the lines yourself.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.


Topic archived. No new replies allowed.