If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Need help in This Code plzz

>Write a program in which you create a Hen class. Inside this class, nest a Nest class. Inside Nest, place an Egg class. Each class should have a display() member function. For each class, create a constructor and a destructor that prints an appropriate message when it is called. In main(), create an instance of each class using new and call the display() function for each one. After calling display(), free the storage using delete.
And i came up with this code can anyone help me if im missing something its realy comfusing question. and also the last line about Delete function im confusing about as well plzz help.

Re: Need help in This Code plzz

All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

Re: Need help in This Code plzz

You created a constructor for the hen class, but it does not initialise its members. You have not created a constructor/destructor for nest or egg. You also have no way of setting the class members. The assignment asks for instances of each class to be created using new which you don't do so have no storage to release using delete. To show some of what I mean, the below is some suggested changes to the hen class

All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

Re: Need help in This Code plzz

Originally Posted by s_zar

Write a program in which you create a Hen class. Inside this class, nest a Nest class. Inside Nest, place an Egg class. Each class should have a display() member function. For each class, create a constructor and a destructor that prints an appropriate message when it is called. In main(), create an instance of each class using new and call the display() function for each one. After calling display(), free the storage using delete.

Assignments like this make me question the sanity of the teachers giving them...

From a pure reality POV... So there is an egg in a nest... and this nest is in a hen. Wait, what, the hen ate the nest (along with the egg in it) ?

What is the point of this ?
Who designs code like this ? Why are these unrelated classes defined inside eachother ? I could understand if you have the 3 separate classes and a relation between them, but the definition of this assignment is a joke.

Re: Need help in This Code plzz

Assignments like this make me question the sanity of the teachers giving them...

From a pure reality POV... So there is an egg in a nest... and this nest is in a hen. Wait, what, the hen ate the nest (along with the egg in it) ?

What is the point of this ?
Who designs code like this ? Why are these unrelated classes defined inside eachother ? I could understand if you have the 3 separate classes and a relation between them, but the definition of this assignment is a joke.

I was thinking the same thing. I've been doing this for decades and never written anything so goofy. A student's going to come out of class thinking that's how you design programs. It's nuts.

Re: Need help in This Code plzz

Assignments like this make me question the sanity of the teachers giving them...

From a pure reality POV... So there is an egg in a nest... and this nest is in a hen. Wait, what, the hen ate the nest (along with the egg in it) ?

What is the point of this ?
Who designs code like this ? Why are these unrelated classes defined inside eachother ? I could understand if you have the 3 separate classes and a relation between them, but the definition of this assignment is a joke.

As an ex c++ teacher, I have to agree with you. The 'point?' of these assignments is to test the students understanding of the syntax of the language - it has nothing to do with what would be encountered in 'real' c++ programming. The teacher may have no choice in what/how they teach if they are hired to teach an already written course - in which case I have some sympathy for the teacher. When I was teaching, I was supposed to teach just this sort of 'rubbish'. I tried to move my teaching examples more towards 'real' programming and introduce strings/vectors etc early on but was reprimanded by higher authority for not following 'the course'. I left.

This brings us back to that old chestnut - qui docet doctores - and the design of c++ teaching material. Can't the c++ professional community produce some teaching aides as to how modern c++ should be taught?

All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

Re: Need help in This Code plzz

Originally Posted by 2kaud

This brings us back to that old chestnut - qui docet doctores - and the design of c++ teaching material. Can't the c++ professional community produce some teaching aides as to how modern c++ should be taught?

Re: Need help in This Code plzz

The 'point?' of these assignments is to test the students understanding of the syntax of the language

I know what the point of "an" assignment is. THe point in this particular assignment isn't obvious.

In part becasue the formulation of the assignment is "silly" rather than something you'd actually be asked to write from a half decent analyst.
And in part because the formulation makes no sense "in the real world".

it has nothing to do with what would be encountered in 'real' c++ programming.

Then what is the point of teaching if it is not to prepare a student for "the real" C++ programming jobs?

Is it a good idea to fill the heads of our youth with silliness that upon embarking on a real job, the first few weeks (months) is spent doing nothing but trying to weed out hard ingrained bad programming practices, design principles and ideas ?

The teacher may have no choice in what/how they teach if they are hired to teach an already written course - in which case I have some sympathy for the teacher. When I was teaching, I was supposed to teach just this sort of 'rubbish'. I tried to move my teaching examples more towards 'real' programming and introduce strings/vectors etc early on but was reprimanded by higher authority for not following 'the course'. I left.

I can understand they're following a book, in which case, I redirect my sanity check towards the author of said book, and towards the body of educational authority that decided such nonsense book was "a good idea" in the first place.
Even then, I still blame the teacher in part for following the book without proper personal input.

Re: Need help in This Code plzz

Agreed When I was teaching and I tried to give 'personal input' of 20 years of programming it was 'frowned upon' - so I left as I couldn't agree with what was being demanded of me. I was supposed to follow a course written by a so-called 'expert' programmer who in practice wasn't. He was a 'language lawyer' who knew every last little detail of the syntax of the language as it then was but when challenged hadn't a clue how to write a decent program for the 'real world'. He got into teaching because it was the only job he could get and tried to fool everybody into thinking he was an 'expert' because of his syntax knowledge. Its guys like him that give the teaching profession a bad reputation. I wouldn't have hired him as a junior - never mind an expert - programmer. IMO we need some kind of accreditation for those that teach programming.

All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!