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

In class, the following two files are used to describe an introductory level obj

ID: 3796737 • Letter: I

Question

In class, the following two files are used to describe an introductory level object oriented program in C++. However, the files may not be complete. Implement the code as a header file and an implementation file and modify the code, if needed to make it operate as advertised. Follow the usual submission rules with your code in .cpp and .h files.

///////// thinker.h

class thinking_cap

{

public:

     void slots(char new_green[ ], char new_red[ ]);

     void push_green( ) const;

     void push_red( ) const;

private:

     char green_string[50];

     char red_string[50];

};

//////// thinker.cpp

#include <iostream.h>

#include <stdlib.h>

#include "thinker.h"

int main( )

{

    thinking_cap student;

    thinking_cap fan;

    student.slots( "Hello", "Goodbye");

    fan.slots( "Go Cougars!", "Boo!");

    student.push_green( );

    fan.push_green( );

    student.push_red( );

return 0;

}

void thinking_cap::slots(char new_green[ ], char new_red[ ])

{

     assert(strlen(new_green) < 50);

     assert(strlen(new_red) < 50);

     strcpy(green_string, new_green);

     strcpy(red_string, new_red);

}

void thinking_cap::push_green

{

     cout << green_string << endl;

}

void thinking_cap::push_red

{

     cout << red_string << endl;

}

Explanation / Answer

#include <iostream.h>

#include <stdlib.h>

#include "thinker.h"

//base class

class thinking_cap

{

public:

     void slots(char new_green[ ], char new_red[ ]);

     void push_green( ) const;

     void push_red( ) const;

private:

     char green_string[50];

     char red_string[50];

};

//derived class

class thicker: public thinking{

void slots(char new_green[ ], char new_red[ ])

{

     assert(strlen(new_green) < 50);

     assert(strlen(new_red) < 50);

     strcpy(green_string, new_green);

     strcpy(red_string, new_red);

}

void push_green

{

     cout << green_string << endl;

}

void push_red

{

     cout << red_string << endl;

}

};

// main function in which created two obtects for the class "thinking"

and called the function of another class thinker by inheritance

int main( )

{

    thinking_cap student;

    thinking_cap fan;

    student.slots( "Hello", "Goodbye");

    fan.slots( "Go Cougars!", "Boo!");

    student.push_green( );

    fan.push_green( );

    student.push_red( );

return 0;

}

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