Please help me with FLOWCHART and UML diagram for class, thank you!
#include <iostream>
#include <fstream>
#define MAX 10
using namespace std;
class WordListTree {
public:
// Structure of a node
struct Node {
string key;
// Create an array of up to MAX
children
Node* child[MAX];
};
// Create a tree of strings
Node* newNode(string key) {
Node* temp = new Node;
(*temp).key = key;
for (int i = 0; i < MAX;
i++)
(*temp).child[i]
= NULL;
return temp;
}
// Traverse the tree and search for a matching
string
void traverse(Node* root, string iData)
{
if (root) {
// Check for
match against WordList.txt input array element
if ((*root).key
== iData) {
cout << (*root).key << " ";
return;
}
for (int i = 0;
i < MAX; i++) {
traverse((*root).child[i], iData);
}
}
}
// A function to create a tree with our internal
word list
Node* teamWordList() {
Node* root = newNode("ANT");
(*root).child[0]
= newNode("BEE");
(*root).child[1]
= newNode("CAT");
(*root).child[2]
= newNode("DOG");
(*root).child[3]
= newNode("EMU");
(*root).child[0]->child[0] = newNode("FOX");
(*root).child[0]->child[1] = newNode("GOAT");
(*root).child[1]->child[0] = newNode("HORSE");
(*root).child[2]->child[0] = newNode("IMPALA");
(*root).child[2]->child[0]->child[0] =
newNode("JACKAL");
return
root;
}
};
int main() {
//Create an object of WordListTree class
WordListTree treeObject;
// Create the example tree int he class to use as
comparison
WordListTree::Node* root =
treeObject.teamWordList();
// Create an object of the fstream class
ifstream iFile;
iFile.open("WordList.txt");
// Validate file
if (iFile.fail()) {
cerr << "Error Opening File"
<< endl;
exit(1);
}
// Initialize array
string wordList[10];
// Vars
string iData;
// Read file list until EOF, extract words, enter
words into array elements
cout << "The following word(s)
match:\n\n";
for (int i = 0; i < 10; i++) {
iFile >> iData;
wordList[i] = iData;
// Send element to traversal
function to test for word match
treeObject.traverse(root,
iData);
}
}
Please help me with FLOWCHART and UML diagram for class, thank you! #include <iostream> #include <fstream>...
in c++ please program for this code #include <iostream> #include <fstream> #include <string> #include <cstring> // for string tokenizer and c-style string processing #include <algorithm> // max function #include <stdlib.h> #include <time.h> using namespace std; // Extend the code here as needed class BTNode{ private: int nodeid; int data; int levelNum; BTNode* leftChildPtr; BTNode* rightChildPtr; public: BTNode(){} void setNodeId(int id){ nodeid = id; } int getNodeId(){ return nodeid; } void setData(int d){ data = d; } int getData(){ return data;...
can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define SIZE 100 using namespace std; //declare struct struct word_block { std::string word; int count; }; int getIndex(word_block arr[], int n, string s); int main(int argc, char **argv) { string filename="input.txt"; //declare array of struct word_block word_block arr[SIZE]; int count = 0; if (argc < 2) { cout << "Usage: " << argv[0] << "...
1. Write a function in Tree class which returns true if and only if the tree satisfies the binary search tree property. The function’s header line is public boolean isValidBST() And in the attached code, you just need to finish the function after the comment: “//Instructor hint: please write your code here:” Make sure you execute your code, and the result in the main function after calling your function should be same as the prompt message I write. Clearly you...
Hi there, I am working on a binary search tree code in c++. The program must store and update students' academic records, each node includes the student name, credits attempted, credits earned and GPA. I have made some progress with the code and written most of the functions in the .cpp file (already did the .h file) but i am struggling with what to put in the main and how to put an update part in the insert function. I...
Please add a detailed comment for this program. #include<iostream> #include<string> #include<fstream> #include<sstream> #include<cctype> using namespace std; int is_palindrome(string word){ int len = word.size(); for(int i=0; i<len/2; i++){ if(toupper(word[i])!=toupper(word[len-i-1])) return 0; } return 1; } int have_vowels3(string word){ int cnt = 0; for(int i=0; i<word.size(); i++){ if(tolower(word[i])=='a' || tolower(word[i])=='e' || tolower(word[i])=='i' || tolower(word[i]) =='o' || tolower(word[i]) == 'u') cnt++; } if(cnt>=3) return 1; else return 0; } int have_consecutives(string word){ for(int i=0; i<word.size()-1; i++){ if(tolower(word[i])=='o' && tolower(word[i+1]=='o')) return 1; } return...
I am stuck on a data structure problem, I am just going off of Geeks for Geeks for help but I need to print 100 random numbers in the range of [1-200]. I can currently only print 5 numbers. Here is my code: #include <stdio.h> #include <stdlib.h> #include <limits.h> using namespace std; //binary tree has data & left and right child struct node{ int data; struct node *left; struct node *right; }; //create a new node struct node* newNode (int...
So my test.h file has: #include <iostream> #include <fstream> using namespace std; class test { private: int data[]; public: test(string filename); }; My test.cpp file has: #include "sort.h" test::test(string filename) { ifstream inFile; inFile.open(filename); int iter = 0; while(!inFile.eof()) { cin >> data[iter]; iter++; } int numberOfNumbers = iter; for (iter = 0; iter < numberOfNumbers; iter++) cout << data[iter] << " "; ...
fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str; while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title); getline(inFile, books[size].Author); getline(inFile, books[size].publisher); getline(inFile,...
C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...
C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...