Link to home
Start Free TrialLog in
Avatar of coririzzo
coririzzo

asked on

Need help with exam review question- class with pointers

Here is the problem:  (I think the output is 20, 30, 40  and 20, 30, 40, but I am not sure about pointb.)
Given the following class:
    class pointtype {
      private:
            int *x, int *y, int *z;
      public:
            pointtype(int, int, int);
            ~pointtype();
            void setpoint(int, int, int);
            void getpoints(int *, int *, int *)
            void print() const; // a function which prints the values of x and y      
};

And the following declaration and c++ statements:

pointtype pointa(12, 16, 20), pointb(0,0, 0);
pointb = pointa;
pointa.setpoint(20, 30, 40 );
pointa.print();
pointb.print();

What is the output?      
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

It is hard to figure out without full class implementation code.
But I don't see the reason for private member to be:
          int *x, int *y, int *z;
instead of:
          int x, int y, int z;
There is a syntax error in this line:
          int *x, int *y, int *z;
 must be:
          int *x,  *y,  *z;
 
SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Now I have to go to sleep, good luck,
Jaime.
Avatar of coririzzo
coririzzo

ASKER

Thanks Jaime, but I didn't write this code.  It was given to us by the instructor as a review for an exam, and we are asked to say what the output is the way it is written.  Your comment about the values won't be copied automatically to point b without a pointer lead me to believe the answer is 20, 30, 40 for pointa and 12, 16, 20 for pointb.
Avatar of Axter
This is clearly a homework question.

It's against EE policy for Experts to do homework questions.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> From Jaime:
> pointb is copied from pointa, but when you assign new values to pointa, values won't be automatically copied to pointb
> unless you use a pointer.

coririzzo:
I think I have explained earlier (not as detailed as Alex) that both object won't contain the same. So I think I deserve some credits.
Jaime.
>>>> that both object won't contain the same

Jaime, the objects contain the same. That is different to the explanation you gave as you posted a class definition with int x, y, z and the question was about int pointers *x, *y, *z. So, your answer was correct, but wasn't an answer to the question.

Regards, Alex
Based on Comment http:#12214435 this question clearly falls under the guidelines as homework.
It will be deleted in 24 hours.

coririzzo and participating Experts:
  You are advised to read this link regarding homework if you haven't already:
  https://www.experts-exchange.com/Community_Support/New_Topics/help.jsp#hi56

The accepted answer has been vacated and the question PAQ'd pending delete.

ee_ai_construct
Community Support Admin
Sorry, I think we was not DOING  a homework, there are many EXPLANATIONS about the use of pointers and copy constructors. So let me disagree with you (and Axter). But you are the moderator.....

I WOULDN'T CONSIDER THIS AN **ANSWER**
>But I don't see the reason for private member to be:
>          int *x, int *y, int *z;
>instead of:
>          int x, int y, int z;

THIS IS NOT DIRECTLY RELATED TO SPECIFIC QUESTION. JUST ADVICING:
>There is a syntax error in this line:
>          int *x, int *y, int *z;
>must be:
>          int *x,  *y,  *z;


THIS IS AN EXPLANATION.
>I think I understand what you are trying to do.
>pointb is copied from pointa, but when you assign new values to pointa, values won't be automatically copied to pointb >unless you use a pointer.

THIS IS A DETAILED EXPLANATION (AS ALEX LIKE);
>That is wrong.
>Look at that:
>pointa:  { 0x00001230, 0x00001240, 0x00001250 };
>pointa.x = 0x00001230:  { 12 }
>pointa.y = 0x00001240:  { 16 }
>pointa.z = 0x00001250:  { 20 }
etcetera.....
>>>> If you have homework, and don't understand part of it, be honest about it. The >>>> Experts will be more than happy to teach you.

There is nothing in the question (and the answers) that goes beyond that part of the EE guide lines regarding homework.

Regards, Alex
I know Axter is a teacher and teacher's don't like if their questions to pupils were answered by experts. But that is his problem. That is/was an open forum and not any single person should be allowed to make their own narrow-minded opinion a general rule.

Regards, Alex
I am a teacher too (sometimes), and I know that it is hard for everybody (specially for a 16-18 years old kid) to understand them.
 
I refer to the 'pointers' Chapter.
It's hard to unterstand for me what happens here. As fast as they have been to delete the question as slow now are their reactions...

Axter, ee_ai_construct: I want an answer. And i'm no school boy.

Regards, Alex
>>>> Thanks Jaime, but I didn't write this code.  It was given to us by
>>>> the instructor as a review for an exam, and we are asked to say
>>>> what the output is the way it is written.  Your comment about
>>>> the values won't be copied automatically to point b without a
>>>> pointer lead me to believe the answer is 20, 30, 40 for pointa
>>>> and 12, 16, 20 for pointb.

That was the author's comment before Axter's first and only comment. You can easily see, that the questioner wasn't awaiting a complete answer but tried to unterstand what happens and gave an own suggestion. Jaime's answer was misleading the questioner to a wrong conclusion.  So, the answer *must* be corrected.

Regards, Alex


The answer to this question is 42.
>>Axter, ee_ai_construct: I want an answer. And i'm no school boy.

Exactly what is the question???
Please post in Dan's link:
http:Q_21155598.html
Thanks to all who helped me, and I have split the points.  I will say that I am NOT 16 - 18 (ha ha), but am a 54 year old who is taking classes while working full time( testing server management software).  I have a master's degree, but not in the right field to advance any further in my job.  I am also taking this class online, so I don't have a live instructor to ask for advice.  I also did not think that getting input for a question from an exam review was the same as asking for code for a homework assignment.  
Cori
I am in the same position as coririzzo: You can look at my bio under gonzal13. I too am trying to learn VB6 just for the pleasure of it. I took the last semester that it was offered since they were changing over to VB.Net. The teacher changed the two day schedule to one day schedule.

Fortunately I bought the books recomended on the visual basic site and use the MSDN reference manual. Still they are all generic. One learns by seeing examples of code also. Thus my need to post on th VB site. Several have been very patient with me. Others are suspicious.

On to of thing to knowt isthat I am a 60 year old retired roject engineer that always has had to jump into the unknown. Since I have free time, I decided to take a very large program that I wrote in Basic in 1982 and rewrite it in vsuac basic. I reason that by the time I finish I should have a fair to good command of VB6.

Thus I need to work with understanding and patient experts in theVB6 area.

gonzal13(Joe)
gonzal13, this is a C++ area not VB. However, I can recommend learning C++ for the pleasure of it.

I find it reassuring to know that there are some old timers out there learning this stuff. I've been a slow learner all my life and am probably getting slower in middle age. I'd like to think that I can still be receptive to new ideas in retirement. It is inspirational to hear about 60+s jumping in.