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

Info iconThis 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; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background 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

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online