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

Explain each line in thinker.cpp & thiner.h For example.... int main () //this i

ID: 3797037 • Letter: E

Question

Explain each line in thinker.cpp & thiner.h

For example.... int main () //this is the main method

Also, explain what this program is doing in detail. List the preconditions and post conditions of this program.

//thinker.cpp

#include <iostream.h>

#include <cstdlib>

#include <cassert>

#include "thinker.h"

using namespace std;

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;

}

//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];

};

Explanation / Answer

Hi, Please find my explanaton.

Please let me know in case of any issue.


//thinker.cpp
#include <iostream.h>
#include <cstdlib>
#include <cassert>
#include "thinker.h"
using namespace std;

int main( )
{
thinking_cap student; // creating an object of thinking_cap class named 'student'

thinking_cap fan;// creating an object of thinking_cap class names 'fan'

// calling 'slots' method of student object and passing two char array as parameter
student.slots( "Hello", "Goodbye");

// calling 'slots' method of fan object and passing two char array as parameter
fan.slots( "Go Cougars!", "Boo!");

// calling 'push_green' method of student object
student.push_green( );

// calling 'push_green' method of fan object
fan.push_green( );

// calling 'push_red' method of student object
student.push_red( );
return 0;
}

// Precondition: length of new_green and new_red array should < 50
// Postcondition: store the content of new_green in green_string
//                   and store the content of new_red in red_string
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);
}

// Precondition: green_string should be initialized
// Postcondition : content of green_string will be printed on terminal
void thinking_cap::push_green
{
cout << green_string << endl;
}

// Precondition: red_string should be initialized
// Postcondition : content of red_string will be printed on terminal
void thinking_cap::push_red
{
cout << red_string << endl;
}




//thinker.h
class thinking_cap
{

public:
   // this function takes two charater array as input and store the content of these array in
   // green_string and red_string of class variable
void slots(char new_green[ ], char new_red[ ]);
// this function display the content of push_green
void push_green( ) const;
// this function display the content of red_string
void push_red( ) const;

private:
   // these are the member variables of class thinking_cap
char green_string[50]; // char array of size 50
char red_string[50];
};

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