473,566 Members | 3,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ProcessTransact ions 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
ProcessTransact ions
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 1794
* fa**********@gm ail.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_autho r() { 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**********@g mail.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**********@gm ail.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 ProcessTransact ions 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
ProcessTransact ions
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
1851
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 succsefully install the Addin on other machines. The install runs without error, it does unpack necessary files, and it does create many Addin related...
5
2734
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 that only scripts get rendered. I have seen this mentioned on this newsgroup before but with no resolution. Can anyone give any insight into this...
8
2503
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 file (present under the Properties folder of the project) 3. Now I created a file called test.js on the root folder of the project,
2
14814
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 for some it just suddenly stopped working. After a build it'll work maybe once or twice, then stop. I've tried repairing my installation of Visual...
1
3852
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 for some it just suddenly stopped working. After a build it'll work maybe once or twice, then stop. I've tried repairing my installation of Visual...
9
3195
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. What it does is to call a webservice with two parameters, one being a integer, the other one being a "String" which contains XML (not the best...
7
4030
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 Admin tool from the IDE however. I noticed some people referring to a directory called c:\Inetpub\wwwroot\aspnet_webadmin\, which i do not have on my...
4
3567
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
2153
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) Hide.dll methods and data I want to remain hidden I have a DLL, Hide.dll, that contains methods that I want to handle for
20
3393
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 classes. Is there a good tutorial out there on the web that a novice can understand. I currently wanting to add a password generator class to one of my...
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7953
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.