| | |
help in phonebook
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Why don't you show us what you have started and we'll go from there. If you have nothing started start and you'll be more likely to get help.
•
•
Join Date: May 2008
Posts: 13
Reputation:
Solved Threads: 0
i don't have a clue a bout the sort i've tried many functions from the internet but they didn't work but i've began in the other function in the phone book and that is what i get thnx
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<string> #include<fstream> #include<algorithm> using namespace std; fstream phonebook; struct phone { char word[50]; char fword[50]; fstream edit; int id; string fname; string sname; string lname; int phonenumber; int mobilenumber; string email; }; phone info; char d,f,r; string c,g; int add() { phonebook.open("c:\\c\\phonebook.txt",ios::out|ios::app); cout<<"enter the first name\n"; cin>>info.fname; cout<<"enter the second name\n"; cin>>info.sname; cout<<"enter the last name\n"; cin>>info.lname; cout<<"enter the phone number\n"; cin>>info.phonenumber; cout<<"enter the moile number\n"; cin>>info.mobilenumber; cout<<"enter the e-mail\n"; cin>>info.email; phonebook<<info.fname<<"\t "<<info.sname<<"\t "<<info.lname<<" \t " <<info.phonenumber<<" \t "<<info.mobilenumber<<" \t "<<info.email<<endl;; cout<<endl; phonebook.close(); return 0; } int getdisplay() { cout<<"if u wanna display all contacts press 'a'\n"<<"if u wanna display contacts begining with specific letter press 'c'\n"; cin>>r; phonebook.open("c:\\c\\phonebook.txt",ios::in); phonebook.clear(); switch(r) { case 'a': { while(!phonebook.eof()) { getline(phonebook,c); cout<<c<<endl; } phonebook.close(); break; } case 'c': { phonebook.open("c:\\c\\phonebook.txt",ios::in); phonebook>>c; cout<<"enter the wanted letter"; cin>>g; // getdisplay; cout<<"dsucyeehr"; phonebook.close(); break; } } return 0; } void getsearch() { cout << "Enter your contact:"<<endl; cin >> info.word; phonebook.open("c:\\c\\phonebook.txt",ios::in); phonebook.clear(); int counter =0; while (!phonebook.eof()){ phonebook >> info.fword; int j=strcmp(info.fword,info.word); if (j==0){ cout << "contact was found in the file :)"<<endl; cout<< info.word << endl; counter ++; phonebook>>info.fname>>info.sname>>info.lname>>info.phonenumber>>info.mobilenumber>>info.email; cout<<info.fword<<" "<<info.fname<<" "<<info.sname<<" "<<info.lname <<" "<<info.phonenumber<<" "<<info.mobilenumber<<" "<<info.email; break; } } if (counter == 0) cout << "contact was not found in the file :(" << endl; phonebook.close(); } int main() { while(1) { cout<<endl<<"1-Adding new contacts"<<endl <<"2-Displaying contacts information"<<endl <<"3-Searching for a contact"<<endl <<"4-Deleting a contact"<<endl <<"5-Modifying a contact information"<<endl <<"6-Sort the contacts by name"<<endl <<"7-exit"<<endl<<endl; cout<<"enter your choice"<<endl; cin>>d; switch(d) { case '1': { add(); cout<<"if u wann add another contact press 'y' if not press 'n'"; cin>>f; if(f=='y') { add(); } break; } case '2': { getdisplay(); break; } case '3': { getsearch(); break; } case '4': { break; } case '5': { break; } case '6': { break; } case '7': { return 0; break; } } } system ("pause"); return 0; }
Last edited by Ancient Dragon; May 7th, 2008 at 1:01 pm. Reason: add code tags
If you reading the information from phonebook why are you asking user to input it ?
•
•
Join Date: May 2008
Posts: 13
Reputation:
Solved Threads: 0
i've edited the code and made a function for sorting but now i need the modifiy function how can i modify a contact that's my code hope u can help
C++ Syntax (Toggle Plain Text)
#include<iostream> #include <cstring> #include<string> #include <iomanip> #include <map> #include<fstream> #include<algorithm> #include <vector> //#include <stdlio> using namespace std; fstream phonebook; struct phone { char word[50]; char fword[50]; fstream edit; int id; string fname; string fname2; string sname; string lname; int phonenumber; int mobilenumber; string email; }; phone info; char d,f,r; string c,g; void sortingtany2() { vector<string> sV; phonebook.open("c:\\c\\phonebook.txt"); string word; // separates words in file at a whitespace // and loads a string vector while(getline(phonebook,word)) sV.push_back(word); cout << "Unsorted words:" << endl; for(int i = 0; i < sV.size(); i++) cout << sV[i] << endl; cout << "---------------" << endl; cout << "Sorted words:" << endl; sort( sV.begin(), sV.end() ); for(int i = 0; i < sV.size(); i++) { cout << sV[i] << endl; phonebook<<sV[i]; } } void edit() { string c; char c1; cout << "Please type some lines of text. Enter a period to finish:\n"; do { c=cin.get(); phonebook>>info.fname; if(c==info.fname) { info.fname.clear(); } } while (c1!='.'); } void add() { phonebook.open("c:\\c\\phonebook.txt",ios::out|ios::app); cout<<"enter the first name\n"; cin>>info.fname; cout<<"enter the second name\n"; cin>>info.sname; cout<<"enter the last name\n"; cin>>info.lname; cout<<"enter the phone number\n"; cin>>info.phonenumber; cout<<"enter the moile number\n"; cin>>info.mobilenumber; cout<<"enter the e-mail\n"; cin>>info.email; phonebook<<info.fname<<"\t "<<info.sname<<"\t "<<info.lname<<" \t " <<info.phonenumber<<" \t "<<info.mobilenumber<<" \t "<<info.email<<endl;; cout<<endl; phonebook.close(); } void getdisplay() { cout<<"if u wanna display all contacts press 'a'\n"<<"if u wanna display contacts begining with specific letter press 'c'\n"; cin>>r; phonebook.open("c:\\c\\phonebook.txt",ios::in); phonebook.clear(); switch(r) { case 'a': { while(!phonebook.eof()) { getline(phonebook,c); cout<<c<<endl; } phonebook.close(); break; } case 'c': { char le; phonebook.open("c:\\c\\phonebook.txt",ios::in); cout<<"enter the wanted letter"; cin>>le; phonebook.seekg(0,ios::beg); while(getline(phonebook ,c)) { cout<<"zashgdas"; for(int i=0;i<c.length();i++) { cout<<"afa"; if(c[0]>=le) { cout<<c; cout<<"hasgdajk"; break; } } } phonebook.close(); break; } } } void getsearch() { cout << "Enter your contact:"<<endl; cin >> info.word; phonebook.open("c:\\c\\phonebook.txt",ios::in); phonebook.clear(); int counter =0; while (!phonebook.eof()) { phonebook >> info.fword; int j=strcmpi(info.fword,info.word); if (j==0) { cout << "contact was found in the file :)"<<endl; cout<< info.word << endl; counter ++; break; } } if (counter == 0) cout << "contact was not found in the file :(" << endl; phonebook>>info.fname>>info.sname>>info.lname>>info.phonenumber>>info.mobilenumber>>info.email; cout<<info.fword<<" "<<info.fname<<" "<<info.sname<<" "<<info.lname <<" "<<info.phonenumber<<" "<<info.mobilenumber<<" "<<info.email<<endl; phonebook.close(); } void getmodify() { cout << "Enter your letter:"<<endl; cin >> info.word; phonebook.open("c:\\c\\phonebook.txt",ios::in); int counter =0; while (!phonebook.eof()){ phonebook >> info.fword; int j=strcmpi(info.fword,info.word); if (j==0){ cout << "contact was found in the file :)"<<endl; cout<< info.word << endl; counter ++; info.word==NULL; break; } } if (counter == 0) cout << "contact was not found in the file :(" << endl; phonebook.close(); } int getdel() { char hot; phonebook.open("c:\\c\\phonebook.txt",ios::in); ofstream myfile("c:\\c\\1.txt",ios::out); cout<<"ur u sure u want to delete all contact(y/n)"<<endl; cin>>hot; if (hot=='y') { phonebook>>info.fname; while( getline(phonebook,info.fname)) { cout << info.fword<< "\n"; } phonebook.close(); myfile.close(); // delete the original file remove("c:\\c\\phonebook.txt"); // rename old to new rename("c:\\c\\1.txt","c:\\c\\phonebook.txt"); } else { cout<<"the contact still as it is"<<endl; } // all done! return 0; } void del() { string del; cout << "Enter your contact:"<<endl; cin >> info.word; phonebook.open("c:\\c\\phonebook.txt",ios::in); phonebook.clear(); int counter =0; while (!phonebook.eof()) { phonebook >> info.fword; int j=strcmpi(info.fword,info.word); if (j==0) { cout << "contact was found in the file :)"<<endl; cout<< info.word << endl; counter ++; break; } } if (counter == 0) cout << "contact was not found in the file :(" << endl; phonebook>>info.fname>>info.sname>>info.lname>>info.phonenumber>>info.mobilenumber>>info.email; info.fname.clear(); info.fname=' '; phonebook<<info.fname; phonebook.close(); } int main() { while(true) { cout<<endl<<"1-Adding new contacts"<<endl <<"2-Displaying contacts information"<<endl <<"3-Searching for a contact"<<endl <<"4-Deleting a contact"<<endl <<"5-Modifying a contact information"<<endl <<"6-Sort the contacts by name"<<endl <<"7-exit"<<endl<<endl; cout<<"enter your choice"<<endl; cin>>d; switch(d) { case '1': { add(); cout<<"if u wann add another contact press 'y' if not press 'n'"; cin>>f; if(f=='y') { add(); } break; } case '2': { getdisplay(); break; } case '3': { getsearch(); break; } case '4': { int e; cout<<"enter '1'if u want to delete all contact"<<endl <<"enter '2' if u want to delete specific contact"<<endl; cin>>e; switch (e) { case 1: { getdel(); break; } case 2: { del(); break; } } break; } case '5': { getmodify(); break; } case '6': { sortingtany2(); break; } case '7': { return 0; break; } } } system ("pause"); return 0; }
Last edited by Ancient Dragon; May 7th, 2008 at 1:02 pm. Reason: add code tags
![]() |
Similar Threads
- phonebook problem (C++)
- expert! how to do this? PHONEBOOK! (C++)
- Phonebook program! (C)
- Phonebook program help (C++)
Other Threads in the C++ Forum
- Previous Thread: Windows Message loop
- Next Thread: string to int
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






