Question: #include #include using namespace std; class Gelatin { public: Gelatin(double gelantinWeight); Gelatin(const Gelatin ©Gelatin); double weight(); const char *shape(); void morph(const char *morphShape); void morph();
#include
#include
using namespace std;
class Gelatin {
public:
Gelatin(double gelantinWeight);
Gelatin(const Gelatin ©Gelatin);
double weight();
const char *shape();
void morph(const char *morphShape);
void morph();
Gelatin split();
private:
double _gelatinWeight;
const char *_gelatinShape;
};
Gelatin::Gelatin(double gelatinWeight) {
_gelatinWeight = gelatinWeight;
_gelatinShape = "sphere";
}
double Gelatin::weight() {
return _gelatinWeight;
}
const char *Gelatin::shape() {
return _gelatinShape;
}
void Gelatin::morph(const char *morphShape) {
std::string str = morphShape;
if (str == "flat") {
_gelatinShape = morphShape;
}
else {
_gelatinShape = "sphere";
}
}
void Gelatin::morph() {
_gelatinShape = "sphere";
}
Gelatin Gelatin::split() {
Gelatin gelatin(270);
Gelatin copyGelatin = gelatin;
return copyGelatin;
}
Gelatin::Gelatin(const Gelatin ©Gelatin) {
_gelatinWeight = copyGelatin._gelatinWeight;
_gelatinShape = copyGelatin._gelatinShape;
}
bool operator!=(const Gelatin &gelatinNew, const Gelatin &gelatin) {
if (gelatinNew != gelatin) {
return true;
}
return false;
}
int main() {
Gelatin gelatin(540);
cout << "Gelatin weight: " << gelatin.weight() << endl;
cout << "Gelatin shape: " << gelatin.shape() << endl;
gelatin.morph("flat");
cout << "Gelatin morph shape (flat): " << gelatin.shape() << endl;
gelatin.morph();
cout << "Gelatin morph shape (sphere): " << gelatin.shape() << endl;
gelatin.morph("crazy");
cout << "Gelatin morph shape (sphere): " << gelatin.shape() << endl;
Gelatin newGelatin = gelatin.split();
cout << "newGelatin split weight: " << newGelatin.weight() << endl;
cout << "newGelatin split shape: " << newGelatin.shape() << endl;
if (newGelatin != gelatin) {
cout << "NE" << endl;
}
return 0;
}
Why is there a Segmentation fault when I compile the program. Thanks for your explanation.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
