Question: main.cpp #include #include boat.h /* * Instructions: * This code will not compile as-is. Begin by trying to get the code to compile. * *
main.cpp
| #include | |
| #include "boat.h" | |
| /* | |
| * Instructions: | |
| * This code will not compile as-is. Begin by trying to get the code to compile. | |
| * | |
| * Review the header files for boat and sailboat. Create an appropriate public inheritance | |
| * relationship between the classes. | |
| * If appropriate, move the attributes from one class to the other. | |
| * Implement the boat and sailboat classes in the corresponding cpp files | |
| * Add getters and setters for both classes, as well as default and parameterized constructors | |
| * You do not need to create a copy constructor | |
| * Add const as is appropriate to methods | |
| * | |
| * Modify the code below to create the boat and sailboat using the parameterized constructors you created. | |
| * | |
| */ | |
| int main() { | |
| Boat boat; // change this | |
| boat.sink(); | |
| SailBoat sailBoat; // change this | |
| sailBoat.sink(); | |
| return 0; | |
| } |
boat.h
| #ifndef MIDTERM_REVIEW_KL_BOAT_H | |
| #define MIDTERM_REVIEW_KL_BOAT_H | |
| #include | |
| class Boat { | |
| std::string name; | |
| int numSails; | |
| void sink(); | |
| }; | |
| #endif //MIDTERM_REVIEW_KL_BOAT_H |
boat.cpp
#include "boat.h"
sailboat.cpp
#include "sailboat.h"
sailboat.h
| #ifndef MIDTERM_REVIEW_KL_SPEEDBOAT_H | |
| #define MIDTERM_REVIEW_KL_SPEEDBOAT_H | |
| class SailBoat { | |
| bool hasMotor; | |
| int length; | |
| }; | |
| #endif //MIDTERM_REVIEW_KL_SPEEDBOAT_H |
makefile
| boats: boat.o sailboat.o main.cpp | |
| g++ -std=c++11 boat.o sailboat.o main.cpp | |
| boat.o: boat.cpp boat.h | |
| g++ -c -std=c++11 boat.cpp | |
| sailboat.o: sailboat.cpp sailboat.h | |
| g++ -c -std=c++11 sailboat.cpp |
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
