Project 8: Better FlashDrive I have provided you with a sample class named Flash
ID: 3814214 • Letter: P
Question
Project 8: 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 ( XCode5 or XCode6 or XCode7 or VS2010 or VS2012 ). 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 class FlashDrive. 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.
FlashDrive
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( );
Sample Driver Code
can anyone help me on this problem
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;
Sample Driver Code
#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; }
Explanation / Answer
ANSWER:
//You can write the following code in your header file.
#ifndef FlashDrive_h
#define FlashDrive_h
#include <iostream>
using namespace std;
class FlashDrive
{
//as seen in the format, we have 3 private variables
int StorageCapacity;
int StorageUsed;
bool IsPluggedIn;
public:
//default constructor will set everything to false or 0
FlashDrive()
{
StorageCapacity=0;
StorageUsed=0;
IsPluggedIn=0;
}
FlashDrive( int capacity, int used, bool pluggedIn )
{
StorageUsed=used;
StorageCapacity=capacity;
IsPluggedIn=pluggedIn;
}
void plugIn()
{
IsPluggedIn=1;
}
void pullOut()
{
IsPluggedIn=0;
}
void writeData( int amount )
{
//this condition is important as we might not want to overflow data
if(StorageCapacity-StorageUsed>amount)
StorageUsed+=amount;
else
cout<<" Not enough space ";
}
void eraseData( int amount )
{
StorageUsed-=amount;
if(StorageUsed<0)
StorageUsed=0;
}
void formatDrive( )
{
StorageUsed=0;
}
int getCapacity( )
{
return StorageCapacity;
}
void setCapacity( int amount )
{
StorageCapacity=amount;
}
int getUsed( )
{
return StorageUsed;
}
void setUsed( int amount )
{
if(amount>StorageCapacity)
cout<<" Amount given greater than capacity";
else
StorageUsed=amount;
}
bool isPluggedIn( )
{
return IsPluggedIn;
}
};
#endif / END OF THE HEADER FILE/
YOUR OUTPUT WILL BE LIKE THIS:
Output:
Welcome to Howie's Flash USB Drive Store!
How much memory do you need? 100
Let's format the drive...
Let's plug in the drive...
Let's write some data...
Let's unplug the drive...
Enjoy your drive!!
Program ended with exit code: 0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.