Menu

[Solved]Getting Way Many Errors Member Accessible Please Solve Project 3 Files Required Maincpp Fi Q37177363

I am getting way too many errors such as member in accessible.Please solve this project. 3 files are required.

here in the main.cpp file,

Sample Driver Code

cs101::FlashDrive drive1( 10, 0, false );cs101::FlashDrive drive2( 20, 0, false ); drive1.plugIn( );drive1.formatDrive( );drive1.writeData( 5 );drive1.pullOut( );drive2.plugIn( );drive2.formatDrive( );drive2.writeData( 1 );drive2.pullOut( );cs101::FlashDrive combined = drive1 + drive2;cout << “this drive’s filled to ” << combined.getUsed() << endl;cout << “this drive’s capacity is ” <<combined.getCapacity() << endl;cs101::FlashDrive other = drive1 – drive2;cout << “the other drive’s filled to ” <<other.getUsed( ) << endl;cout << “the other drive’s capacity is ” <<other.getCapacity() << 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;}

Help please with a Project in C++

In C++, many of the keyboard symbols that are used between twovariables can be given a new meaning. This feature is calledoperator overloading and it is one of the most popular C++features. Any class can choose to provide a new meaning to akeyboard symbol. Not every keyboard letter is re-definable in thisway, but many of the ones we have encountered so far are like +, -,*, /, >and <for example. It is a class’ choice to do this, somostly it is viewed as a driver code convenience to supportthem.

But because so many of us have an assumption that +should doaddition but also perform string concatenation when working withtextual data. Each operator becomes a friendfunction in C++ that your class can implement. Thearguments to most of the operator overloads are defined as constFlashDrive &. This syntax is a new kind of parameter passingcalled const-reference parameters.

For a class type, like FlashDrive, const &signifies aread-only argument that cannot be changed by the function thatreceives this object. The compiler enforces this restriction and,for classes, const &simulates a pass-by-value mechanism withoutthe overhead of copying the object, which might take a tremendousamount of time away from our program. Read the book and demo sourceexamples carefully to see how this is done. Trust me, the firsttime you work with operators in C++, it is a very error-proneprocess. My best advice to you is to complete one operator at atime.

place FlashDrivein namespace cs101 which will affectthe resulting driver code as well as the class’ .hand .cppfiles. *Note: your code will not compile until you define thecs101namespace

Flashdrive 2.0

Rules of the flashdrive comparisons:

  1. The addition operator ( +) combines two flashdrives by createda new flashdrive that has the larger capacity of the two operandflashdrives (e.g. if you have a 20GB flash drive and add it to a10GB flashdrive, the resulting flashdrive has 20GB of space, not10GB – capacity is the max()operation). Then, the operator shouldmark that the new flash drive has used the sum of the two operand’sflashdrives (for instance, if one of the operands used 5GB and theother used 12GB, the resulting flashdrive has used 17GB).
  2. The subtraction operator ( -) substracts two flashdrives bycreated a new flashdrive that has the larger capacity of the twooperand flashdrives (e.g. if you have a 20GB flash drive andsubtract a 10GB flashdrive, the resulting flashdrive has 20GB ofspace, not 10GB – capacity is the max()operation). Then, theoperator should remove the right operand’s storage from the leftoperand (for instance, if the left operand has used 20GB and theother used 12GB, the resulting flashdrive has used 8GB).
  3. The less than operator ( <) should compare the if the leftoperand’s storage used is less than the right operand’s storageused.
  4. The greater than operator ( >) should compare the if theleft operand’s storage used is greater than the right operand’sstorage used.

Using flashdrive_2_0.cpp, enhance the FlashDriveclass so that itsupports the operators +, -, <and >. A sample pile of drivercode is shown below to assist you in this effort. Operators+and-should create a new FlashDrivefrom the two arguments by combiningtheir contents. If you wind up with a FlashDrivewith a value storedthat exceeds its capacity, print out an error message. If you windup with a negative capacity or storage value, print out an errormessage. Operators <and >must return booland should comparethe holdings of the two arguments to determine which one isbigger.

My strong advice is to work one operator at a time, as thesesteps are very error-prone and lead to many, many compileerrors.

Finally, I would also like you to place FlashDrivein namespacecs52which will affect the resulting driver code as well as theclass’ .hand .cppfiles. * Note:your code will notcompile until you define the cs52namespace

This is the header file:

FlashDrive 2.0

FlashDrive( );FlashDrive( int capacity, int used, bool pluggedIn );void plugIn( );bool isPluggedIn( );void pullOut( );void writeData( int amount );void eraseData( int amount );void formatDrive( );void setCapacity( int amount );void setUsed( int amount );int getCapacity( );int getUsed( );

Here is the flashdrive.cpp file

#include “FlashDrive.h”
#include <iostream>

FlashDrive::FlashDrive( ) {
my_StorageCapacity = 0;
my_StorageUsed = 0;
my_IsPluggedIn = false;
}

FlashDrive::FlashDrive( int capacity, int used, boolpluggedIn ) {
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 ) { //Eraseamount of data
my_StorageUsed -= amount;
}

void FlashDrive::formatDrive( ) { //Clear data
my_StorageUsed = 0;
}

int FlashDrive::getCapacity( ) {
return( my_StorageCapacity );
}

void FlashDrive::setCapacity( int amount ) {
my_StorageCapacity = amount;
}

int FlashDrive::getUsed( ) {
return( my_StorageUsed );
}

void FlashDrive::setUsed( int amount ) {
my_StorageUsed = amount;
}

bool FlashDrive::isPluggedIn( ) {
return( my_IsPluggedIn );
}

/* Create new flashdrive from arguments by addingcontents */
FlashDrive operator+(const FlashDrive &left, const FlashDrive&right)
{
int new_Capacity;
if (left.my_StorageCapacity >= right.my_StorageCapacity)
{
new_Capacity = left.my_StorageCapacity;
}
else
{
new_Capacity = right.my_StorageCapacity;
}
int new_StorageUsed = left.my_StorageUsed +right.my_StorageUsed;
FlashDrive temp = FlashDrive(new_Capacity, new_StorageUsed,false);
temp.checkForErrors(new_Capacity, new_StorageUsed);
return temp;
}

/* Create new flashdrive from arguments by subtractingcontents */
FlashDrive operator-(const FlashDrive &left, const FlashDrive&right)
{
int new_Capacity;
if (left.my_StorageCapacity >= right.my_StorageCapacity)
{
new_Capacity = left.my_StorageCapacity;
}
else
{
new_Capacity = right.my_StorageCapacity;
}
int new_StorageUsed = left.my_StorageUsed -right.my_StorageUsed;
FlashDrive temp = FlashDrive(new_Capacity, new_StorageUsed,false);
temp.checkForErrors(new_Capacity, new_StorageUsed);
return temp;
}

/* With < operator, compare holdings of two arguments*/
bool operator<(const FlashDrive &left, const FlashDrive&right)
{
return (left.my_StorageUsed < right.my_StorageUsed);
}

/* With > operator, compare holdings of two arguments*/
bool operator>(const FlashDrive &left, const FlashDrive&right)
{
return (left.my_StorageUsed > right.my_StorageUsed);
}

/* Check for errors and print error messages */
void FlashDrive::checkForErrors(int new_Capacity, intnew_StorageUsed) {
if (new_StorageUsed > new_Capacity) {
cout << “error: capacity exceeded by ” <<new_StorageUsed – new_Capacity << ” kilobytesn”;
}
if (new_Capacity < 0) {
cout << “error: negative capacity (” << new_Capacity<< “)n”;
}
if (new_StorageUsed < 0) {
cout << “error: negative storage used (” <<new_StorageUsed << “)n”;
}
}

Sample Output

this drive’s filled to 6 this drive’s capacity is 20 the other drive’s filled to 4 the other drive’s capacity is 20 looks like combined is bigger… looks like other is bigger… looks like drive2 is smaller…

Expert Answer


Answer to I am getting way too many errors such as member in accessible. Please solve this project. 3 files are required. here in… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *