473,396 Members | 1,797 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.

dynamic array of objects

New to c++ and OOP. I need help
I'm trying to code a sample library system using arrays of objects that
will do the following:
-Add a book to the library
-Remove a book from the library
-Search for a specific book
-List books on a given subject or author in alphabetical order
I'm totally buffed. I don't even know where to start.
All help will be appreciated

Jun 1 '06 #1
7 4520
Briton wrote:
New to c++ and OOP. I need help
I'm trying to code a sample library system using arrays of objects that
will do the following:
Don't settle prematurely on an internal representation.
-Add a book to the library
-Remove a book from the library
-Search for a specific book
-List books on a given subject or author in alphabetical order


Looks like you already have a pretty decent conception of what the interface
will be like. First turn this into a class declaration. I would think of
something like:

class library_database {
public:

// constructors and stuff omitted

void insert ( book const & );

void erase ( book const & );

template < typename OutIter >
void copy_books ( std::string const & search_string,
OutIter where );
/*
this is supposed to perform
*where++ = some book
for all books that match a given search

The books will be written in some defined order.
*/

}; // library_database

Then set out tom implement that. If you find that the design is not
adequate, start over.
Best

Kai-Uwe Bux

Jun 1 '06 #2
Briton wrote:
New to c++ and OOP. I need help
I'm trying to code a sample library system using arrays of objects that
will do the following:
-Add a book to the library
-Remove a book from the library
-Search for a specific book
-List books on a given subject or author in alphabetical order
I'm totally buffed. I don't even know where to start.
All help will be appreciated


Start with the basics and work your way up. If someone here decides to
write the homework for you: you'ld be hopelessly confused beyond repair.

This is an excellent project. Start with item #1. Write a type that
represents a book. Then prove you can create a single instance of a book
in main(). If you can't get that done: the rest of the project is
irrelevant.

If you are too lazy to even try then the last thing you want to be is a
programmer. Drop-out of the course, its not for you. And as always: the
only way to learn is by coding. He who makes no mistakes is the one that
does not try.

The task you've been given is a very, very simple task. Delving into C++
becomes much, much more complicated after you've completed this one. If
you haven't the discipline and drive to get started, find something else
to do.
Jun 1 '06 #3
Briton posted:
New to c++ and OOP. I need help
I'm trying to code a sample library system using arrays of objects that
will do the following:
-Add a book to the library
-Remove a book from the library
-Search for a specific book
-List books on a given subject or author in alphabetical order
I'm totally buffed. I don't even know where to start.
All help will be appreciated


Rentacoder.com has a homework section. They might do it for you for as
little as $30.

You'll eventually fail computer programming at the end of your course, but
hey... at least you'll save face until then.

On the other hand, if you're in any way serious about this, you'll get your
hands on a good C++ book like "Accelerated C++ by Andrew Koenig".
-Tomás
Jun 1 '06 #4
Tomás wrote:
Briton posted: -snip-
Rentacoder.com has a homework section. They might do it for you for as
little as $30.
LOL! Funny. I didn't know they had that :-)
You'll eventually fail computer programming at the end of your course, but
hey... at least you'll save face until then.
Perhaps he gets his final grade based on what he hands in or a grade
based on a combination of exam + homework grades...
On the other hand, if you're in any way serious about this, you'll get your
hands on a good C++ book like "Accelerated C++ by Andrew Koenig".


Correct.
Best regards
Martin Jřrgensen

--
---------------------------------------------------------------------------
Home of Martin Jřrgensen - http://www.martinjoergensen.dk
Jun 1 '06 #5
"Salt_Peter" <sa********@codigo.core> wrote in message
news:qd*******************@news20.bellglobal.com.. .
Briton wrote:
New to c++ and OOP. I need help
I'm trying to code a sample library system using arrays of objects that
will do the following:
-Add a book to the library
-Remove a book from the library
-Search for a specific book
-List books on a given subject or author in alphabetical order
I'm totally buffed. I don't even know where to start.
All help will be appreciated


Start with the basics and work your way up. If someone here decides to
write the homework for you: you'ld be hopelessly confused beyond repair.

This is an excellent project. Start with item #1. Write a type that
represents a book. Then prove you can create a single instance of a book
in main(). If you can't get that done: the rest of the project is
irrelevant.

If you are too lazy to even try then the last thing you want to be is a
programmer. Drop-out of the course, its not for you. And as always: the
only way to learn is by coding. He who makes no mistakes is the one that
does not try.

The task you've been given is a very, very simple task. Delving into C++
becomes much, much more complicated after you've completed this one. If
you haven't the discipline and drive to get started, find something else
to do.


I don't think you have to code to learn. Coding is only one part of the
software engineering cycle. You definitely need to know the language and
tools used to generate programs with that language. And like any new
language mastering it takes time. I've always believed mastering the
concepts is much more important than mastering on implementation on a given
platform.

Basically, you need to define what the objects in your system need to do,
and what data needs to be stored and manipulated in those objects to satisfy
your requirements. To get you started, it sounds like books will need a
subject and author. Have fun.
Jun 1 '06 #6
Martin Jřrgensen posted:

Perhaps he gets his final grade based on what he hands in or a grade
based on a combination of exam + homework grades...

Across all professions, there should be an "off-the-cuff" test. For
example, take the student and put them in a room, and tell them that
they've one hour to produce something you specify.

If it was flower arranging, tell them to make some sort of arrangement.

If it was chemistry, tell them to prepare some compound.

If it's computer programming, tell them you want a particular program.
These "off-the-cuff" tests would weed out the fakers.
-Tomás
Jun 2 '06 #7
"Briton" <br******@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
New to c++ and OOP. I need help
I'm trying to code a sample library system using arrays of objects that
will do the following:
-Add a book to the library
-Remove a book from the library
-Search for a specific book
-List books on a given subject or author in alphabetical order
I'm totally buffed. I don't even know where to start.
All help will be appreciated


Well, look at this and identify all the objects.

"add a book to the library"

We have a book
We have a library.

"remove a book from the library"
nothign new needed here.

"Search for a specific book"
Okay, we'll need to be able to search the books.

"List books on a given subject or author in alphabetical order"
Hmm.. need to be indexed at least alphabetcially.

So, it looks like we want to have books in an ordered list.

So first, create your book. What do books have? From your work you see
they have:
"given subject"
"author"
"alphabetical order"

a subject
an author
a title

you might want to include the isbn even though this isn't required.

So, create your book class with those variables.
Test it.

Now, you need a way to add this book to the library, which will be some type
of container, which we need to decide on.

We can use a vector, but a vector is unsorted naturally.
We can use a map, which is sorted, but only has one key.

If there is a container that allows more than one key for a collection, I
dont' know what it is. There may very well be one.

So I would probably stick it on in a vector.
Do the searches manually, which is rather slow (iterate through all the
entries searching).
Build a vector for the result and search it.

You may notice, I haven't given you a single line of code. That's right,
this is homework. Maybe someone else has a better solution than a vector
though, if someone does it would be great.

Jun 2 '06 #8

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

Similar topics

3
by: Andrew.Morgan | last post by:
Hi I have three classes TDigest, THash and TSHA1. //--------------------------------------------------------------------------- class TDigest { public: // Constructors. TDigest(int Count);
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
1
by: lemonade | last post by:
Hello! Can someone explain to me the difference between dynamic array of pointers vs dynamic array of objects by giving a real life example. Following is the code that I am using for dynamic...
9
by: wASP | last post by:
Hello again to all of you geniuses, I'm having a problem trying to load dynamic controls at the initialization phase. I've read the docs, and I thought I had it figured out:...
7
by: murrayatuptowngallery | last post by:
After a few searches & inquiries here, I have a method of generating an html table populated with results of equations that works and wasn't too far up a learning curve for me, thanks to a helpful...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
2
by: him1979 | last post by:
If I have these classes: class student { private: string * name; int faculty number; date datebirth; public: ... };
4
Frinavale
by: Frinavale | last post by:
Introduction Sometimes, when developing web applications, we need to be able to dynamically load controls based on user selections. The following article describes a simple scenario where TextBox...
2
by: headware | last post by:
Do dynamic arrays declared using ReDim have to be freed? I assume that if it's an array of dynamically created objects (e.g. Scripting.Dictionary), each one of those objects will have to be set to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.