Re: C++ Contest Challenge
On Mar 31, 8:32 pm, dave_mikes...@fastmail.fm wrote:
What's with all the ding dang Wiccans and magicians using C++ lately?
Can't you just conjure up a solution to your IT problems?
My solution? I got one now. It is a new object oriented design
model. You see I take containers and all the work I do with them
happens inside of the class. So that frees up a lot of space in my
main function, and lets me forget about tired old functions. Take a
peek:
#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, string> b_Pair;
insert( b_Pair(name, number) );
}
~Bookz(){}
void search_Name(string 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"){cout <<"Finished inputing data."<<endl<<endl;
break;}
cout<<"Number: ";
cin >> n;
if(n=="end"){cout <<"Finished inputing data."<<endl<<endl;
break;}
keeper.add(s,n);
cout <<"Name: ";
}
cout << "To search the database enter a name. 'quit' exits."<<endl;
while (s != "quit"){
cout<<"$ ";
cin >> s;
keeper.search_Name(s);
}
cout<<"Goodbye."<<endl;
return 0;
}