Modify the NodeT to include a string field called def (which will hold the word
ID: 3716013 • Letter: M
Question
Modify the NodeT to include a string field called def (which will hold the word definitions).
In the currently existing NodeT constructor, set the def field to be a blank string (“”);
Create a second constructor that takes as input parameters 2 strings. It should set data to be
the first input string, and def to be the second input strings. All the other fields should be set as they were in the first constructor.
Modify the printNode method in the NodeT class to print out the data, then the height, and then the def
#include "NodeT.hpp"
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
NodeT::NodeT(string x) {
data = x;
left = NULL;
right = NULL;
parent = NULL;
height = 1;
}
NodeT::~NodeT() {
if ((left != NULL) || (right != NULL)) {
cout << "deleting may leave dangling SNodes" << endl;
}
}
void NodeT::printNode() {
cout << "|"<<data << ", "<< height <<"|" << endl;
}
Explanation / Answer
Answer:
//header file
//Since your NodeT.hpp is not provided
//include this one line in NodeT definition
string def;
//include this line below NodeT(string);
NodeT(string,string);
//////////////////////////////////////////////////////////
//NodeT.cpp file:
#include "NodeT.hpp"
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
NodeT::NodeT(string x) {
data = x;
//existing NodeT constructor, set the def field to be a blank string (“”);
def="";
left = NULL;
right = NULL;
parent = NULL;
height = 1;
}
//Create a second constructor that takes as input parameters 2 strings.
NodeT::NodeT(string x, string y) {
//set data to be the first input string, and def to be the second input strings
data = x;
def=y;
//All the other fields should be set as they were in the first constructor.
left = NULL;
right = NULL;
parent = NULL;
height = 1;
}
NodeT::~NodeT() {
if ((left != NULL) || (right != NULL)) {
cout << "deleting may leave dangling SNodes" << endl;
}
}
//Modify the printNode method in the NodeT class to print out the data, then the height, and then the def
void NodeT::printNode() {
cout << "|"<<data << ", "<< height <<", "<< def << "|" << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.