Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> using namespace::std; class coin { friend ostream & operator

ID: 652502 • Letter: #

Question

#include <iostream>
using namespace::std;

class coin {
   friend ostream & operator << ( ostream &, const coin &);
   friend bool operator == ( int n, const coin & right);
               // will return true if n is equal to the count field of right

   public:
           coin(void);
           coin(int ct, const char * d);
           coin(const coin &);
           ~coin(void);

           int getCount(void) const;

           coin & setCount(int n);
           coin & setDesc( const char *);

           const coin & getLarger( const coin & ) const;
               // will return as an alias the larger coin
               // , i.e. larger of the invoking instance and the paramater
               // use getCount() to determine the largest

           const coin & operator = ( const coin &);

           coin operator + ( const coin & ) const;
               // return coin with counts added
               // same desc as the invoking instance

           bool operator == ( const coin &) const;
               // return true if the counts are equal

           bool operator == ( int v) const;
               // return true if v is equal to the count field

   private:
           const char * getDesc(void) const;
           int count;
           char desc[25];
   };

class bank {
   friend ostream & operator<<(ostream &, const bank &);

   public:
           bank(void);
           bank(int, const char * coinDesc, const char * ownerName);
           bank(const bank &);
           bank( const coin &, const char * ownerName);

           ~bank();

           int getCount(void) const;

           bank & changeOwner( const char *);

           const bank & operator = (const bank &);

           bool operator == ( const bank & ) const;
               // will return true if the owners are equal as strings
               // and coin fields data are equal as coins

           bool operator != ( const bank &) const;
       private:
           coin data;
           char * owner;
   };


// Write the Class functions

ostream & operator << ( ostream & w, const coin & c)
{
w << c.getDesc() << " C " << c.getCount() << " C " ;
return w;


}

bool operator == (int n, const coin & right)
               // will return true if n is equal to the count field of right

{
if (n == right.count)
{
return true;
}
else{
return false;


}
}


coin::coin(void)
{
setCount(0).setDesc(0);

}

coin::coin(int ct, const char * d)
{
setCount(ct).setDesc(d);

}

coin::coin(const coin & other) //: data(other.data), count(other.count),disc(other.disc)
{
setCount(other.getCount()).setDesc(other.getDesc());


}


coin::~coin(void)
{

}

int coin::getCount(void) const
{
return count ;


}

const char * coin::getDesc(void) const
{
return desc;


}

coin & coin::setCount(int count) // MUST USE THE PARAMETER NAME OF COUNT
{

this->count = count;
return *this;
  

}

coin & coin::setDesc( const char * c)
{
strcpy(this->desc, c);
return * this;
  


}

const coin & coin::getLarger( const coin & right ) const
{
if (this->count > right.count)
{
return *this;
}
else{
  
return right;

}

}

// In the above function, explain the 3 uses of const


const coin & coin::operator = ( const coin & right)
{

if( this == & right ) return *this;
this->count = right.count;
strcpy(this->desc, right.desc);

return *this;


}

coin coin::operator + ( const coin & right) const
{
                       // return coin with counts added
                   // same desc as the invoking instance

coin temp;
temp.setCount(this->getCount());
temp.setDesc(this->getDesc());

return temp;


}


bool coin::operator == ( const coin & right) const
               // return true if the counts are equal
{


return((this->getCount() == right.getCount()) && (this->getDesc() == right.getDesc()));

}

bool coin::operator == ( int v) const
               // return true if v is equal to the count field
{
return (this->getCount() == v) ? true : false;

}

// ****** bank functions *******

ostream & operator<<(ostream & w, const bank & b)
{
w << b.getCount() << "Count: " << b.data;

return w;
}
bank::bank(void): data()
{


  
owner = new char[4];
   strcpy(owner, "N/A");

  
// data = count;
// owner = desc ;


}

bank::bank(int a, const char * coinDesc, const char * ownerName): data(a, coinDesc) //, owner(ownerName)

{

changeOwner(ownerName);
//coin (a, coinDesc);
  

}

bank::bank(const bank & other): data(other.data), //owner(other.owner)
{
changeOwner(other.owner);
}

bank::bank( const coin & c, const char * ownerName) : data(c) //, owner(ownerName)
{

strcpy(owner, ownerName);
}
bank::~bank()
{
}
int bank::getCount(void) const
{
return data.getCount();
}

bank & bank::changeOwner( const char * c)
{
if(c != nullptr)
{
if(owner != nullptr)
   {
   delete owner;
   }
owner = new char[strlen(c) + 1];
   strcpy(owner, c);
}
}

const bank & bank::operator = (const bank & right)
{
if(this == & right ) return *this;
this->data = right.data ;
  
//this->owner= right.owner ;
owner = new char[right];


return *this;

}

bool bank::operator == ( const bank & right ) const
{
// will return true if the owners are equal as strings
// and the coin fields are equal as coins
return (this->getCount() == right.getCount()) ? true: false;

}

bool bank::operator != ( const bank & right ) const
{
return (this->getCount() != right.getCount()) ? true: false;
  
}
// *****************************************************************************
// Client functions

coin returnLarger( const coin & left, const coin & right)
           // will return the larger coin, based on the count value
           // the desc of the coin returned will be "Larger Coin";
{ // write returnLarger now

}

int main()
{
   coin a(4,"Dime");
   coin c(5,"Penny"), d(12,"Quarter"), e(15,"$20 Gold Coin"), f;
   bank b(24,"Dollar Bill", "John Doe");

       cout << a << b << c;
   // Write the above using function notation:

   // ________________________________________________________
   //   operator <<(operator<<(operator<<(cout, a ), b), c);
       f = (c + d) + e;
   // Write the above using function notation NOTE: There are 3 operators:
   f = c.operator +(d).operator + (e);
   // __________________________________________________________
   return 0;
}

In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1Viostream:38: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ios:216: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ locale:15: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string:439: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:628: In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:604: /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iterator:341:10: fatal error debug file not found #include debug 1 error generated.

Explanation / Answer

Somewhere you are missing the file path or you have given wrong file path..

make it proper then check it works fine