Having some trouble with my first attempt at classes.
Write a C++ definition for an abstract data type describing a book store inventory. Each boo has the following attributes:
-book title(string)
--book author (string)
book price(floating point)
count of books on hand (integer)
The member functions are as follows:
- A constructor that is used to initialize all eight elements of the array.
- A function that displays in a readable tabular form the contents of the entire book collection
-A modify function that, once called, prompts the user first for a book numb (1-9)and then for a code (T,A,P or C) indicating which attribute(title, author, Price or count ) of the indicated book is to be changed;finally,the function should provide a prompt for the new value of the attribute.
Write the declaration for an object named inventory of the type described by the class.
Ok so I think I did my header file right, but am having a little trouble with the implementation on the .cpp file. I wrote my questions in the .cpp file. Thanks.
Header file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <string>
using namespace std;
#ifndef BSTORE_H
#define BSTORE_H
class bstore
{
public:
bstore();
bstore(int);
void title(string);
void author(string);
void price(float);
void countofbooks(int);
void tabular();
void modify();
private:
string name;
float money;
int count;
};
#endif
|
cpp file:
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 33
|
#include "hw.h"
#include <string>
#include <iostream>
using namespace std;
bstore::bstore(){
}
void bstore::title(string)
{
cout<<"Title of book: ";
cin>> name;
}
void bstore::author(string)
{
cout<<"Name of Author: "<<endl;
cin>> name;
}
void bstore::price(float)
{
cout<<"Cost of Book: "<<endl;
cin>> money;
}
void bstore::countofbooks(int)
{
cout<<"# of book: "<<endl;
cin>> count;
}
//what does it mean by a constructor it initialize all 8 elements? Is that just an array to set up all 8 books? books[7]? How would I setup such an array.
// dont know what to do for the void and tabular functions. For the tabular I think I could construct an array and store each
// book title in it and then display it.
//i think I can figure out modify once my array is setup.
|