Header Files and Classes

Hi Everyone,

I'm going through my homework and I've done almost all of it but this last question regarding header files. I was hoping someone could confirm my first function and point me in the right direction regarding function two.

The Problem:
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book has the following attributes:

Book Title (character string);
Book Author (character string);
Book Price (Floating point number having two decimal places);
Count of books on hand (int);

The member functions are as follows:
A constructor that is used to initialize all four elements of the structure to values inputted by the user;

A function that displays in a readable tabular form the contents of a book in inventory;

A modify function that has an argument a code ('T', 'A', 'P', or 'C') indicating which attribute (title,author,price or count) of the indicated book is to be changed. Based upon the attribute code, the appropriate prompt should be displayed to allow the user to enter the new value of the attribute.

I created the first function ...my header file is below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef BOOKSTORE_H
#define BOOKSTORE_H

#include <iostream>
using namespace std;

class BookStore
{
private:
	string BookTitle;
	string BookAuthor;
	float  BookPrice;
	int    BookAvail;

public:
	BookStore bookinventory (Shades, Edgar, 15, 10);
	void Display();



};
#endif

//FUNCTION VOID Display
void Bookstore::Display()
{
	cout<<"Title: "<<BookTitle<<endl;
	cout<<"Author: "<<BookAuthor<<endl;
	cout<<"Price: "<<BookPrice<<endl;
	cout<<"Availability: "<<BookAvail;
}//END VOID Display



Any helps or links to good help guides would be appreciated!
Last edited on
Line 16 is an error. You would have a statement like that in the code that will use this class. Besides, Shades is not a string literal, but "Shades" is. What you do need here is a constructor that takes four parameters (string, string, float, int).


Floating point types are weird. Currencies should use integer "fixed point" types. For your exercise, a float might suffice, but you have to do output formatting in Display(). Furthermore, Display() can be const, because it does not modify the object.

The modify function should probably have a switch statement.
Last edited on
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book has the following attributes:


Also, I could be wrong when i see the word abstract I think 'pure virtual class'. Might the intention be to eventually have different types of books deriving from this?
Last edited on
Topic archived. No new replies allowed.