C FlashDrive PLEASE show 3 files 1maincpp 2flashdrive20h 3fl
C++ FlashDrive
PLEASE show 3 files!!!!
1---main.cpp
2---flashdrive_2_0.h
3---flashdrive_2_0.cpp
FlashDrive
Sample Driver Code
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( );
#include
#include \"FlashDrive.h\"
using namespace std;
using namespace cs52;
void main( )
{
cs52::FlashDrive drive1( 10, 0, false );
cs52::FlashDrive drive2( 20, 0, false );
drive1.plugIn( );
drive1.formatDrive( );
drive1.writeData( 5 );
drive1.pullOut( );
drive2.plugIn( );
drive2.formatDrive( );
drive2.writeData( 1 );
drive2.pullOut( );
cs52::FlashDrive combined = drive1 + drive2;
cout << \"this drive\'s filled to \" << combined.getUsed( ) << endl;
cs52::FlashDrive other = combined – drive1;
cout << \"the other cup\'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;
}
}
int my_StorageCapacity;
int my_StorageUsed;
bool my_IsPluggedIn;
| FlashDrive | Sample Driver Code |
| FlashDrive( ); void plugIn( ); int getCapacity( ); int getUsed( ); bool isPluggedIn( ); | #include void main( ) if (combined > other) { if (drive2 < drive1) { |
| int my_StorageCapacity; |
Solution
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class SodaCan {
public:
SodaCan();
SodaCan(string brand, int size, int contents);
bool isEmpty();
void pourInSoda(int amount);
void drink(int amount);
void setSize(int size);
int getSize() const;
string getBrand() const;
void setBrand(string brand);
int getContents() const ;
friend SodaCan operator+ (const SodaCan& left, const SodaCan& right);
friend SodaCan operator- (const SodaCan& left, const SodaCan& right);
friend bool operator> (const SodaCan& left, const SodaCan& right);
friend bool operator< (const SodaCan& left, const SodaCan& right);
friend bool operator>= (const SodaCan& left, const SodaCan& right);
friend bool operator<= (const SodaCan& left, const SodaCan& right);
friend bool operator== (const SodaCan& left, const SodaCan& right);
friend bool operator!= (const SodaCan& left, const SodaCan& right);
friend std::ostream& operator <<(std::ostream& os, const SodaCan* my_can);
friend std::istream& operator>>(std::istream& ins, SodaCan *&can);
private:
string my_Brand;
int my_Size;
int my_Contents;
};
int main(){
SodaCan myPepsi;
SodaCan yourDietCoke;
SodaCan bigGulp;
SodaCan junk;
bigGulp.setBrand(\"Pepsi\");
bigGulp.setSize(128);
myPepsi.setBrand(\"Pepsi\");
myPepsi.setSize(12);
yourDietCoke.setBrand(\"Coke\");
yourDietCoke.setSize(12);
myPepsi.pourInSoda(2);
yourDietCoke.pourInSoda(3);
bigGulp.pourInSoda(64);
/// junk should have 76 ounces
junk = bigGulp + myPepsi;
cout << junk;
if (junk > bigGulp) {
cout << \"junk