In: Computer Science
For the following C++ code, identify the 10 errors and rewrite the code using the space provided below. Do not write a new program just add, remove or change the characters/words that make the code incorrect. #include "iostream> using namespace std: class Line { public: Line( double L ) [ setLength(L); } void setLength( double L ) { length = L } double getLength( void ) { return length; } private= double length; }; int main() { double len; cout >> "How long is this line? " cin >> len; Line = line(len); Line *LPtr = line; cout << "Length of line : " << LPtr.getLength() << endl; }
/* CORRECTED 10 ERRORS AND SEE COMMENT TO KNOW ERRORS */
#include <iostream> // 1-> (") incorrect use
<
using namespace std; // 2- > use ;
class Line {
public:
Line( double L ) { // 3-> ([)
incorrect use {
setLength(L);
}
void setLength( double L ) {
length = L; //
4-> missed ;
}
double getLength( void ) {
return
length;
}
private: // 5-> use :
double length;
};
int main() {
double len;
// 6-> use (<<) insted of (>>) 7->
missing ;
cout << "How long is this line? ";
cin >> len;
Line line(len); // 8-> (=) no need
Line *LPtr = &line; // 9-> use &
cout << "Length of line : " <<
LPtr->getLength() << endl; // use -> instead of .
}
/* OUTPUT */

/* PLEASE UPVOTE */