AVQ2 - void employee:write(ostream& out out<<...

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

View Full Document Right Arrow Icon
#include <iostream> #include <fstream> #include <string> using namespace std; class employee { private: string first; string last; int id; float salary; public: void read(istream& in); void write(ostream& out); }; class workforce { private: string location; string name; int size; employee* list; public: workforce(void); workforce(istream& in); workforce(const workforce& q); ~workforce(void); workforce& operator=(const workforce& q); void write(ostream& out); }; int main(void) { ifstream fin("workforce.in"); ofstream fout("workforce.out"); workforce x(fin); fout << "The workforce x is\n"; x.write(fout); x = x; fout << "\nThe workforce x is\n"; x.write(fout); if(1) { workforce y; y = x; fout << "\nThe assignment of x to y is\n"; y.write(fout); workforce z(x); fout << "\nThe copy of x is\n"; z.write(fout); } fout << "\nThe workforce x is\n"; x.write(fout); fout.close(); system("notepad workforce.out"); return 0; } { in >> first >> last >> id >> salary;
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: } void employee::write(ostream& out) { out << first << " " << last << " " << id << " " << salary << endl; } workforce::workforce(){ location=""; name=""; size=0; list=NULL; } workforce::workforce(istream& in){ int i; in>>location>>name>>size; list = new employee[size]; for(i=0;i<size;i++) list[i].read(in); } workforce::workforce(const workforce& q){ int i; location=q.location; name=q.name; size=q.size; list = new employee[size]; for(i=0; i<size; i++) list[i] = q.list[i]; } workforce::~workforce() { delete list; } workforce& workforce::operator=(const workforce& q){ int i; if(this != &q) { location=q.location; name= q.name; size = q.size; if(size>0) delete list; list = new employee[size]; for(i=0; i<size; i++) list[i] = q.list[i]; } return *this; } void workforce::write(ostream& out){ int i; out<<location<<endl<<name<<endl<<size<<endl; for(i=0;i<size;i++) list[i].write(out); }...
View Full Document

This note was uploaded on 02/21/2010 for the course ENGM 2282 taught by Professor Phillips during the Winter '10 term at Dalhousie.

Page1 / 2

AVQ2 - void employee:write(ostream& out out<<...

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