{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

AVQ1 - int i for(i=0 i< p.count i cout<<...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <cstdlib> using namespace std; class intlist { private: int* data; int max; int count; public: intlist(int size); ~intlist(void); intlist(const intlist& q); intlist& operator=(const intlist& q); void add(int x); friend void show(const intlist& p); }; int main(void) { intlist list1(10); char choice; list1.add(1); list1.add(3); list1.add(5); cout<< "list1 = "; show(list1); cout << "Type c to make a copy of the list\n"; cout << "Type a to assign the list\n"; cin >> choice; if(choice == 'c') { intlist list2(list1); cout << "list2 = "; show(list2); } else if(choice == 'a') { intlist list3(5); list3 = list1; cout << "list3 = "; show(list3); } cout << "list1 = "; show(list1); system("pause"); return 0; } void show(const intlist& p)
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { int i; for(i=0; i < p.count; i++){ cout << p.data[i] << " "; } cout << endl; } intlist::intlist(int size) { max = size; count = 0; data = new int[max]; } intlist::~intlist(void) { delete data; } intlist::intlist(const intlist& q) { int i; max = q.max; count = q.count; data = new int[max]; for(i=0; i<count; i++) data[i] = q.data[i]; } intlist& intlist::operator=(const intlist& q) { int i; if(this != &q) { max = q.max; count = q.count; delete data; data = new int[max]; for(i=0; i<count; i++) data[i] = q.data[i]; } return *this; } void intlist::add(int x) { if(count == max) { cout << "the list is full\n"; exit(1); } data[count] = x; count++; }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern