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;;
} 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
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;;
}
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
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
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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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?
|
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
-...
|
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?
|
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
|
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();
| |
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?
|
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...
|
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...
|
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...
|
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...
|
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. ...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |