473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Working with classes?

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? o_O
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 :D

--Allie

Apr 23 '06 #1
5 1786
* fa**********@gmail.com:
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
Tell your professor about the existence of std::string.

- 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
It's Very Bad Form to expose internal variables via references or
pointers to non-const.

Also, the prefix "get" has negative value in C++.

It does have some positive value in languages like Java and C# that
support dynnamic introspection, combined with a commonly accepted
convention for identifying getters and setters.

Third, there should presumably be some arguments?

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
Ouch, ditch that professor, if that's /actually/ the specification.

An uninitialized object, of a class with non-trivial constructor(s),
should never exist.
[snip] 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? o_O
Yes, the return type.

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.


What's the book title?

Have you looked it up in ACCU's book reviews?
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Apr 23 '06 #2
I mutilate Alf P. Steinbach's response:
Tell your professor about the existence of std::string. What is that?
Also, the prefix "get" has negative value in C++. What do you mean by "negative value"?
Third, there should presumably be some arguments? I was wondering the same thing... but I copied the assignment exactly
as I saw it on the handout.
What's the book title? The book is "Data Structures Using C and C++"
(http://www.amazon.com/gp/product/0130369977).
Have you looked it up in ACCU's book reviews?

It's not listed in ACCU's book reviews o_O

Thanks!

Apr 23 '06 #3
"Alf P. Steinbach" writes:
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.
<snip>
Book( ) // allows you to declare objects of type Book without
initializing any values
Ouch, ditch that professor, if that's /actually/ the specification.

An uninitialized object, of a class with non-trivial constructor(s),
should never exist.


I agree, this is truly a hideous course. I suspect the instructor doesn't
know about vector either, so he needs a default constructor to populate an
array.

[snip]

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? o_O


You want something like:

char* Book::get_author() { return author;}

author is already a pointer due to a kind of a nasty pointer/array
semi-equivalence. And besides that, you copied wrong from your earlier
text.
Apr 23 '06 #4
<fa**********@gmail.com> wrote:
What's the book title?

The book is "Data Structures Using C and C++"
(http://www.amazon.com/gp/product/0130369977).


15 reviews with 3 1/2 stars average. The average was boosted by one guy
making two posts (both five stars) and one guy commenting on the great
buyer/seller relationship, also five stars. I think Amazon is not quite
perfected.

If you just read the reviews and ignore the stars I can't imagine buying
that book. Of course, I think data structures should be taught in
pseudocode anyway, not the language du jour.
Apr 23 '06 #5
fa**********@gmail.com wrote:
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? o_O
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 :D

--Allie


Having years of C++ experience I don't see anything particularly
difficult here. That is from the C++ programming point of view,
unfortunately C++ skills alone are no longer sufficient for gainful
employment in software development. If that's what you're intending
you'll need at least a 2-1+ in Computer Science, or maybe less if gained
from Oxbridge or other highly rated University, and preferably be under 30.
I'm over 40 with a 2-2 from a lesser rated University, lots of C/C++
STL experience, but not using any associated technology like
COM/MFC/embedded/Linux/UNIX, and have been unemployed for the last 3
years. It would appear I'm well past my sell by date and will no doubt
have to find employment other than IT. Perhaps not the class you were
expecting, but you have been warned!

JB
Apr 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard | last post by:
All, I have coded an Outlook automation Addin in C# and .NET. I created the project using the Extensibility wizard. The Addin installs and runs Ok on my machine. However I am unable to...
5
by: Paul de Goede | last post by:
I set the Response.Filter in my aspnet application but I have noticed that if you do a Server.Transfer that the filter doesn't get called. And in actual fact the response is mostly empty. It seems...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
1
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
7
by: vamichael | last post by:
When I try to run the Website Administration Tool from my published application using http://localhost/myapp/webadmin.axd I am getting a "resource not found" error message. I can use the...
4
by: JohnB111 | last post by:
Hi Environment: Windows XPPRO SP2 IIS 5.1 AVG Anti Virus (Not script Blocking) The following code used to work perfectly on my local development machine and still does on my web server.
9
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service)...
20
by: Auddog | last post by:
I'm new to working with classes. I'm pretty much a self taught php programmer that uses php mostly for database entry and listings. I would like to expand my talents and start working with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.