CSI 250L Lab 8 Solution, Spring 2012

American University of Science and Technology · Programming II Lab · 6 pages · Dr. Saeed Raheel · with solution

All CSI 250L files
CSI 250L Lab 8 Solution, Spring 2012, page 1

Stuck on a question? A tutor can walk you through it.

CSI 250L Lab 8 Solution, Spring 2012, page 2 CSI 250L Lab 8 Solution, Spring 2012, page 3 CSI 250L Lab 8 Solution, Spring 2012, page 4 CSI 250L Lab 8 Solution, Spring 2012, page 5 CSI 250L Lab 8 Solution, Spring 2012, page 6

More CSI 250L files

Show the text of this lab
#include <iostream> using namespace std; #include <string> class Date { friend ostream &operator<< ( ostream &, const Date & ); friend istream &operator>> (istream &, Date & ); private: int day, month, year; public: Date( int = 1, int = 1, int = 2011 ); }; Date::Date( int d, int m, int y ) { day = d; month = m; year = y; } ostream &operator<< (ostream &output, const Date &d ) { output << "Maufacturing Date: " << d.day << "/" << d.month << "/" << d.year << "\n"; return output; } istream &operator>> (istream &input, Date &d ) { input >> d.day; input.ignore(); input >> d.month; input.ignore(); input >> d.year; return input; } class Screen { friend ostream &operator<< ( ostream &, const Screen & ); friend istream &operator>> (istream &, Screen & ); private: string brand; int size; double price; string color; Date date; public: Screen( string = "", int = 0, double = 0.0, string = "", const Date & = NULL ); }; Screen::Screen( string b, int s, double p, string c, const Date & d ) { brand = b; size = s; price = p; color = c; date = d; } ostream &operator<< (ostream &output, const Screen &s ) { output << "Brand: " << s.brand << "\nSize: " << s.size << "\nPrice: " << s.price << "\nColor: " << s.color; output << s.date; return output; } istream &operator>> (istream &input, Screen &s ) { input >> s.brand; input >> s.size; input >> s.price; input >> s.color; input >> s.date; return input; } int main() { Screen s; cout << "Enter brand, size, price, color, and manufacturing date of the screen:\n"; cin >> s; cout << "The information entered is:\n"; cout << s; system( "pause" ); return 0; } #include <iostream.h> #include "IntegerSet.h" void main() { IntegerSet S1, S2, Se; char choice = 'y'; S1.insertE(5); S1.insertE(8); S1.insertE(10); S1.insertE(85); S1.insertE(3); S2.insertE(5); S2.insertE(8); S2.insertE(10); S2.insertE(85); S2.insertE(0); IntegerSet Su = S1.unionE(S2); IntegerSet Su_over = S1 + S2; IntegerSet Si = S1.interE(S2); IntegerSet Sc = S2; cout << "S1 is "; S1.printE(); cout << "S2 is "; S2.printE(); cout << "Empty set "; Se.printE(); cout << "Union "; Su.printE(); cout << "Union with overloading "; Su_over.printE(); cout << "Intersection "; Si.printE(); cout << "Copied set from S2 "; Sc.printE(); if(S1.equalE(S2)) cout << "Sets are the same" << endl; else cout << "Sets are not the same" << endl; if(S1 == S2) cout << "Using overloading: Sets are the same" << endl; else cout << "Using overloading: Sets are not the same" << endl; } #include <iostream> #include "IntegerSet.h" ostream& operator<<(ostream& out, const IntegerSet &is) { for (int a=0;a<101;a++) out << is.set[a] << endl; return out; } IntegerSet::IntegerSet() { for(int a = 0; a < 101; a++) set[a] = false; } IntegerSet IntegerSet::unionE(const IntegerSet &is) { IntegerSet holder; for(int a = 0; a < 101; a++) if((set[a] == true) || (is.set[a] == true)) holder.set[a] = true; else holder.set[a] = false; return holder; } IntegerSet IntegerSet::interE(const IntegerSet &is) { IntegerSet holder; for(int a = 0; a < 101; a++) if(set[a] == false || is.set[a] == false) holder.set[a] = false; else holder.set[a] = true; return holder; } void IntegerSet::insertE(int a) { if(a >= 0 && a < 101) set[a] = true; } void IntegerSet::deleteE(int a) { if(a >= 0 && a < 101) set[a] = false; } bool IntegerSet::equalE(const IntegerSet &is) { bool flag = true; for(int a = 0; a < 101; a++) if(set[a] != is.set[a]) { flag = false; break; } return flag; } IntegerSet IntegerSet::operator+(const IntegerSet &is) { IntegerSet holder; for(int a = 0; a < 101; a++) if(set[a] == true || is.set[a] == true) holder.set[a] = true; else holder.set[a] = false; return holder; } void IntegerSet::printE() const { int flag = 101; for(int a = 0; a < 101; a++) if(set[a] == true) cout << a << " "; else flag--; if(flag == 0) cout << "-------" << endl; else cout << endl; } #ifndef INTEGERSET_H #define INTEGERSET_H #include <iostream> using namespace std; class IntegerSet { friend ostream &operator<<(ostream& , const IntegerSet&); private: bool set[101]; public: IntegerSet(); IntegerSet(const IntegerSet&); ~IntegerSet(); IntegerSet unionE(const IntegerSet&); IntegerSet interE(const IntegerSet&); void insertE(int); void deleteE(int); void printE() const; bool equalE(const IntegerSet&); IntegerSet operator+(const IntegerSet&); IntegerSet operator-(const IntegerSet&); }; #endif