Project 7: Better FlashDrive I have provided you with a sample class named Flash
ID: 3664552 • Letter: P
Question
Project 7: Better FlashDrive
I have provided you with a sample class named FlashDrive which has been diagrammed below. You can acquire the source to the FlashDrive class by clicking on the correct link for their development platform ( VS2010 VS2012 XCode5 XCode6 XCode7 ). For this unit, I'd like you to identify additional member variables (data) that would be appropriate for the class FlashDrive. I would also like you to identify additional methods (functions) that would be appropriate for the classFlashDrive. Update and resubmit the .h file for FlashDrive 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 CHANGES, ALTHOUGH YOU ARE WELCOME TO DO MORE THAN THIS IF YOU WISH.
Class Details
Sample Driver
FlashDrive
FlashDrive();
FlashDrive( int capacity, int size,bool pluggedIn );
void setCapacity( int amount );
int getCapacity( );
void setUsed( int amount );
int getUsed( );
bool isPluggedIn( );
void plugIn();
void pullOut();
void writeData( int amount );
void eraseData( int amount );
void formatDrive( );
int my_Size;
int my_Contents;
bool my_IsPluggedIn;
int 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;
return( 0 );
}
Class Details
Sample Driver
FlashDrive
FlashDrive();
FlashDrive( int capacity, int size,bool pluggedIn );
void setCapacity( int amount );
int getCapacity( );
void setUsed( int amount );
int getUsed( );
bool isPluggedIn( );
void plugIn();
void pullOut();
void writeData( int amount );
void eraseData( int amount );
void formatDrive( );
int my_Size;
int my_Contents;
bool my_IsPluggedIn;
#include "FlashDrive.h"
using namespace std;
int 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;
return( 0 );
}
Explanation / Answer
class FlashDrive
{
friend FlashDrive operator+ (FlashDrive used1 , FlashDrive used2);
friend FlashDrive operator= (FlashDrive used1);
friend bool operator <( const FlashDrive &lhs, const FlashDrive &rhs );
friend bool operator >( const FlashDrive &lhs, const FlashDrive &rhs );
public:
/*void FlashDrive::operator= (FlashDrive usedtotal)
{
my_StorageUsed = usedtotal.getUsed();
}*/
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( );
private:
int my_StorageCapacity;
int my_StorageUsed;
bool my_IsPluggedIn;
}
drive1,drive2;
FlashDrive operator +(FlashDrive used1, FlashDrive used2 )
{
FlashDrive combined;
combined = (used1.getUsed()+ used2.getUsed());
return combined;
}
bool operator <(FlashDrive &lhs,FlashDrive &rhs )
{
return ( lhs.getUsed() < rhs.getUsed() );
}
bool operator >(FlashDrive &lhs,FlashDrive &rhs )
{
return ( operator <( rhs, lhs ) );
}
FlashDrive operator -(FlashDrive used1, FlashDrive used2 )
{
FlashDrive other;
other= (used1.getUsed()-used2.getUsed());
return other;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.