Hi, Could someone please answer this question for me? For the first question jus
ID: 3721305 • Letter: H
Question
Hi, Could someone please answer this question for me? For the first question just denote in bullet points, That would be helpful. Thanks!
Examine the following C++ code and identify and describe the syntactical and structural errors. There are approximately 10, depending on how you identify them The same error repeated is considered to be a single error | #include 2 using namespace std; 4 public class Point2D { 5 private: 6 double x, y; 7 public: 9 10 Point2DO; Point2D (double, double); virtual print() 12 13 Point2D: Point2D() x-0, y-0 t) 14 Point2D: Point2D (double x1, double y1) : x1(x), yl(y) t 15 16 print() f coutExplanation / Answer
line 4. no need to use access specifier while declaring a class
line 10. function print should have a return type i.e virtual void print();
line 13. incorrect syntax, correct syntax will be : x(0), y (0)
line 14. there's no class variable named x1, y1 , correct syntax: x(x1),y(y1)
line 16. scope resolution operator required
line 19. structural error, use private access specifier
line 21. structural error, use public access specifier
line 26. incorrect syntax
line 27. needed to be merged with line 26 with proper syntax :
line 30. super keyword doesnt exist, use Point2D::print instead.
ans 1b.
// following code is tested
int main()
{
Point2D *ar[10]; //array of 10 pointers to point 2d
Pixel p;
for(double i=0;i<10;i++)
{ ar[i] = &p; //pointers pointing to pixel objects
ar[i]->Pixel(i+1,i+1,3,4,5); //calling pixel function with coordinates
ar[i]->print(); //late binding e.i run time polymorphism
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.