Maurice Tutor

(5)

$15/per page/Negotiable

About Maurice Tutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Biology,Calculus,Chemistry,Economics,English,Essay writing,Geography,Geology,Health & Medical,Physics,Science Hide all
Teaching Since: May 2017
Last Sign in: 398 Weeks Ago, 2 Days Ago
Questions Answered: 66690
Tutorials Posted: 66688

Education

  • MCS,PHD
    Argosy University/ Phoniex University/
    Nov-2005 - Oct-2011

Experience

  • Professor
    Phoniex University
    Oct-2001 - Nov-2016

Category > Computer Science Posted 27 Aug 2017 My Price 15.00

TrashCan class

Project 2: Better TrashCan

I have provided you with a sample class named TrashCan which has been diagrammed below and described in the online course content. You can acquire the source to the TrashCan class by clicking here (.NET 2012 XCode)**(content below)

TrashCan.h

#ifndef TRASHCAN_H

#define TRASHCAN_H

#include

using namespace std;

class TrashCan {

public:TrashCan( );

TrashCan( int size );

TrashCan( int size, int contents );

void setSize( int size );

int getSize( );

int getContents( );

void addItem( );

void empty( );

void cover( );

void uncover( );

void printCan( );

private:

bool myIsCovered;

int my_Size;

int my_Contents;

};

#endif

TrashCan.cpp

#include "TrashCan.h"

TrashCan::TrashCan( ) {

myIsCovered = false;

my_Size = 0;

my_Contents = 0;

}

TrashCan::TrashCan( int size ) {

myIsCovered = false;

my_Size = size;

my_Contents = 0;

}

TrashCan::TrashCan( int size, int contents ) {

myIsCovered = false;

my_Size = size;

my_Contents = contents;

}

void TrashCan::setSize( int size ) {

my_Size = size;

}

int TrashCan::getSize( ) {

return( my_Size );

}

int TrashCan::getContents( ) {

return( my_Contents );

}

void TrashCan::addItem( ) {

my_Contents = my_Contents + 1;

}

void TrashCan::empty( ) {

my_Contents = 0;

}

void TrashCan::cover( ) {

myIsCovered = true;

}

void TrashCan::uncover( ) {

myIsCovered = false;

}

void TrashCan::printCan( ) {

cout

if (my_Contents != 1) {

cout

}

cout

}

For this unit, I'd like you to identify additional member variables (data) that would be appropriate for the class TrashCan. I would also like you to identify additional methods (functions) that would be appropriate for the class TrashCan. Update and resubmit the .h file for TrashCan with the new possible methods and members you have identified commented and explained. YOU ARE NOT REQUIRED TO CODE UP ANYTHING MORE THAN THE .H FILE.

TrashCan Class

TrashCan( );
TrashCan(int size );
TrashCan(int size, int contents );

void setSize( int size );
int getSize( );
int getContents( );
void addItem( );
void empty( );
void cover( );
void uncover( );

void printCan( );

bool myIsCovered;
int my_Size;
int my_Contents;

Driver Code

#include "TrashCan.h"

#include
using namespace std;

int main( ) {

cout

TrashCan myCan;
TrashCan yourCan;

yourCan.setSize( 12 );
myCan.setSize( 12 );

yourCan.addItem( );
yourCan.addItem( );
myCan.addItem( );

myCan.printCan();
yourCan.printCan();

return( 0 );

}

Project 1: Fuller TrashCan

Using TrashCan.cpp (.NET 2012 XCode ), enhance the TrashCan class so that it supports the operators +, -, < and >. A sample pile of driver code is shown below to assist you in this effort. Operators + and - should create a new TrashCan from the two arguments by combining their contents. If you wind up with a TrashCan with a size that exceeds its capacity, print out an error message. If you wind up with a negative capacity or negative size, print out an error message. Operators < and > must return bool and should compare the holdings of the two arguments to determine which one is bigger.

My strong advice is to work one operator at a time, as these steps are very error-prone and lead to many, many compile errors.

TrashCan Class

TrashCan( );
TrashCan(int size );
TrashCan(int size, int contents );

void setSize( int size );
int getSize( );
int getContents( );
void addItem( );
void empty( );
void cover( );
void uncover( );

void printCan( );

bool myIsCovered;
int my_Size;
int my_Contents;

Driver Code

#include "TrashCan.h"

#include
using namespace std;

int main( ) {

cout

TrashCan myCan;
TrashCan yourCan;

yourCan.setSize( 12 );
myCan.setSize( 12 );

yourCan.addItem( );
yourCan.addItem( );
myCan.addItem( );

myCan.printCan();
yourCan.printCan();

TrashCan combined = yourCan + myCan;
cout
TrashCan other = combined – myCan;
cout

if (combined > other) {
cout
}
else {
cout
}
if (myCan > other) {
cout
}
else {
cout
}

if (yourCan
cout
}
else {
cout
}

return( 0 );

}

Project 3: Pointer TrashCan

Using the TrashCan class provided earlier, upgrade the class so that operator << and operator >> work well with pointers (that is, TrashCan *). Youll need to re-overload these operators, adding the function:
friend std::ostream& operator
friend std::istream& operator >>( std::istream& ins, TrashCan * & can );

HINT: Be very careful to test for NULL!

ANOTHER HINT: My strong advice is to work one operator at a time, as these steps are very error-prone and lead to many, many compile errors.

TrashCan Class

TrashCan( );
TrashCan(int size );
TrashCan(int size, int contents );

void setSize( int size );
int getSize( );
int getContents( );
void addItem( );
void empty( );
void cover( );
void uncover( );

void printCan( );

bool myIsCovered;
int my_Size;
int my_Contents;

Driver Code

#include "TrashCan.h"

#include
using namespace std;

int main( ) {

cout

TrashCan myCan;
TrashCan yourCan;

yourCan.setSize( 12 );
myCan.setSize( 12 );

yourCan.addItem( );
yourCan.addItem( );
myCan.addItem( );

myCan.printCan();
yourCan.printCan();

TrashCan combined = yourCan + myCan;
cout
TrashCan other = combined – myCan;
cout

if (combined > other) {
cout
}
else {
cout
}
if (myCan > other) {
cout
}
else {
cout
}

if (yourCan
cout
}
else {
cout
}

// Code related to this assignment is below...
TrashCan * can = new TrashCan( );
can->setSize( 10 );
can->addItem( );
can->addItem( );
cout
// Now let's change the can...
cin >> can;
cout

delete( can );

TrashCan * nullcan = NULL;

// be careful...

cout
cin >> nullcan;

return( 0 );

}

 

Answers

(5)
Status NEW Posted 27 Aug 2017 12:08 PM My Price 15.00

Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll

Not Rated(0)