Maruf_Hasan

remove phone

Jun 24th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. class Admin
  2. {
  3. public:
  4. void Add_phone();
  5. void Remove_phone();
  6. void Update_phone_price();
  7. Clear_all();
  8. };
  9. void Admin::Remove_phone()
  10. {
  11. int choice;
  12. while(true)
  13. {
  14. cout<<"Enter Which Type of Phone U want to Delete from the List"<<endl;
  15. cout<<"1.Featured phone"<<endl;
  16. cout<<"2.Midrange phone"<<endl;
  17. cout<<"3.Flagship phone"<<endl;
  18. cout<<"4.Apple Phone"<<endl;
  19. cout<<"0.Exit"<<endl;
  20. cin>>choice;
  21. if(choice==1)
  22. {
  23.  
  24. fstream fin,fout;
  25. fin.open("Featuredphone.csv",ios::in);
  26. fout.open("New1.csv",ios::out | ios::app);
  27. vector<string>row;
  28. string line,word,temp;
  29. int cnt=0;
  30. cout<<"Enter the Name of Phone U want to Remove"<<endl;
  31. string name;
  32. cin>>name;
  33. while(getline(fin,line))
  34. {
  35. row.clear();
  36. // getline(fin,line);
  37. stringstream s(line);
  38. while(getline(s,word,','))
  39. {
  40. row.push_back(word);
  41. }
  42. if(name==row[0]){
  43. }
  44. else
  45. {
  46. fout<<row[0]<<","<<row[1]<<","<<row[2]<<endl;
  47. }
  48. }
  49. fin.close();
  50. fout.close();
  51. remove("Featuredphone.csv");
  52. rename("New1.csv","Featuredphone.csv");
  53. }
  54.  
  55. else if(choice==2)
  56. {
  57. fstream fin,fout;
  58. fin.open("Midrangedphone.csv",ios::in);
  59. fout.open("New1.csv",ios::out | ios::app);
  60. vector<string>row;
  61. string line,word,temp;
  62. int cnt=0;
  63. cout<<"Enter the Name of Phone U want to Remove"<<endl;
  64. string name;
  65. cin>>name;
  66. while(getline(fin,line))
  67. {
  68. row.clear();
  69. // getline(fin,line);
  70. stringstream s(line);
  71. while(getline(s,word,','))
  72. {
  73. row.push_back(word);
  74. }
  75. if(name==row[0]){
  76. continue;
  77. }
  78. else
  79. {
  80. for(int i=0;i<row.size()-1;i++)
  81. {
  82. fout<<row[i]<<",";
  83. }
  84. fout<<row[row.size()-1]<<endl;
  85. }
  86. }
  87. fin.close();
  88. fout.close();
  89. remove("Midrangedphone.csv");
  90. rename("New1.csv","Midrangedphone.csv");
  91. }
  92. else if(choice==3)
  93. {
  94. cout<<"Enter the Name of Phone U want to Remove"<<endl;
  95. string name;
  96. cin>>name;
  97. fstream fin,fout;
  98. fin.open("Flagship_phone.csv",ios::in);
  99. fout.open("New1.csv",ios::out | ios::app);
  100. vector<string>row;
  101. string line,word,temp;
  102. int cnt=0;
  103. while(getline(fin,line))
  104. {
  105. row.clear();
  106. // getline(fin,line);
  107. stringstream s(line);
  108. while(getline(s,word,','))
  109. {
  110. row.push_back(word);
  111. }
  112. if(name==row[0]){
  113. continue;
  114. }
  115. else
  116. {
  117. for(int i=0;i<row.size()-1;i++)
  118. {
  119. fout<<row[i]<<",";
  120. }
  121. fout<<row[row.size()-1]<<endl;
  122. }
  123. }
  124. fin.close();
  125. fout.close();
  126. remove("Flagship_phone.csv");
  127. rename("New1.csv","Flagship_phone.csv");
  128. }
  129. else if(choice==4)
  130. {
  131. cout<<"Enter the Name of Phone U want to Remove"<<endl;
  132. string name;
  133. cin>>name;
  134. fstream fin,fout;
  135. fin.open("Apple_phone.csv",ios::in);
  136. fout.open("New1.csv",ios::out | ios::app);
  137. vector<string>row;
  138. string line,word,temp;
  139. int cnt=0;
  140. while(getline(fin,line))
  141. {
  142. row.clear();
  143. // getline(fin,line);
  144. stringstream s(line);
  145. while(getline(s,word,','))
  146. {
  147. row.push_back(word);
  148. }
  149. if(name==row[0]){
  150. continue;
  151. }
  152. else
  153. {
  154. for(int i=0;i<row.size()-1;i++)
  155. {
  156. fout<<row[i]<<",";
  157. }
  158. fout<<row[row.size()-1]<<endl;
  159. }
  160. }
  161. fin.close();
  162. fout.close();
  163. remove("Apple_phone.csv");
  164. rename("New1.csv","Apple_phone.csv");
  165. }
  166. else if(choice==0)
  167. {
  168. break;
  169. }
  170. else
  171. {
  172. continue;
  173. }
  174. }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment