Question

heree is the code #ifndef ASSIGNMENT_VERSION1_DATA_STRUCT_H #define ASSIGNMENT_VERSION1_DATA_STRUCT_H #endif //ASSIGNMENT_VERSION1_DATA_STRUCT_H #include #include #include #include // for...

heree is the code

#ifndef ASSIGNMENT_VERSION1_DATA_STRUCT_H
#define ASSIGNMENT_VERSION1_DATA_STRUCT_H

#endif //ASSIGNMENT_VERSION1_DATA_STRUCT_H

#include
#include
#include
#include // for setw and setfill stream manipulators
#include // for invalid_argument exception class
#include // for ostringstream class
#include
#include
#include

using namespace std;

class data_struct {

private:
// data members

int id, size_file, parent_id;
char folder;
string file_folder_name;


public:

data_struct *left;
data_struct *right;

// constructor with 4 parameters
data_struct(int i, string nm, int l, char m, int n) {

id = i;
file_folder_name = nm;
size_file = l;
folder = m;
parent_id = n;

left = NULL;
right = NULL; //initialize a pointer variable when that pointer variable isn’t assigned any valid memory address yet.

}

// function which will be used to display
void display() {
cout << "[" << id << "][" << file_folder_name << "][" << size_file << "][" << folder << "][" << parent_id << "]"
<< endl;
// inorder(head);
}

vector file;// vector of string which stores the file
data_struct *head; // pointer of type data_struct which
ofstream fout;// decraling an output file stream

data_struct() {

head = NULL;
int id, size_file, parent_id;
string file_folder_name;
char folder;

ifstream fin("file.txt");// reading from file
if (fin) {
while (!fin.eof()) {
string line;
fin >> line;
line = line.substr(1, line.length() - 2);
int y = line.find("][");
stringstream ss(line.substr(0, y));
ss >> id;
line.erase(0, y + 2);
y = line.find("][");
file_folder_name = line.substr(0, y);
line.erase(0, y + 2);
y = line.find("][");
stringstream ss2(line.substr(0, y));
ss2 >> size_file;
line.erase(0, y + 2);
y = line.find("][");
stringstream ss3(line.substr(0, y));
ss3 >> parent_id;
file.push_back(new data_struct(id, file_folder_name, size_file, folder, parent_id));

}

// now constructing BST
loadTree();
}
else {
cout << "no prior saved file!" << endl;
}
}

// constructing tree

void loadTree() {

for (int i = 0; i < file.size(); i++)
if (file[i]->id == 0) {
head = file[i];
break;
}
for(int i=0;i if(file[i]->id!=0)
insert(head, file[i]);
}
// }

}

// for updation in file
void finorder(data_struct *node){
if (node){
finorder(node->left);
fout<<"["right);
}
}

//inorder traversal of tree
void inorder(data_struct *node){
if(node){
inorder(node->left);
node->display();
inorder(node->right);
}
}

//void display(){
// inorder(head);
//}

//updations
void updateFile(){
fout.open("file.txt");
finorder(head);
fout.close();
}
data_struct* insert(data_struct * node, data_struct *key){
if(!node)
return key;
if(key->idid)
node->left = insert(node->left,key);
if(key->id>node->id)
node->right = insert(node->right,key);
return node;
}

void search(data_struct * node, int id){
if (!node){
cout << "element not found!!\n";
return;
}
if (node->id == id){
node ->display();
return;
}
if (idid)
search (node ->left,id);
if(id>node->id)
search(node->right,id);
}
data_struct *minNode(data_struct* t){
while(t->left){
t= t->left;
}
return t;
}
data_struct* Delete(int id, data_struct *node){
if (!node)
return node;
if(id < node->id)
node->left = Delete(id, node->left);
else if (id>node->id)
node-> right = Delete(id,node->right);
else{
if (!node->left){
data_struct *temp =node->right;
free(node);
return temp;
}
data_struct * temp =minNode(node->right);
node->id = temp-> id;
node ->file_folder_name = temp ->file_folder_name;
node->size_file = temp->size_file;
node->folder = temp->folder;
node->parent_id = temp->parent_id;
node->right = Delete(temp->id,node->right);
}
return node;
}
void menu(){

cout<<"| M E N U |"< cout<<"| 1 | Add |"< cout<<"| 2 | Delete |"< cout<<"| 3 | List |"< cout<<"| 4 | Search |"< cout<<"| 5 | Exit |"< cout<<"|_____|______|\n"<

while(true){

int choice;
cout<<"enter your choice: ";
cin>> choice;
if(choice ==1){
int id, size_file,parent_id;
string file_folder_name,line;
char folder;
cin>>line;
line=line.substr(1,line.length()-2);
int y = line.find("][");
stringstream ss(line.substr(0,y));
ss>>id;
line.erase(0,y+2);
y= line.find("][");
stringstream ss2(line.substr(0,y));
ss2>>size_file;
line.erase(0,y+2);
y=line.find("][");
folder=line[0];
line.erase(0,y+2);
y=line.find("][");
stringstream ss3(line.substr(0,y));
ss3>>parent_id;
head=insert(head,new data_struct(id,file_folder_name,size_file,folder,parent_id));
updateFile();
}
if (choice ==3){
display();
}
if (choice ==4){
int id;
cout<<"enter the id:";
cin>>id;
search(head,id);
}
if(choice ==5) {
break;
}
cout< }
}
};

#include
#include
#include
#include "data_struct.h"
#include // for setw and setfill stream manipulators
#include // for invalid_argument exception class
#include // for ostringdtream class
#include

using namespace std;


int main() {

data_struct().menu();

return 0;
}

the scenario of this program is to first read data from a text file, the data in the text file is about files and foldes stored in a storage device.here is a sample of the data from a text file that must be included:

[0][Root][0][T][0]
[1][file.txt][45643][F][0]
[2][folder1][0][T][0]
[3][file2.txt][7346][F][2]

this information should be represented in an adequate data structure. the data structure should then be loaded into a binary search tree. the program must provide listing searching deleting and adding files or folders through the binary search tree. finally the information must be exported in a text file.
the programm must be in c++ object oriented as you can see i have implented the binary search tree but it is not functioning well so i will be very thankful if you could help me out.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

You must include these library in first file

#include<iostream>

#include<iomanip>

#include<fstream>

#include<vector>

#include<stdexcept>

#include<string>

#include<algorithm>

#include<sstream>'

In second file include this libraries

#include<iostream>

#include<iomanip>

#include<stdexcept>

#include<string>

#include<fstream>

Add a comment
Know the answer?
Add Answer to:
heree is the code #ifndef ASSIGNMENT_VERSION1_DATA_STRUCT_H #define ASSIGNMENT_VERSION1_DATA_STRUCT_H #endif //ASSIGNMENT_VERSION1_DATA_STRUCT_H #include #include #include #include // for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have a C++ code that lets me enter, display and delete a student record. I...

    I have a C++ code that lets me enter, display and delete a student record. I need to implement a function that prints the average grade score of the students I input. Below is my code and a picture of how my code looks right now. #include<iostream> #include<stdlib.h> using namespace std; //Node Declaration struct node {    string name;    string id;    int score;    node *next;   }; //List class class list {        private:        //head...

  • Hi I've a problem with this code. When I add more than 1 song to the...

    Hi I've a problem with this code. When I add more than 1 song to the list, it doesn't show the first one, only shows the latest one, when I called the function displaysong, let's say when you add 2 songs ID 1 then ID 2, it shows only ID 1. Can you fix it.  Everything else is fine.. #include <iostream> #include<string> using namespace std; //class Song class Song{ private: int songID; string title; string artist; string album; int year; public:...

  • I'm having trouble getting this program to compile and run. It is in C++ Language and...

    I'm having trouble getting this program to compile and run. It is in C++ Language and being run with CodeBlocks. Problem Statement: create and manage a linked list. Program will loop displaying a menu of user operations concerning the management of a linked list. Included will be:       H create link at head       R remove link at head       T create link at tail       K remove link at tail       I remove link at ID          S search...

  • 1) Create a struct called CourseInfo to store info about a course (Include variables for courseNum,...

    1) Create a struct called CourseInfo to store info about a course (Include variables for courseNum, courseName, & grade) 2) Change the type for the 'data' member variable in the node struct to CourseInfo (see #1) and rename it to 'courseData' 3) Modify the createNode function to receive a CourseInfo struct as a parameter. It should also display the address of the new node that is created. Display the address in both hex and decimal form. 4) Modify the display...

  • C++ comment code Comment the following code #include <iostream> using namespace std; class Node { public:...

    C++ comment code Comment the following code #include <iostream> using namespace std; class Node { public: Node(int val); int value; Node* next; }; Node::Node(int val){ value = val; } class List { public: List(); // Uncomment the line below once you're ready List(List &other); void push_front(int value); bool pop_front(int &value); void push_back(int value); bool pop_back(int &value); int at(int index); void insert_at(int index, int value); void remove_at(int index); int size(); private: // other members you may have used Node* head; Node*...

  • Q. write the algorithm for each function in this code: void insert(int x, node*&p) { //cheak...

    Q. write the algorithm for each function in this code: void insert(int x, node*&p) { //cheak if the pointer is pointing to null. if (p==NULL) {     p = new node;     p->key=x;     p->left=NULL;     p->right=NULL; } else {     //Cheak if the element to be inserted is smaller than the root.     if (x < p->key)     {       //call the function itself with new parameters.       insert(x,p->left);     }     //cheak if the alement to be inserted...

  • in c++ please program for this code #include <iostream> #include <fstream> #include <string> #include <cstring> //...

    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;...

  • C++ Assignment Project 1 - NodeList Building upon the the ListNode/List code I would like you...

    C++ Assignment Project 1 - NodeList Building upon the the ListNode/List code I would like you to extend the interface of a list to have these member functions as well. struct ListNode { int element; ListNode *next; } Write a function to concatenate two linked lists. Given lists l1 = (2, 3, 1)and l2 = (4, 5), after return from l1.concatenate(l2)the list l1should be changed to be l1 = (2, 3, 1, 4, 5). Your function should not change l2and...

  • C++ Assignment Project 1 - NodeList Building upon the the ListNode/List code I would like you to extend the interface of...

    C++ Assignment Project 1 - NodeList Building upon the the ListNode/List code I would like you to extend the interface of a list to have these member functions as well. struct ListNode { int element; ListNode *next; } Write a function to concatenate two linked lists. Given lists l1 = (2, 3, 1)and l2 = (4, 5), after return from l1.concatenate(l2)the list l1should be changed to be l1 = (2, 3, 1, 4, 5). Your function should not change l2and...

  • Lab 6 Help

    I need help with this lab assignment. I use C++, thank you. Derive a MinHeap class from the BST class of your Lab 4 code.Define/Override only the Search/Insert/Delete methods in the new class.Write a new main for this lab which:Will only be a test program for the MinHeap.Declares and creates a MinHeap object as necessary.Declares and creates the Dollar objects as necessary.Inserts the 20 Dollar objects specified in Lab 4 in the same order.Performs all 4 traversals after the inserting...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT