Maruf_Hasan

admin update price

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