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

Hi, I need help designing a class to work with some test program code that was p

ID: 3629443 • Letter: H

Question

Hi, I need help designing a class to work with some test program code that was provided for me. I am really just having trouble getting started, I know that I need a copy constructor, a default constructor, a 2 argument constructor, assignment operator and a destructor. I also need to have the output << operator overloaded. I have started working on the class myself I just don't think that I am on the right track. Any help would be appreciated. I have no idea what the ID CopyCheck is at the very top, I have never seen anything like that before the main statement. I provided this code before but did not really get the help that I was looking for, I need help with the actual code, not just telling me what constructors and functions I need to write.

I have included the test code that we are supposed to design the class header file "id.h" and the class program file "id.cpp" around.


#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <id.h>
// #include <id.cpp> // in lieu of makefile

const size_t arraySize = 10;
const size_t numDigits = 2;

ID CopyCheck (ID id) // pass in by value calls CC
{
ID x = id; // initialization calls CC (NOT assignment!)
return x; // return by value calls CC
}

int main()
{
ID p1, p2("Chris Lacher", 100);
std::cout << " IDs after declaration: ";
std::cout << " p1 = " << p1 << ' ';
std::cout << " p2 = " << p2 << ' ';

p1.SetName("blah");
p1.SetAge(44);
p2.SetName("blahblah");
p2.SetAge(44);
std::cout << " IDs after Set: ";
std::cout << " p1 = " << p1 << ' ';
std::cout << " p2 = " << p2 << ' ';

p1 = CopyCheck(p2);
std::cout << " IDs after p1 = CopyCheck(p2): ";
std::cout << " p1 = " << p1 << ' ';
std::cout << " p2 = " << p2 << ' ';

ID p3 ("Assignment Check", 50);
p1 = p2 = p3;
std::cout << " IDs after p1 = p2 = p3: ";
std::cout << " p1 = " << p1 << ' ';
std::cout << " p2 = " << p2 << ' ';
std::cout << " p3 = " << p3 << ' ';

ID * idarray = new ID [arraySize];
std::cout << " ID Array after declaration: ";
for (size_t i = 0; i < arraySize; ++i)
{
std::cout << " id[" << std::setw(numDigits) << i << "] = " << idarray[i] << ' ';
}


for (size_t i = 0; i < arraySize; ++i)
{
idarray[i].SetName("A. B. Student");
idarray[i].SetAge(17 + i);
}
std::cout << " ID Array after Set: ";
for (size_t i = 0; i < arraySize; ++i)
{
std::cout << " id[" << std::setw(numDigits) << i << "] = " << idarray[i] << ' ';
}
}

Explanation / Answer

class ID

{

private: string name;

int age;

public: void SetName(string name1)

{

name = name1;
}

void SetAge(int a)

{

age = a;
}

ID& ID::operator=(ID const& p)
{
   if (this == &p) return *this;
this.name = p.name;

this.ae =p.age;
   return *this;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote