Hi! Please help me debug the following code in C++. Below, you may find the prompt, the code and the identified error.
Posted: Sun May 15, 2022 12:32 pm
Hi! Please help me debug the following code in C++. Below, you may find the prompt, the code and the identified error. Please Identify what is incorrect, correct the code, and provide comments to explain. Thanks!
\/ athlete.h 1 2 3 4 5 6 7 8 9 16 11 12 13 14 15 16 17 #include <iostream> using namespace std; // lots us use c++ throughout entire program class Athletes // creates a class for athletes with their name and height [ private: // access specifier - cannot be accessed/modified from outside the class string name; // private attribute - defines name as a string double height: // private attribute - defines heritht as a integer publici // access specifier can be accessed/modified from outside the class Athletes(string, double ); // public attribute - function void setName(string); // public attribute - set function which returns nothing void setHeight (double); // public attribute - set function which returns nothing string getName(); // public attribute - get function which returns a string double getHeight(); / public attribute - set function which returns a integer 3:
// athlete.cpp #include'athlete.h" // lets us work with Athlete.h Athletes: : Athletes (string n, double h) // defines functions { setName(n); // assign setter value setHeight(h); // assign setter value name = n; // defines names string set function height = h; // defines height integer set function } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 void Athletes::setName(string n) // voids setName function { name = n; 3 void Athletes::setHeight (double h) // voids setHeight function { height = h; } string Athletes::getName() // defines getName function { return name; returns the value of name as a string 1 e double Athletes::getHeight() // defines the getHeight function { return height; returns the value of height as a double 3
7/ client.cpp #include <iostream> //lets us work with cout #include athlete.cpp" // lets us work with using namespace std; // lets us use c++ throughough entire program 1 2. 3 4 5 6 7 8 9 10 11 12 13 14 int main() // main function Athletes ooc("Usain Bolt",77); // creates Athletes object of class cout << "Name: " << ooc.getName() << endl; // prints name with object of class cout << "Height: " << ooc.getHeight() << inches << endl; prints height with object of class return e; // lots computer know everything ran okay w
\/ athlete.h 1 2 3 4 5 6 7 8 9 16 11 12 13 14 15 16 17 #include <iostream> using namespace std; // lots us use c++ throughout entire program class Athletes // creates a class for athletes with their name and height [ private: // access specifier - cannot be accessed/modified from outside the class string name; // private attribute - defines name as a string double height: // private attribute - defines heritht as a integer publici // access specifier can be accessed/modified from outside the class Athletes(string, double ); // public attribute - function void setName(string); // public attribute - set function which returns nothing void setHeight (double); // public attribute - set function which returns nothing string getName(); // public attribute - get function which returns a string double getHeight(); / public attribute - set function which returns a integer 3:
// athlete.cpp #include'athlete.h" // lets us work with Athlete.h Athletes: : Athletes (string n, double h) // defines functions { setName(n); // assign setter value setHeight(h); // assign setter value name = n; // defines names string set function height = h; // defines height integer set function } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 void Athletes::setName(string n) // voids setName function { name = n; 3 void Athletes::setHeight (double h) // voids setHeight function { height = h; } string Athletes::getName() // defines getName function { return name; returns the value of name as a string 1 e double Athletes::getHeight() // defines the getHeight function { return height; returns the value of height as a double 3
7/ client.cpp #include <iostream> //lets us work with cout #include athlete.cpp" // lets us work with using namespace std; // lets us use c++ throughough entire program 1 2. 3 4 5 6 7 8 9 10 11 12 13 14 int main() // main function Athletes ooc("Usain Bolt",77); // creates Athletes object of class cout << "Name: " << ooc.getName() << endl; // prints name with object of class cout << "Height: " << ooc.getHeight() << inches << endl; prints height with object of class return e; // lots computer know everything ran okay w