Maruf_Hasan

Ahona

Nov 12th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Array
  5. {
  6. vector<int>v;
  7. public:
  8. void ReadArray()
  9. {
  10. cout<<"Enter the number of elements"<<endl;
  11. int n;
  12. cin>>n;
  13. cout<<"Enter the elements"<<endl;
  14. for(int i=0;i<n;i++)
  15. {
  16. int x;
  17. cin>>x;
  18. v.push_back(x);
  19. }
  20. }
  21. void InsertArray()
  22. {
  23. cout<<"Enter the element"<<endl;
  24. int x;
  25. cin>>x;
  26. v.push_back(x);
  27. }
  28. void DeleteArray()
  29. {
  30. cout<<"Enter the element"<<endl;
  31. int x;
  32. cin>>x;
  33. v.erase(remove(v.begin(),v.end(),x),v.end());
  34. }
  35. double AverageArray()
  36. {
  37. double sum=0;
  38. for(int i=0;i<v.size();i++)
  39. {
  40. sum+=v[i];
  41. }
  42. return sum/v.size();
  43. }
  44. void ShowArray()
  45. {
  46. for(int i=0;i<v.size();i++)
  47. {
  48. cout<<v[i]<<" ";
  49. }
  50. cout<<endl;
  51. }
  52. };
  53. int main()
  54. {
  55. Array A;
  56. cout<<"Enter your choice"<<endl;
  57. int choice;
  58. cout<<"1 to read Array"<<endl;
  59. cout<<"2 to insert in Array"<<endl;
  60. cout<<"3 to Delete from Array"<<endl;
  61. cout<<"4 to get the average of Array"<<endl;
  62. cout<<"5 to Show all the elements of Array"<<endl;
  63. cout<<"0 to Exit"<<endl;
  64. while(true)
  65. {
  66. cout<<"Enter Choice"<<endl;
  67. cin>>choice;
  68. if(choice==1)
  69. {
  70. A.ReadArray();
  71.  
  72. }
  73. if(choice==2)
  74. {
  75. A.InsertArray();
  76. }
  77. if(choice==3)
  78. {
  79. A.DeleteArray();
  80. }
  81. if(choice==4)
  82. {
  83. double avg=A.AverageArray();
  84. cout<<"Average is "<<avg<<endl;
  85. }
  86. if(choice==5)
  87. {
  88. A.ShowArray();
  89. }
  90. if(choice==0)
  91. {
  92. break;
  93. }
  94. else
  95. {
  96. continue;
  97. }
  98.  
  99. }
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment