473,586 Members | 2,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object Oriented Design Contest

I have code here that explains my object oriented design model. I've
been reading about other design models from what is documented on
wikipedia about the key book on the subject: http://en.wikipedia.org/wiki/Design_patterns

All of the models look fun and interesting but they are very
specialized. I find myself writing bloated C++ code anyway, and not
finding a way to use the basic design models. So I've invented my
own. I call it recursive container design. The idea is to use a
container like a vector, or in my example a map, and do all of the
work within your container inside of the class. This keeps your code
very neat. It may seem redundant at first, but it keeps all of your
code organized in an easy to read and understand classes. This code
really reduced the size of my main function and created a neat little
class that directly relates to what I'm doing.

The only problem is that the code runs into problems after it is
compiled. The search_Name function in my program fails to lookup the
key pair for the data entered into the database. This is probably
because I've never worked with object oriented design before, and
haven't done anything with this particular container before either.

So if anyone is willing to fix up my code, I'll send you a free i-
pod! No one wanted to play my last contest, and I think this one is
more educational and far easier.

#include <utility>
#include <iostream>
#include <string>
#include <map>

using namespace std;

class Bookz : public map<string, string>
{

public:
Bookz() {
cout << "Welcome to the database. Enter information, and type 'end'
to stop."<< endl;
cout << "Name: ";
}
void add(string name, string number){
typedef pair <string, stringb_Pair;
insert( b_Pair(name, number) );
}
~Bookz(){}
void search_Name(str ing lookup_Num){
map <string, string:: const_iterator b_Name;
b_Name = find(lookup_Num );
cout << b_Name -second << "." << endl;
}
};

int main( void ) {
Bookz keeper;

string s="";
string n="";
while (s!="end" || n!="end"){
cin >s;
if(s=="end"){co ut <<"Finished inputing data."<<endl<<e ndl;
break;}
cout<<"Number: ";
cin >n;
if(n=="end"){co ut <<"Finished inputing data."<<endl<<e ndl;
break;}
keeper.add(s,n) ;
cout <<"Name: ";
}
cout << "To search the database enter a name or number. 'quit'
exists."<<endl;
while (s != "quit"){
cout<<"$ ";
cin >s;
keeper.search_N ame(s);
}

if (s == "quit")
cout<<"Goodbye. "<<endl;;
}

Apr 1 '07 #1
5 1474
On Sat, 31 Mar 2007 17:18:29 -0700, a rock fell the sky, hitting
virtualadepts on the head, and inspiring the following:
I have code here that explains my object oriented design model. I've
been reading about other design models from what is documented on
wikipedia about the key book on the subject:
http://en.wikipedia.org/wiki/Design_patterns

All of the models look fun and interesting but they are very
specialized. I find myself writing bloated C++ code anyway, and not
finding a way to use the basic design models. So I've invented my own.
I call it recursive container design. The idea is to use a container
like a vector, or in my example a map, and do all of the work within
your container inside of the class. This keeps your code very neat. It
may seem redundant at first, but it keeps all of your code organized in
an easy to read and understand classes. This code really reduced the
size of my main function and created a neat little class that directly
relates to what I'm doing.

The only problem is that the code runs into problems after it is
compiled. The search_Name function in my program fails to lookup the
key pair for the data entered into the database. This is probably
because I've never worked with object oriented design before, and
haven't done anything with this particular container before either.

So if anyone is willing to fix up my code, I'll send you a free i- pod!
No one wanted to play my last contest, and I think this one is more
educational and far easier.

#include <utility>
#include <iostream>
#include <string>
#include <map>

using namespace std;

class Bookz : public map<string, string{

public:
Bookz() {
cout << "Welcome to the database. Enter information, and type
'end'
to stop."<< endl;
cout << "Name: ";
}
void add(string name, string number){
typedef pair <string, stringb_Pair; insert( b_Pair(name,
number) );
}
~Bookz(){}
void search_Name(str ing lookup_Num){
map <string, string:: const_iterator b_Name; b_Name =
find(lookup_Num );
cout << b_Name -second << "." << endl;
}
};

int main( void ) {
Bookz keeper;

string s="";
string n="";
while (s!="end" || n!="end"){
cin >s;
if(s=="end"){co ut <<"Finished inputing
data."<<endl<<e ndl;
break;}
cout<<"Number: ";
cin >n;
if(n=="end"){co ut <<"Finished inputing
data."<<endl<<e ndl;
break;}
keeper.add(s,n) ;
cout <<"Name: ";
}
cout << "To search the database enter a name or number. 'quit'
exists."<<endl;
while (s != "quit"){
cout<<"$ ";
cin >s;
keeper.search_N ame(s);
}

if (s == "quit")
cout<<"Goodbye. "<<endl;;
}
You're missing a goto in there, I think.

In any case, when you create a class - say books - then you want to have
two things: methods and properties.

You're gonna need a set of properties about the books and a whole
shitload of methods to call from whatever other class you have.

Also, you're confusing your books class with whatever presentation class
you should have. Please separate them.
--
k
Apr 1 '07 #2
On Mar 31, 8:25 pm, PerfectReign <perfectre...@x r4ti.cotse.netw rote:
On Sat, 31 Mar 2007 17:18:29 -0700, a rock fell the sky, hitting
virtualadepts on the head, and inspiring the following:


I have code here that explains my object oriented design model. I've
been reading about other design models from what is documented on
wikipedia about the key book on the subject:
http://en.wikipedia.org/wiki/Design_patterns
All of the models look fun and interesting but they are very
specialized. I find myself writing bloated C++ code anyway, and not
finding a way to use the basic design models. So I've invented my own.
I call it recursive container design. The idea is to use a container
like a vector, or in my example a map, and do all of the work within
your container inside of the class. This keeps your code very neat. It
may seem redundant at first, but it keeps all of your code organized in
an easy to read and understand classes. This code really reduced the
size of my main function and created a neat little class that directly
relates to what I'm doing.
The only problem is that the code runs into problems after it is
compiled. The search_Name function in my program fails to lookup the
key pair for the data entered into the database. This is probably
because I've never worked with object oriented design before, and
haven't done anything with this particular container before either.
So if anyone is willing to fix up my code, I'll send you a free i- pod!
No one wanted to play my last contest, and I think this one is more
educational and far easier.
#include <utility>
#include <iostream>
#include <string>
#include <map>
using namespace std;
class Bookz : public map<string, string{
public:
Bookz() {
cout << "Welcome to the database. Enter information, and type
'end'
to stop."<< endl;
cout << "Name: ";
}
void add(string name, string number){
typedef pair <string, stringb_Pair; insert( b_Pair(name,
number) );
}
~Bookz(){}
void search_Name(str ing lookup_Num){
map <string, string:: const_iterator b_Name; b_Name =
find(lookup_Num );
cout << b_Name -second << "." << endl;
}
};
int main( void ) {
Bookz keeper;
string s="";
string n="";
while (s!="end" || n!="end"){
cin >s;
if(s=="end"){co ut <<"Finished inputing
data."<<endl<<e ndl;
break;}
cout<<"Number: ";
cin >n;
if(n=="end"){co ut <<"Finished inputing
data."<<endl<<e ndl;
break;}
keeper.add(s,n) ;
cout <<"Name: ";
}
cout << "To search the database enter a name or number. 'quit'
exists."<<endl;
while (s != "quit"){
cout<<"$ ";
cin >s;
keeper.search_N ame(s);
}
if (s == "quit")
cout<<"Goodbye. "<<endl;;
}

You're missing a goto in there, I think.

In any case, when you create a class - say books - then you want to have
two things: methods and properties.

You're gonna need a set of properties about the books and a whole
shitload of methods to call from whatever other class you have.

Also, you're confusing your books class with whatever presentation class
you should have. Please separate them.

--
k
I WIN! My Object Oriented Code FLYS LIKE A EAGLE!!! I found the bug,
and corrected it. All I needed to do is go back and re-read about the
error I was encountering. YAY!

#include <utility>
#include <iostream>
#include <string>
#include <map>

using namespace std;

class Bookz : public map<string, string>
{

public:
Bookz() {
cout << "Welcome to the database. Enter information, and type 'end'
to stop."<< endl;
cout << "Name: ";
}
void add(string name, string number){
typedef pair <string, stringb_Pair;
insert( b_Pair(name, number) );
}
~Bookz(){}
void search_Name(str ing lookup_Num){
cout << find(lookup_Num ) -second << "." << endl;
}
};

int main( void ) {
Bookz keeper;

string s="";
string n="";
while (s!="end" || n!="end"){
cin >s;
if(s=="end"){co ut <<"Finished inputing data."<<endl<<e ndl;
break;}
cout<<"Number: ";
cin >n;
if(n=="end"){co ut <<"Finished inputing data."<<endl<<e ndl;
break;}
keeper.add(s,n) ;
cout <<"Name: ";
}
cout << "To search the database enter a name or number. 'quit'
exists."<<endl;
while (s != "quit"){
cout<<"$ ";
cin >s;
keeper.search_N ame(s);
}

if (s == "quit")
cout<<"Goodbye. "<<endl;;
}

Apr 1 '07 #3
Dnia Sat, 31 Mar 2007 17:18:29 -0700, virtualadepts napisa³(a):
So if anyone is willing to fix up my code
Fix-up your brain at first.
And stop cross-posting [we've told you that already].
I'll send you a free i-pod!
Up to now, you're sending us a free spam only.
A LOTS of free spam!
So there is only one way out:

*PLONK!*

See you next life.....

--
SasQ
Apr 1 '07 #4
ajk
On 31 Mar 2007 17:18:29 -0700, vi***********@g mail.com wrote:
>#include <utility>
#include <iostream>
#include <string>
#include <map>

using namespace std;

class Bookz : public map<string, string>
{

public:
Bookz() {
cout << "Welcome to the database. Enter information, and type 'end'
to stop."<< endl;
cout << "Name: ";
}
void add(string name, string number){
typedef pair <string, stringb_Pair;
insert( b_Pair(name, number) );
}
~Bookz(){}
void search_Name(str ing lookup_Num){
map <string, string:: const_iterator b_Name;
b_Name = find(lookup_Num );
cout << b_Name -second << "." << endl;
}
};

int main( void ) {
Bookz keeper;

string s="";
string n="";
while (s!="end" || n!="end")
{
cin >s;
if(s=="end")
{
cout <<"Finished inputing data."<<endl<<e ndl;
break;
}
cout<<"Number: ";
cin >n;
if(n=="end")
{
cout <<"Finished inputing data."<<endl<<e ndl;
break;
}
keeper.add(s,n) ;
cout <<"Name: ";
}
cout << "To search the...r. 'quit' exists."<< endl;
while (s != "quit")
{
cout<<"$ ";
cin >s;
keeper.search_N ame(s);
}

if (s == "quit")
{
cout<<"Goodbye. "<<endl;;
}
}
Why are you inheriting from the map template? it is better design to
add map<string,stri ngmember variable in your class. then use
insert/find on that member variable

the map<is used for hash tables but adding IO in it is not a good
design (if u don't add it for debugging purposes).

Always try to keep your design simple, if you derive from map<and
adding all this cout's in your class you are not having a clean design
and the chances are that you will never be able reuse your class
as-is.
hth/ajk
Apr 1 '07 #5
On Apr 1, 2:51 am, virtualade...@g mail.com wrote:
On Mar 31, 8:25 pm, PerfectReign <perfectre...@x r4ti.cotse.netw rote:
On Sat, 31 Mar 2007 17:18:29 -0700, a rock fell the sky, hitting
virtualadepts on the head, and inspiring the following:
I have code here that explains my object oriented design model. I've
been reading about other design models from what is documented on
wikipedia about the key book on the subject:
>http://en.wikipedia.org/wiki/Design_patterns
All of the models look fun and interesting but they are very
specialized. I find myself writing bloated C++ code anyway, and not
finding a way to use the basic design models. So I've invented my own.
I call it recursive container design. The idea is to use a container
like a vector, or in my example a map, and do all of the work within
your container inside of the class. This keeps your code very neat. It
may seem redundant at first, but it keeps all of your code organized in
an easy to read and understand classes. This code really reduced the
size of my main function and created a neat little class that directly
relates to what I'm doing.
The only problem is that the code runs into problems after it is
compiled. The search_Name function in my program fails to lookup the
key pair for the data entered into the database. This is probably
because I've never worked with object oriented design before, and
haven't done anything with this particular container before either.
So if anyone is willing to fix up my code, I'll send you a free i- pod!
No one wanted to play my last contest, and I think this one is more
educational and far easier.
#include <utility>
#include <iostream>
#include <string>
#include <map>
using namespace std;
class Bookz : public map<string, string{
public:
Bookz() {
cout << "Welcome to the database. Enter information, and type
'end'
to stop."<< endl;
cout << "Name: ";
}
void add(string name, string number){
typedef pair <string, stringb_Pair; insert( b_Pair(name,
number) );
}
~Bookz(){}
void search_Name(str ing lookup_Num){
map <string, string:: const_iterator b_Name; b_Name =
find(lookup_Num );
cout << b_Name -second << "." << endl;
}
};
int main( void ) {
Bookz keeper;
string s="";
string n="";
while (s!="end" || n!="end"){
cin >s;
if(s=="end"){co ut <<"Finished inputing
data."<<endl<<e ndl;
break;}
cout<<"Number: ";
cin >n;
if(n=="end"){co ut <<"Finished inputing
data."<<endl<<e ndl;
break;}
keeper.add(s,n) ;
cout <<"Name: ";
}
cout << "To search the database enter a name or number. 'quit'
exists."<<endl;
while (s != "quit"){
cout<<"$ ";
cin >s;
keeper.search_N ame(s);
}
if (s == "quit")
cout<<"Goodbye. "<<endl;;
}
You're missing a goto in there, I think.
In any case, when you create a class - say books - then you want to have
two things: methods and properties.
You're gonna need a set of properties about the books and a whole
shitload of methods to call from whatever other class you have.
Also, you're confusing your books class with whatever presentation class
you should have. Please separate them.
--
k

I WIN! My Object Oriented Code FLYS LIKE A EAGLE!!! I found the bug,
and corrected it. All I needed to do is go back and re-read about the
error I was encountering. YAY!

#include <utility>
#include <iostream>
#include <string>
#include <map>

using namespace std;

class Bookz : public map<string, string>
{

public:
Bookz() {
cout << "Welcome to the database. Enter information, and type 'end'
to stop."<< endl;
cout << "Name: ";
}
void add(string name, string number){
typedef pair <string, stringb_Pair;
insert( b_Pair(name, number) );
}
~Bookz(){}
void search_Name(str ing lookup_Num){
cout << find(lookup_Num ) -second << "." << endl;
}

};

int main( void ) {
Bookz keeper;

string s="";
string n="";
while (s!="end" || n!="end"){
cin >s;
if(s=="end"){co ut <<"Finished inputing data."<<endl<<e ndl;
break;}
cout<<"Number: ";
cin >n;
if(n=="end"){co ut <<"Finished inputing data."<<endl<<e ndl;
break;}
keeper.add(s,n) ;
cout <<"Name: ";
}
cout << "To search the database enter a name or number. 'quit'
exists."<<endl;
while (s != "quit"){
cout<<"$ ";
cin >s;
keeper.search_N ame(s);
}

if (s == "quit")
cout<<"Goodbye. "<<endl;;
}


Can it be used as a new grep? Or giggle desktop search :-)) Can
language process language?

Apr 1 '07 #6

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

Similar topics

2
3463
by: ggg | last post by:
I'm looking for a complete project/application done with heavy use of of object-oriented programming & design. Preferably something well documented and/or commented so that I can pick it apart and learn how/why they designed it they way they did. Any suggestions?
1
2174
by: Robert Hathaway | last post by:
COMP.OBJECT FAQ Version II Beta now Available http://www.objectfaq.com/oofaq2 ================================================== - Latest Important Information on Object Technology - What's New Page - What professionals *must keep up on* in rapidly changing environment - Available on Homepage, email notification on updates now available -...
5
2914
by: Martin | last post by:
When was inheritance intruduced into object oriented programming? More generally, does anyone know or have any sources on when the different features were introduced into object oriented programming?
34
7059
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. Yensao
11
9230
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
8
2380
by: Dale | last post by:
I've searched Amazon and read probably 100 reviews but can't find what seems to be any book that is widely accepted as the definitive book on object oriented programming design and techniques. And most of the highest rated are all written 10 to 15 years ago. Any good suggestions?
4
1782
by: scottrm | last post by:
I am fairly new to oo design and I am looking at developing an object oriented asp.net application which will be built on top of a relational database. I have read quite a bit of the theory but find it hard to put it into practice. In particular I am confused in terms of interacting with the database. It seems to me classes map quite closely...
2
1705
by: Chris Asaipillai | last post by:
Hi there Im starting a new course this Saturday. OBJECT ORIENTED DEVELOPMENT WITH VISUAL BASIC .NET and will cover the following concepts and principles. a.. Be able to build VB.NET applications using custom object design. b.. Utilise existing .NET Framework objects and extending functionality. c.. Become familiar with how to...
46
2999
by: ajba74 | last post by:
Hi fellows, I am reading some books to learn the C programming language, and sometimes I have the feeling that when somebody becomes a C expert, he must learn a more modern and object-oriented language. When I read things like "... C++ is an evolution of C ..." or "... C is a subset of C++ ..." I tend to believe that I will have to learn...
0
7839
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
8200
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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
8215
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...
0
5390
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
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.