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 program code that was provid

ID: 3629369 • Letter: H

Question

Hi, I need help designing a class to work with some program code that was provided for me. I am really just having trouble getting started, I know that I have to declare the SetName and SetAge functions but I am not sure what to do with the ID thing in the top of the program. I have started working on the class header file but just don't think I am on the right track. Any help would be appreciated it. I have included the test code that we are supposed to design the class "id.h" 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

For the header file "ID.h" #include #include using namespace std; #ifndef ID_H #define ID_H class ID { private: string name; int age; public: friend ostream& operatorname = rhs.name; } //------------------------------------------------------- const ID& ID::operator=(const ID& rhs) { if (this != &rhs) { this->name = rhs.name; this->age = rhs.age; } return *this; } //------------------------------------------------------- std::ostream& operator
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