Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++ i have the following classes class stringHolder{ node *head; public: stringHolder(); void add(string str); } class node{ private: node *next; string str; public:

in c++ i have the following classes

class stringHolder{

node *head;

public:

stringHolder();

void add(string str);

}

class node{

private:

node *next;

string str;

public:

node();

}

how would i write a private function in the string holder class that could take in head->next modify it so that if head->next is called again it maintains that modification?

for example, if i added the following private function to be called from the add function in the stringHolder class

void string_Holder::update(node *ptr, string _str){

ptr->str = _str;

}

and then once i'm back in the add function if i access head->next it shows that it's str variable has been modified?

so like

void stringHolder::add(string str){

node *temp = head->next;

if(temp==NULL){

update(head->next, "hello");

}

std::cout<<"head->next->str =" << head->next->str << std::endl;

and have it display hello?

}

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

List the elements in each set. {p|p is an integer less than 3}

Answered: 1 week ago

Question

What is the principle of thermodynamics? Explain with examples

Answered: 1 week ago