Maruf_Hasan

Untitled

Jun 24th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. class phonebook//Base Class
  6. {
  7. public:
  8. string name;
  9. string mobile;
  10. string email;
  11. virtual void modifynumber(string nam){};
  12. virtual void modifyname(string nam){};
  13. virtual void display(string nam){};
  14. virtual void add(string name){};
  15. virtual void delete_number(string name){};
  16. virtual void clear_all(){};
  17. virtual void send_messages(string name){};
  18. virtual void display_sent_messages(string name){};
  19. };
  20. class addnum:public phonebook
  21. {
  22. public:
  23. void add(string name);
  24. };
  25.  
  26. //to display or modify existing number
  27. class existnum:public phonebook
  28. {
  29. void modifynumber(string nam);
  30. void modifyname(string nam);
  31. void display(string nam);
  32. };
  33.  
  34. //to delete a particular number
  35. class deletenum:public phonebook
  36. {
  37. void delete_number(string name);
  38. };
  39. //to clear the whole phonebook
  40. class clear_phonebook: public phonebook
  41. {
  42. void clear_all();
  43. };
  44. void addnum:: add(string name)
  45. {
  46. fstream fin;
  47. //ofstream out;
  48. fin.open("file1.csv",ios::in | ios::app);
  49. //out.open("Edited.csv",ios::out);
  50. vector<string>row;
  51. string line,word,temp,num;
  52. cout<<"Enter the Number"<<endl;
  53. cin>>num;
  54. cout<<"Want to add email?"<<endl;
  55. string str;
  56. if(str=="YES" || "yes")
  57. {
  58. cout<<"Enter the email"<<endl;
  59. string email;
  60. cin>>email;
  61. fin<<name<<","<<num<<","<<email<<endl;
  62. }
  63. fin.close();
  64. }
  65.  
  66. void clear_phonebook::clear_all()
  67. {
  68. remove("file1.csv");
  69. return;
  70. }
  71. void existnum::display(string name)
  72. {
  73. fstream fin;
  74. fin.open("file1.csv",ios::in);
  75. vector<string>row;
  76. string line,word,temp;
  77. int cnt=0;
  78. while(getline(fin,line))
  79. {
  80. row.clear();
  81. //getline(fin,line);
  82. stringstream s(line);
  83. while(getline(s,word,','))
  84. {
  85. row.push_back(word);
  86. }
  87. if(name==row[0]){
  88. cnt=1;
  89. cout<<row[1]<<endl<<row[2]<<endl;
  90. }
  91. }
  92. fin.close();
  93. if(cnt==0)
  94. {
  95. cout<<"Not found"<<endl;
  96. }
  97. }
  98. void existnum:: modifyname(string nam)
  99. {
  100. fstream fin,fout;
  101. fin.open("file1.csv",ios::in);
  102. fout.open("file2.csv",ios::out | ios::app);
  103. vector<string>row;
  104. string line,word,temp;
  105. int cnt=0;
  106. while(getline(fin,line))
  107. {
  108. row.clear();
  109. // getline(fin,line);
  110. stringstream s(line);
  111. while(getline(s,word,','))
  112. {
  113. row.push_back(word);
  114. }
  115. if(nam==row[0]){
  116. cnt=1;
  117. cout<<"Enter the Modified Name"<<endl;
  118. string newname;
  119. cin>>newname;
  120. fout<<newname<<","<<row[1]<<","<<row[2]<<endl;
  121. //break;9
  122. }
  123. else
  124. {
  125. fout<<row[0]<<","<<row[1]<<","<<row[2]<<endl;
  126. }
  127. }
  128. fin.close();
  129. fout.close();
  130. remove("file1.csv");
  131. rename("file2.csv","file1.csv");
  132. }
  133.  
  134. void existnum:: modifynumber(string nam)
  135. {
  136. fstream fin,fout;
  137. fin.open("file1.csv",ios::in);
  138. fout.open("file2.csv",ios::out | ios::app);
  139. vector<string>row;
  140. string line,word,temp;
  141. int cnt=0;
  142. while(getline(fin,line))
  143. {
  144. row.clear();
  145. // getline(fin,line);
  146. stringstream s(line);
  147. while(getline(s,word,','))
  148. {
  149. row.push_back(word);
  150. }
  151. if(nam==row[0]){
  152. cnt=1;
  153. cout<<"Enter the Modified number"<<endl;
  154. string newnum;
  155. cin>>newnum;
  156. fout<<row[0]<<","<<newnum<<","<<row[2]<<endl;
  157. //break;9
  158. }
  159. else
  160. {
  161. fout<<row[0]<<","<<row[1]<<","<<row[2]<<endl;
  162. }
  163. }
  164. fin.close();
  165. fout.close();
  166. remove("file1.csv");
  167. rename("file2.csv","file1.csv");
  168. }
  169. void deletenum:: delete_number(string nam)
  170. {
  171. fstream fin,fout;
  172. fin.open("file1.csv",ios::in);
  173. fout.open("file2.csv",ios::out | ios::app);
  174. vector<string>row;
  175. string line,word,temp;
  176. int cnt=0;
  177. while(getline(fin,line))
  178. {
  179. row.clear();
  180. // getline(fin,line);
  181. stringstream s(line);
  182. while(getline(s,word,','))
  183. {
  184. row.push_back(word);
  185. }
  186. if(nam==row[0]){
  187. continue;
  188. }
  189. else
  190. {
  191. fout<<row[0]<<","<<row[1]<<","<<row[2]<<endl;
  192. }
  193. }
  194. fin.close();
  195. fout.close();
  196. remove("file1.csv");
  197. rename("file2.csv","file1.csv");
  198. }
  199. class message :public phonebook
  200. {
  201. void send_messages(string name);
  202. void display_sent_messages(string name);
  203. };
  204. void message::send_messages(string name)
  205. {
  206. fstream fin,fout;
  207. fin.open("file1.csv",ios::in);
  208. fout.open("msg.csv",ios::out | ios::app);
  209. vector<string>row;
  210. string line,word,temp;
  211. int cnt=0;
  212. while(getline(fin,line))
  213. {
  214. row.clear();
  215. // getline(fin,line);
  216. stringstream s(line);
  217. while(getline(s,word,','))
  218. {
  219. row.push_back(word);
  220. }
  221. if(name==row[0]){
  222. cout<<"Enter your text."<<endl;
  223. cout<<"To: "<<endl<<row[0]<<endl<<row[1]<<endl;
  224.  
  225. string text;
  226. // cin>>text;
  227. getchar();
  228. getline(cin,text);
  229. fout<<row[0]<<','<<row[1]<<','<<text<<endl;
  230. }
  231. }
  232. fin.close();
  233. fout.close();
  234. }
  235. void message::display_sent_messages(string name)
  236. {
  237.  
  238. fstream fin;
  239. fin.open("msg.csv",ios::in);
  240. vector<string>row;
  241. string line,word,temp;
  242. int cnt=0;
  243. while(getline(fin,line))
  244. {
  245. row.clear();
  246. //getline(fin,line);
  247. stringstream s(line);
  248. while(getline(s,word,','))
  249. {
  250. row.push_back(word);
  251. }
  252. if(name==row[0]){
  253. cnt=1;
  254. cout<<row[2]<<endl;
  255. cout<<endl<<endl;
  256. }
  257. }
  258. fin.close();
  259. if(cnt==0)
  260. {
  261. cout<<"Not found"<<endl;
  262. }
  263. }
  264. int main()
  265. {
  266. phonebook *phn;
  267. existnum ex;
  268. addnum addnumbers;
  269. deletenum deletenumbers;
  270. clear_phonebook clr;
  271. cout<<"*********** ";
  272. cout<<"Welcome to Phonebook"<<"***********"<<endl;
  273. cout<<"Enter Your choice"<<endl;
  274. message msg;
  275. string name;
  276. return 0;
  277. }
Advertisement
Add Comment
Please, Sign In to add comment