Fuller FlashDrive Using FlashDrive.cpp ( http://ideone.com/Jr1Uhl ), enhance the
ID: 3666093 • Letter: F
Question
Fuller FlashDrive
Using FlashDrive.cpp ( http://ideone.com/Jr1Uhl ),
enhance the FlashDrive 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 FlashDrive from the two arguments by combining their contents. If you wind up with a FlashDrive with a value stored that exceeds its capacity, print out an error message. If you wind up with a negative capacity or storage value, 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. Operator << should print out the values of the private member variables. Operator >> should read in and set the values of the private member variables.
FlashDrive
Sample Driver Code
FlashDrive
FlashDrive( );
FlashDrive( int capacity, int used, bool pluggedIn );
void plugIn( );
void pullOut( );
void writeData( int amount );
void eraseData( int amount );
void formatDrive( );
int getCapacity( );
void setCapacity( int amount );
int getUsed( );
void setUsed( int amount );
bool isPluggedIn( );
int my_StorageCapacity;
int my_StorageUsed;
bool my_IsPluggedIn;
#include
#include "FlashDrive.h"
using namespace std;
void main( )
{
FlashDrive drive1( 10, 0, false );
FlashDrive drive2( 20, 0, false );
drive1.plugIn( );
drive1.formatDrive( );
drive1.writeData( 5 );
drive1.pullOut( );
drive2.plugIn( );
drive2.formatDrive( );
drive2.writeData( 1 );
drive2.pullOut( );
FlashDrive combined = drive1 + drive2;
cout << "this drive's filled to " << combined.getUsed( ) << endl;
FlashDrive other = combined – drive1;
cout << "the other drives's filled to " << other.getUsed( ) << endl;
if (combined > other) {
cout << "looks like combined is bigger..." << endl;
}
else {
cout << "looks like other is bigger..." << endl;
}
if (drive2 > other) {
cout << "looks like drive2 is bigger..." << endl;
}
else {
cout << "looks like other is bigger..." << endl;
}
if (drive2 < drive1) {
cout << "looks like drive2 is smaller..." << endl;
}
else {
cout << "looks like drive1 is smaller..." << endl;
}
cout << "Here is drive1...." << endl;
cout << drive1 << endl;
cin >> "Let's set drive1...." << endl;
cin >> drive1;
cout << "Here is drive1. Notice the changes..." << endl;
cout << drive1 << endl;
}
FlashDrive
Sample Driver Code
FlashDrive
FlashDrive( );
FlashDrive( int capacity, int used, bool pluggedIn );
void plugIn( );
void pullOut( );
void writeData( int amount );
void eraseData( int amount );
void formatDrive( );
int getCapacity( );
void setCapacity( int amount );
int getUsed( );
void setUsed( int amount );
bool isPluggedIn( );
int my_StorageCapacity;
int my_StorageUsed;
bool my_IsPluggedIn;
#include
#include "FlashDrive.h"
using namespace std;
void main( )
{
FlashDrive drive1( 10, 0, false );
FlashDrive drive2( 20, 0, false );
drive1.plugIn( );
drive1.formatDrive( );
drive1.writeData( 5 );
drive1.pullOut( );
drive2.plugIn( );
drive2.formatDrive( );
drive2.writeData( 1 );
drive2.pullOut( );
FlashDrive combined = drive1 + drive2;
cout << "this drive's filled to " << combined.getUsed( ) << endl;
FlashDrive other = combined – drive1;
cout << "the other drives's filled to " << other.getUsed( ) << endl;
if (combined > other) {
cout << "looks like combined is bigger..." << endl;
}
else {
cout << "looks like other is bigger..." << endl;
}
if (drive2 > other) {
cout << "looks like drive2 is bigger..." << endl;
}
else {
cout << "looks like other is bigger..." << endl;
}
if (drive2 < drive1) {
cout << "looks like drive2 is smaller..." << endl;
}
else {
cout << "looks like drive1 is smaller..." << endl;
}
cout << "Here is drive1...." << endl;
cout << drive1 << endl;
cin >> "Let's set drive1...." << endl;
cin >> drive1;
cout << "Here is drive1. Notice the changes..." << endl;
cout << drive1 << endl;
}
Explanation / Answer
_________________
_______________________
Edit & Run
#include <iostream> #include "FlashDrive.h" using namespace std; void main( ) { int i; cout << "Welcome to Howie's Flash USB Drive Store!" << endl; cout << "How much memory do you need? "; cin >> i; FlashDrive f( i, 0, false ); cout << "Let's format the drive..." << endl; f.formatDrive(); cout << "Let's plug in the drive..." << endl; f.plugIn(); cout << "Let's write some data..." << endl; f.writeData( 10 ); cout << "Let's unplug the drive..." << endl; f.pullOut(); cout << "Enjoy your drive!!" << endl; } Edit & Run
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.