in C++ FORMAT PLEASE: Create a file named BST.cpp in which you have a main funct
ID: 3799952 • Letter: I
Question
in C++ FORMAT PLEASE:
Create a file named BST.cpp in which you have a main function which opens a file, reads the contents of the file into a BST and then performs operations on the tree, the result of which you then write to an output file.
The name of the first input file MUST BE books1.txt and it must contain the following:
Pride and Prejudice
Jane Austen
10.95
2345678
Bleak House
Charles Dickens
8.99
3567897
A Room with a View
E.M. Forster
7.50
1177889
Jane Eyre
Charlotte Bronte
7.90
2345674
The Woman in White
Wilkie Collins
10.75
3256789
Lady Audley's Secret
Mary Elizabeth Braddon
5.50
1212134
Gulliver's Travels
Jonathan Swift
6.80
3434343
Middlemarch
George Elliot
12.50
1256743
Vanity Fair
William Thackery
11.99
3456839
THEN create a second input file called books2.txt and copy and paste the following content into it:
Pedro Paramo
Juan Rulfo
8.95
1123456
Como agua para chocolate
Laura Esquivel
6.90
2375689
La casa de los espiritus
Isabel Allende
7.50
2117889
Los diarios de motocicleta
Ernesto Che Guevara
10.99
2241174
Cien anos de soledad
Gabriel Garcia Marquez
9.75
3556789
El alquimista
Paulo Coelho
8.50
3212132
La casa en Mango Street
Sandra Cisneros
6.80
1134231
El beso de la mujer arana
Manuel Puig
7.75
3456743
Cajas de carton
Francisco Jimenez
10.99
2256839
Explanation / Answer
# embrace <iostream>
# embrace <cstdlib>
using namespace std;
/*
* Node Declaration
*/
struct node
*root;
/*
* Class Declaration
*/
class BST
};
/*
* Main Contains Menu
*/
int main()
worker = new node;
cout<<"Enter the amount to be inserted : ";
cin>>temp->info;
bst.insert(root, temp);
case 2:
if (root == NULL)
if (item == root->info)
if (item < root->info)
ptr = root->left;
else
ptr = root->right;
ptrsave = root;
while (ptr != NULL)
ptrsave = ptr;
if (item < ptr->info)
ptr = ptr->left;
else
ptr = ptr->right;
}
*loc = NULL;
*par = ptrsave;
}
/*
* Inserting part into the Tree
*/
void BST::insert(node *tree, node *newnode)
else
else
else
}
/*
* Case B
*/
void BST::case_b(node *par, node *loc)
else
}
/*
* Case C
*/
void BST::case_c(node *par, node *loc)
suc = ptr;
parsuc = ptrsave;
if (suc->left == NULL && suc->right == NULL)
case_a(parsuc, suc);
else
case_b(parsuc, suc);
if (par == NULL)
else
suc->left = loc->left;
suc->right = loc->right;
}
/*
* Pre Order Traversal
*/
void BST::preorder(node *ptr)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.