(1) what’s wrong with line 3? (2) what’s wrong with the constructors? (3) what’s
ID: 3905556 • Letter: #
Question
(1) what’s wrong with line 3?(2) what’s wrong with the constructors?
(3) what’s wrong with the function setC()?
(4) what’s wrong with the destructor?
(5) what’s wrong with line 19?
(6) what’s wrong with line 20? 1 class A 2 private: 3 int a = 1, b, c, d, *ptr; 4 public: A) int ptrnew int [10) ) A(int b0) this->b(b) I) void setA (int x) const axi void setB(int x) this.b x; ) void setC() { this->c = ptr [0]; } void setD (int x) d xi ) A (int *x) ( 9 10 delete ptr; 12 13 1 4 15 16 void main() 17 const A al; 18 A a2 (1, 2, 3) 19 al.setD (6) 20 cout
Explanation / Answer
PLEASE GIVE THUMBS UP, THANKS
1. a=1 is wrong we dont initialize variable in definition, that should be done in any method.
2.Constructor should set all member variables, in first constructor int prt is a variable not a pointer variable so new in[10] can't be stored in ptr; in second constructor :this->b shold inside {} and ":" should removed, and it should this->b=b not this->b(b);
3. c is not pointer variable only pointer variable are access using "->" otherwise it it accessed by "." operator
4.destructor never takes arguments and ptr=x will not be in destructor
5.Since a1 is const so we can't change any data of a1.
6. a1.ptr[1] can't be acess because ptr is private.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.