Answer to Question #261333 in C++ for Appu

Question #261333

 Rewrite the code in C++ using Factory Method. The goal is to remove the

main function’s dependency on the concrete classes, such as WalkToSchool.


#ifndef WALKTOSCHOOL_H

#define WALKTOSCHOOL_H

#include <iostream>

#include "GoToSchool.hpp"


using namespace std;


class WalkToSchool:public GoToSchool {

  void takeTransit() { cout << "We are walking to school." << endl; }

  void arrive() { cout << "After 10 minutes, we arrive." << endl; }

};


#endif


1
Expert's answer
2021-11-05T07:25:18-0400
#ifndef WALKTOSCHOOL_H
#define WALKTOSCHOOL_H

#include <iostream>
#include "GoToSchool.hpp"

using namespace std;

class WalkToSchool:public GoToSchool {
  void takeTransit() { cout << "We are walking to school." << endl; }
  void arrive() { cout << "After 10 minutes, we arrive." << endl; }
};

WalkToSchool *createNewWalkToSchool() {
  return new WalkToSchool();
}

#endif

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS