Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class Array
- {
- vector<int>v;
- public:
- void ReadArray()
- {
- cout<<"Enter the number of elements"<<endl;
- int n;
- cin>>n;
- cout<<"Enter the elements"<<endl;
- for(int i=0;i<n;i++)
- {
- int x;
- cin>>x;
- v.push_back(x);
- }
- }
- void InsertArray()
- {
- cout<<"Enter the element"<<endl;
- int x;
- cin>>x;
- v.push_back(x);
- }
- void DeleteArray()
- {
- cout<<"Enter the element"<<endl;
- int x;
- cin>>x;
- v.erase(remove(v.begin(),v.end(),x),v.end());
- }
- double AverageArray()
- {
- double sum=0;
- for(int i=0;i<v.size();i++)
- {
- sum+=v[i];
- }
- return sum/v.size();
- }
- void ShowArray()
- {
- for(int i=0;i<v.size();i++)
- {
- cout<<v[i]<<" ";
- }
- cout<<endl;
- }
- };
- int main()
- {
- Array A;
- cout<<"Enter your choice"<<endl;
- int choice;
- cout<<"1 to read Array"<<endl;
- cout<<"2 to insert in Array"<<endl;
- cout<<"3 to Delete from Array"<<endl;
- cout<<"4 to get the average of Array"<<endl;
- cout<<"5 to Show all the elements of Array"<<endl;
- cout<<"0 to Exit"<<endl;
- while(true)
- {
- cout<<"Enter Choice"<<endl;
- cin>>choice;
- if(choice==1)
- {
- A.ReadArray();
- }
- if(choice==2)
- {
- A.InsertArray();
- }
- if(choice==3)
- {
- A.DeleteArray();
- }
- if(choice==4)
- {
- double avg=A.AverageArray();
- cout<<"Average is "<<avg<<endl;
- }
- if(choice==5)
- {
- A.ShowArray();
- }
- if(choice==0)
- {
- break;
- }
- else
- {
- continue;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment