Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Write a C++ program that defines a class named Node that contains two public data members. One data member is an integer (it doesn't

C++ image text in transcribed
Write a C++ program that defines a class named Node that contains two public data members. One data member is an integer (it doesn't matter what the integer represents). The other data member is a pointer to a Node, name it next. The Node pointer points to another instance of the same class. When a new Node is created, it's constructor should accept 1 integer argument to assign to the data member. It should initialize the Node pointer to NULL. New nodes do not point to any other nodes initially. Print out the following message from inside the constructor: cout data; Related to this concept is the "this" pointer that can be use. to access the current object instance from inside the class. For this assignment, all objects should be created dynamically using pointers. Additionally, only use the "his" pointer to access the data members from inside the class. This will require you to use the "pointer-to-member access" operator in conjunction with the "this" pointer. From main, use a for loop to create a chain of 10 nodes (initialized with data values 1 - 10). Remember,all nodes should be created dynamically. Use the addNode method to chain them together. After creating the chain, use another loop to walk over the chain and display the values again. You do not need to worry about freeing the memory used by the program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions