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
Rewrite the code in C++ using Factory Method. The goal is to remove the
main function’s dependency on the concrete classes, such as GoToSchool.
#ifndef GOTOSCHOOL_H
#define GOTOSCHOOL_H
#include <iostream>
using namespace std;
class GoToSchool {
void getUp() { cout << "Get up." << endl; }
void eatBreakfest() { cout << "Eat breakfest." << endl; }
virtual void takeTransit() { cout << "Take school bus." << endl; }
virtual void arrive() = 0;
public:
void go() {
getUp();
eatBreakfest();
takeTransit();
arrive();
}
};
#endif
Rewrite the code in c++ using Factory Method. The goal is to remove the
main function’s dependency on the concrete classes, such as FlyToSchool,
#ifndef FLYTOSCHOOL_H
#define FLYTOSCHOOL_H
#include <iostream>
#include "GoToSchool.hpp"
using namespace std;
class FlyToSchool:public GoToSchool {
void takeTransit() { cout << "We are taking a flight." << endl; }
void arrive() { cout << "After 2 hours, we arrive." << endl; }
};
#endif
Write a program to calculate the area of a rectangle by creating a class named 'Area'
with two variables ‘length’ and ‘breadth’ and two functions. First function named as
'setValues' set the length and breadth of the rectangle and the second function named as
'getArea' returns the area of the rectangle.
Write a C++ program that generates a random number from 0 to 10 and saves it in an integer Correct. The program prompts the user to guess the number between 0 and 10. If the user guesses the number that matches Correct, then the program outputs the message “you guessed the number correctly”. Otherwise, the program checks whether the guessed number is less than Correct and outputs the message” your number is lower than the number. Guess again”. If not, the program will output “your number is higher than the number. Guess again”. The program prompts the user to enter another number until the user enters the correct number.
Write a C++ program that reads a sequence of integer numbers from the input file data.txt. The sequence ends with a sentinel value of zero. The program should output the following into an output file results.txt:
Use the following values in the file data.txt to test your program:
5
4
-8
-7
6
-2
9
Write a C++ program that prompts the user to enter an even integer N which represents how many numbers he/she wants to enter. The program then reads N decimal numbers and finds the minimum number in the first half and the maximum number in the second half.
Complete the declaration and initialization of the array variable with datatype character, char array[ ]=???;. Initialized the first index with A, the second index with T, the third index E, the fourth index N, the fifth index as E, and the sixth index as O.
Your answer's format should be a complete declaration at the same time initialization:
format: datatype array_name[ ]=???;
Answer:
1. Create a menu to execute tasks. There shall be n tasks in total, update as they comes up. You should properly prompt wherever necessary.