F
fakeprogress
For a homework assignment in my Data Structures/C++ class, I have to
create the interface and implementation for a class called Book, create
objects within the class, and process transactions that manipulate (and
report on) members of the class.
Interface consists of:
- 5 private variables
char author[20];
char title[25];
char code[4];
int ncopies; // number of copies owned
int onloan; // number of copies currently on loan
- 5 public methods + 2 other methods
char *getAuthor; // returns (a pointer to) the author's name
char *getTitle; // returns (a pointer to) the title
char *getCode; // returns (a pointer to) the code of the book
int getNcopies; // returns the number of copies owned by the
library
int getOnLoan; // returns the number of copies currently on
loan
void Borrow( int ); // fixed number of copies are borrowed
void nReturn( int ); // returns fixed number of copies
- 2 required constructors + 1 optional constructor
Book( auth, tit, cd, ncop ) // creates an object of type Book
with the info specified & assumes number of copies on loan is 0
Book( auth, tit, cd, ncop, nonloan ) // creates an object of
type Book with the info specified
Book( ) // allows you to declare objects of type Book without
initializing any values
* There is an initial file of information (called initbooks) that
contains the information for the initial library. This information is
stored on a file (and is not to be keyed in individually). Write a
function ReadLibrary that will read the input file and create a book
for each line of information read. As each data line is read, you
should allocate a new record (possibly from within an available array)
and initialize the data.
Each data line contains an author, title, code, and number of copies.
Some data lines contain information regarding the number of copies
currently on loan. You should call the appropriate constructor and
intialize the book to the type of data input.
* There is a file of transactions (called trans) containing
transactions to be processed. Each transaction contains the following:
transaction type: b (borrow) or r (return)
account number: book code
amount: number of copies to be borrowed/returned
The appropriate object (book) corresponding to the book code should be
located. The balance should be updated by the amount input. The update
should be an increase (in the case of a deposit) or a decrease (in the
case of a withdrawal).
Write a function ProcessTransactions that will read the file trans and
process the transactions (and create a log).
* Write a function printFull. This function will print the inventory of
books held, including the author, title, code, number of copies in
holding, and number of copies available. The sequence of this report
should be in the sequence of the actual array at the time that it is
printed.
* Write a main function that will initialize the system and declare
whatever variables are needed. You should create an array of objects of
type Book (max size = 25). The main function should call the following
functions:
ReadLibrary
printFull
ProcessTransactions
printFull
--------------------
Now. I am NOT asking anyone to do this assignment for me. I needed to
type all that out so that one would know exactly what I'm talking about
and be of greater assistance
My question is with the methods I am supposed to write. For example, is
char *getAuthor simply as easy as
char Book :: getAuthor( ) {
return *author;
}
(is that even correct?)
....or am I missing a major point here?
My professor's lesson on classes & objects leaves much to be desired.
Turning to the textbook was no help, either, because he's actually one
of the author's of the book... and he pretty much teaches directly from
the text.
I apologize if my question is silly... but, really, I'm struggling and
don't know where else to turn.
Thank you so much for whatever input you can provide
--Allie
create the interface and implementation for a class called Book, create
objects within the class, and process transactions that manipulate (and
report on) members of the class.
Interface consists of:
- 5 private variables
char author[20];
char title[25];
char code[4];
int ncopies; // number of copies owned
int onloan; // number of copies currently on loan
- 5 public methods + 2 other methods
char *getAuthor; // returns (a pointer to) the author's name
char *getTitle; // returns (a pointer to) the title
char *getCode; // returns (a pointer to) the code of the book
int getNcopies; // returns the number of copies owned by the
library
int getOnLoan; // returns the number of copies currently on
loan
void Borrow( int ); // fixed number of copies are borrowed
void nReturn( int ); // returns fixed number of copies
- 2 required constructors + 1 optional constructor
Book( auth, tit, cd, ncop ) // creates an object of type Book
with the info specified & assumes number of copies on loan is 0
Book( auth, tit, cd, ncop, nonloan ) // creates an object of
type Book with the info specified
Book( ) // allows you to declare objects of type Book without
initializing any values
* There is an initial file of information (called initbooks) that
contains the information for the initial library. This information is
stored on a file (and is not to be keyed in individually). Write a
function ReadLibrary that will read the input file and create a book
for each line of information read. As each data line is read, you
should allocate a new record (possibly from within an available array)
and initialize the data.
Each data line contains an author, title, code, and number of copies.
Some data lines contain information regarding the number of copies
currently on loan. You should call the appropriate constructor and
intialize the book to the type of data input.
* There is a file of transactions (called trans) containing
transactions to be processed. Each transaction contains the following:
transaction type: b (borrow) or r (return)
account number: book code
amount: number of copies to be borrowed/returned
The appropriate object (book) corresponding to the book code should be
located. The balance should be updated by the amount input. The update
should be an increase (in the case of a deposit) or a decrease (in the
case of a withdrawal).
Write a function ProcessTransactions that will read the file trans and
process the transactions (and create a log).
* Write a function printFull. This function will print the inventory of
books held, including the author, title, code, number of copies in
holding, and number of copies available. The sequence of this report
should be in the sequence of the actual array at the time that it is
printed.
* Write a main function that will initialize the system and declare
whatever variables are needed. You should create an array of objects of
type Book (max size = 25). The main function should call the following
functions:
ReadLibrary
printFull
ProcessTransactions
printFull
--------------------
Now. I am NOT asking anyone to do this assignment for me. I needed to
type all that out so that one would know exactly what I'm talking about
and be of greater assistance
My question is with the methods I am supposed to write. For example, is
char *getAuthor simply as easy as
char Book :: getAuthor( ) {
return *author;
}
(is that even correct?)
....or am I missing a major point here?
My professor's lesson on classes & objects leaves much to be desired.
Turning to the textbook was no help, either, because he's actually one
of the author's of the book... and he pretty much teaches directly from
the text.
I apologize if my question is silly... but, really, I'm struggling and
don't know where else to turn.
Thank you so much for whatever input you can provide
--Allie