Alejandro Cruz #2319545 HW7

# Alejandro Cruz #2319545 HW7 - *it=*it 5...

This preview shows pages 1–3. Sign up to view the full content.

Alejandro Cruz #2319545 HW7 #include<iostream> #include <vector> #include <list> using namespace std; int main(){ // an array of ints int a[10]={0,1,2,3, 4, 5, 6, 7, 8, 9 }; //a vector<int> std::vector<int> v (&a[0],&a[0]+10); //List <int> std::list<int> l (&a[0],&a[0]+10); //Define a second array, vector, and list, each initialized as a copy of the first array, vector, and list, respectively int b[10]; for(int i=0;i<10;i++){ b[i]=a[i]; } std::vector<int> v2(v); std::list<int> l2(l); // Increase the value of each element in the array by 2 for(int i=0;i<10;i++){ b[i]+=2; } //Increase the value of each element in the vector by 3; for(int i=0;i<10;i++){ v2[i]+=3; } //Increase the value of each element in list by 5. for (std::list<int>::iterator it = l2.begin(); it != l2.end(); it++)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: *it=*it+5; cout<<"Values of each of the containers are: "<<endl; cout<<"First Array is"<<endl; for(int i=0;i<10;i++){ cout<<a[i]<<" "; } cout<<"\nFirst Vector is:\n"; for(int i=0;i<10;i++){ cout<<v[i]<<" "; } cout<<"\nFirst List is:\n"; for (std::list<int>::iterator it = l.begin(); it != l.end(); it++) cout << *it << ' '; cout<<"\nSecond Array is"<<endl; for(int i=0;i<10;i++){ cout<<b[i]<<" "; } cout<<"\nSecond Vector is:\n"; for(int i=0;i<10;i++){ cout<<v2[i]<<" "; } cout<<"\nSecond List is:\n"; for (std::list<int>::iterator it = l2.begin(); it != l2.end(); it++) cout << *it << ' '; return 0; }...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern