I have provided you with a sample class named FlashDrive which has been diagrammed below. Using the FlashDrive class provided earlier, upgrade the class so that it supports various operators. Make operator+ combine together the contents of two FlashDrive, as long as the contents does not exceed the size. Make operator- subtract one FlashDrive contents from another, as long as the size or contents don't go negative. Support the >> and << operators to allow instances to be read from cin or written to cout. Make the boolean operators <, >, <= and >= test FlashDrive's contents. Make the boolean operator == and != test all of the data members of a TrashCan for an exact match.
//FlashDrive header file declaration
//FlashDrive.h
#ifndef FLASDRIVE_H
#define FLASDRIVE_H
#include<iostream>
using namespace std;
class FlashDrive
{
public:
FlashDrive();
FlashDrive(int capacity, int used, bool
pluggedIn);
void plugIn();
void pullOut();
void writeData(int amount);
void eraseData(int amount);
void formatDrive();
int getCapacity();
int getUsed();
void setUsed(int amount);
bool isPluggedIn();
//declaratio of overload +,-
friend FlashDrive operator+(FlashDrive
&f1,FlashDrive &f2);
friend FlashDrive operator-(FlashDrive
&f1,FlashDrive &f2);
//declaratio of overload <,<=
friend bool operator<(FlashDrive &f1,FlashDrive
&f2);
friend bool operator<=(FlashDrive
&f1,FlashDrive &f2);
//declaratio of overload >,>=
friend bool operator>(FlashDrive &f1,FlashDrive
&f2);
friend bool operator>=(FlashDrive
&f1,FlashDrive &f2);
//declaratio of overload ==, !=
friend bool operator==(FlashDrive &f1,FlashDrive
&f2);
friend bool operator!=(FlashDrive &f1,FlashDrive
&f2);
//declaratio of overload <<,>>
friend ostream& operator<<(ostream&out,
FlashDrive &f);
friend istream& operator>>(istream&out,
FlashDrive &f);
private:
int my_StorageCapacity;
int my_StorageUsed;
bool my_IsPluggedIn;
};
#endif FLASDRIVE_H
--------------------------------------------------------------------------------------------------------
//implemenation of FlashDrive.cpp
//FlashDrive.cpp
#include "FlashDrive.h"
FlashDrive::FlashDrive()
{
my_StorageCapacity=0;
my_StorageUsed=0;
my_IsPluggedIn=false;
}
FlashDrive::FlashDrive(int capacity, int used, bool
pluggedIn)
{
my_StorageCapacity=capacity;
my_StorageUsed=used;
my_IsPluggedIn=pluggedIn;
}
void FlashDrive::plugIn()
{
my_IsPluggedIn=true;
}
void FlashDrive::pullOut()
{
my_IsPluggedIn=false;
}
void FlashDrive::writeData(int amount)
{
my_StorageUsed+=amount;
}
void FlashDrive::eraseData(int amount)
{
my_StorageUsed-=amount;
}
void FlashDrive::formatDrive()
{
my_StorageUsed=0;
}
int FlashDrive::getCapacity()
{
return my_StorageCapacity;
}
int FlashDrive::getUsed()
{
return my_StorageUsed;
}
void FlashDrive::setUsed(int amount)
{
this->my_StorageUsed=amount;
}
bool FlashDrive::isPluggedIn()
{
return my_IsPluggedIn;
}
FlashDrive operator+(FlashDrive &f1,FlashDrive
&f2)
{
FlashDrive combined;
combined.my_StorageCapacity=f1.getCapacity()+f2.getCapacity();
combined.my_StorageUsed=f1.getUsed()+f2.getUsed();
return combined;
}
FlashDrive operator-(FlashDrive &f1,FlashDrive &f2)
{
FlashDrive combined;
combined.my_StorageCapacity=f1.getCapacity()-f2.getCapacity();
combined.my_StorageUsed=f1.getUsed()-f2.getUsed();
return combined;
}
bool operator<(FlashDrive &f1,FlashDrive &f2)
{
return f1.getCapacity() < f2.getCapacity()
&& f1.getUsed() <
f2.getUsed();
}
bool operator>(FlashDrive &f1,FlashDrive &f2)
{
return f1.getCapacity() > f2.getCapacity()
&& f1.getUsed() >
f2.getUsed();
}
bool operator<=(FlashDrive &f1,FlashDrive &f2)
{
return f1.getCapacity() <= f2.getCapacity()
&& f1.getUsed() <=
f2.getUsed();
}
bool operator>=(FlashDrive &f1,FlashDrive &f2)
{
return f1.getCapacity() >= f2.getCapacity()
&& f1.getUsed() >=
f2.getUsed();
}
bool operator==(FlashDrive &f1,FlashDrive &f2)
{
return f1.getCapacity() == f2.getCapacity()
&& f1.getUsed() ==
f2.getUsed()
&& f1.isPluggedIn()
==f2.isPluggedIn();
}
bool operator!=(FlashDrive &f1,FlashDrive &f2)
{
return f1.getCapacity() != f2.getCapacity()
&& f1.getUsed() !=
f2.getUsed()
&& f1.isPluggedIn()
!=f2.isPluggedIn();
}
//overloaiding << operator
ostream & operator << (ostream &out, FlashDrive
&f)
{
out << "Capacity :
"<<f.my_StorageCapacity
<< "Used : " << f.my_StorageUsed
<< "Plugged In : " << f.my_IsPluggedIn
<<endl;
return out;
}
//overloaiding >> operator
istream & operator >> (istream &in, FlashDrive
&f)
{
cout << "Enter capacity";
in >> f.my_StorageCapacity;
cout << "Enter used used ";
in >> f.my_StorageUsed;
return in;
}
--------------------------------------------------------------------------------------------------------
//Test cpp file for FlashDrive class
//Main.cpp
#include<iostream>
//include header file
#include "FlashDrive.h"
using namespace std;
//main method
int main()
{
//Create an object of FlashDrive
FlashDrive drive1(10,0,false);
FlashDrive drive2(20,0,false);
//calling methods
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<<"this other drive's filled to "
<<combined.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
bigger..."
<<endl;
}
else{
cout<<"looks like drive1 is
bigger..."
<<endl;
}
system("pause");
return 0;
}
--------------------------------------------------------------------------------------------------------
Sampel result :
I have provided you with a sample class named FlashDrive which has been diagrammed below. Using...
Project 1 - Operator Overloading (FlashDrive 2.0) In C++, many of the keyboard symbols that are used between two variables can be given a new meaning. This feature is called operator overloading and it is one of the most popular C++ features. Any class can choose to provide a new meaning to a keyboard symbol. Not every keyboard letter is re-definable in this way, but many of the ones we have encountered so far are like +, -, *, /,...
Help please with a Project in C++ In C++, many of the keyboard symbols that are used between two variables can be given a new meaning. This feature is called operator overloading and it is one of the most popular C++ features. Any class can choose to provide a new meaning to a keyboard symbol. Not every keyboard letter is re-definable in this way, but many of the ones we have encountered so far are like +, -, *, /,...
Background: This assignment deals with inheritance. Inheritance is one of the major principles of object-oriented programming. In C++, one of the biggest goals is "code reuse". Inheritance accomplishes this. In order to get inheritance working in C++, you must get both the structure of your .h files as well as the implementation of your constructor correct. Constructor implementations must use an initialization list. Please review the book and the online content on these issues so you know how it works...
Background: The purpose of this assignment is to practice dealing with exception handling and textual data. Exception handling is a very important part of being an object-oriented programming. Rather returning some kind of int return value every time you tickle an object, C++ programmers expect methods to focus on their task at hand. If something bad happens, C++ programmers expect methods to throw exceptions. When caught, exceptions can be processed. When uncaught, they cause a program to terminate dead in...
Please zoom in so the pictures become high resolution. I need three files, FlashDrive.cpp, FlashDrive.h and user_main.cpp. The programming language is C++. I will provide the Sample Test Driver Code as well as the codes given so far in text below. Sample Testing Driver Code: cs52::FlashDrive empty; 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(2); drive2.pullOut(); cs52::FlashDrive combined = drive1 + drive2; // std::cout << "this drive's filled to " << combined.getUsed( )...
Project 2 - Flashdrive 1.0 I have provided you with a sample class named FlashDrive which has been diagrammed below and described in the online course content. 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. Submit a .h file for FlashDrive with the new possible methods and members you have...
In this assignment you are required to complete a class for fractions. It stores the numerator and the denominator, with the lowest terms. It is able to communicate with iostreams by the operator << and >>. For more details, read the header file. //fraction.h #ifndef FRACTION_H #define FRACTION_H #include <iostream> class fraction { private: int _numerator, _denominator; int gcd(const int &, const int &) const; // If you don't need this method, just ignore it. void simp(); // To get...
1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...
C++ - I have a doubly linked list, but I haven't been able to get the "reverse list" option in the code to work(It's option #in the menu in the program). I received this guidance for testing: Test 4 cases by entering (in this order) c,a,z,k,l,m This tests empty list, head of list, end of list and middle of list. Then delete (in this order) a,z,l. This tests beginning, end and middle deletes. This exhaustively tests for pointer errors. #include...
You have been developing a Fraction class for Teacher’s Pet Software that contains several fields and functions. a. Add four arithmetic operators, +, -, *, and /. Remember that to add or subtract two Fractions, you first must convert them to Fractions with a common denominator. You multiply two Fractions by multiplying the numerators and multiplying the denominators. You divide two Fractions by inverting the second Fraction, then multiplying. After any arithmetic operation, be sure the Fraction is in proper...