Advertisement
Maruf_Hasan

apple phone

Jun 24th, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. void Applephn::display(string name)
  2. {
  3. fstream fin;
  4. fin.open("Applephn.csv",ios::in);
  5. vector<string>row;
  6. string line,word,temp;
  7. int cnt=0;
  8. while(getline(fin,line))
  9. {
  10. row.clear();
  11. //getline(fin,line);
  12. stringstream s(line);
  13. while(getline(s,word,','))
  14. {
  15. row.push_back(word);
  16. }
  17. if(name==row[0]){
  18. cnt=1;
  19. cout<<"Brand: "<<row[0]<<endl;
  20. cout<<"Battery : "<<row[1]<<endl;
  21. cout<<"Price: "<<row[2]<<endl;
  22. }
  23. }
  24. fin.close();
  25. if(cnt==0)
  26. {
  27. cout<<"Not found"<<endl;
  28. }
  29. }
  30.  
  31.  
  32. void Applephn::compare(string name1,string name2)
  33. {
  34. fstream fin;
  35. fin.open("Applephn.csv",ios::in);
  36. vector<string>row;
  37. vector<string>phn1,phn2;
  38. string line,word,temp;
  39. int cnt1=0,cnt2=0;
  40. while(getline(fin,line))
  41. {
  42. row.clear();
  43. //getline(fin,line);
  44. stringstream s(line);
  45. while(getline(s,word,','))
  46. {
  47. row.push_back(word);
  48. }
  49. if(name1==row[0]){
  50. cnt1=1;
  51. phn1=row;
  52. }
  53. else if(name2==row[0])
  54. {
  55. cnt2=1;
  56. phn2=row;
  57. }
  58. }
  59. fin.close();
  60. if(cnt1==1 && cnt2==1)
  61. {
  62. for(int i=0;i<phn1.size();i++)
  63. {
  64. cout<<phn1[i]<<" "<<phn2[i]<<endl;
  65. }
  66. }
  67. else if(cnt1==0)
  68. {
  69. cout<<"Sorry"<<endl;
  70. cout<<"Model "<<name1<<"is not available"<<endl;
  71. }
  72. else if(cnt2==0)
  73. {
  74. cout<<"Sorry"<<endl;
  75. cout<<"Model "<<name2<<"is not available"<<endl;
  76. }
  77. else
  78. {
  79. cout<<"Sorry"<<endl;
  80. cout<<"Both Model are not available"<<endl;
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement