Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Otro

COS assignment 2 solution

Puntuación
5.0
(3)
Vendido
17
Páginas
15
Subido en
13-07-2023
Escrito en
2022/2023

COS assignment 2 solution with source code and link to the zipped files. Create a C++ program that will display a binary search tree: inorder traversal, preorder traversal, postorder traversal and height of the tree. The nodes of the binary search tree will be read into the code using a text file. Download from Additional Resources, the files for Assessment 2, Question 1. The file COS2611 AS2 BST S contains a skeleton framework for binary search trees (BST) and two test files. Notice that in main() are the calling procedures to the classes BST and TreeNode. Use the skeleton as a starting point for you. The insertNode function is given to you. This will help you to get started. You may not change the following classes and procedures: • class TreeNode • readFromFileData(string thePath) • main() You must use main() as is. The marker will use the same code and constructs as in main() to call the objects in the classes. What you should provide: the code for the functions (methods): (a) heightOfTree(5) (b) printPreorder(5) (c) printInorder(5) (d) printPostorder Question 2 Company XFibre, is requested by the municipality to install fibre in a new neighbourhood. The company is constrained to bury the fibre cable only along certain paths. Some of the paths might be more expensive. The cost is represented as a weight on the edge. You need to write a C++ program that will determine the minimum spanning tree that will represent the least expensive path for laying the fibre cable. To solve the above problem for Company XFibre, you may use AI (artificial intelligence) to help. As you are aware AI tools, such as ChatGPT1 , are becoming a valuable tool to help programmers in saving valuable time in the development of code for specific problems. Use an AI tool and generate C++ code that will implement Prim’s algorithm using ADT with a time complexity of O(n2 ). After you have downloaded the code from the AI tool, you will need to make some changes. 1. Insert as a comment your student name and number. 2. Add as a comment the question that you have asked the AI tool to generate the code for you. 3. Add as comments in your code, the updates and changes that you are making. This is important as the marker needs to see your input, changes, and updates to the code to make it work for this case study. Adapt the code to allow you to read from a text file the test data. To test your code, download from Additional Resources, Assessment 2, Question 2 the file and copy it to your C-drive: data folder (the same folder as in Question 1). The path in your code should refer to this text file. As with Question 1, the marker will use a different set of data to test your code. The first value in , represents the number of vertices, and the second value is the number of edges. The values thereafter represent combinations of (vertex, edge, and weight)

Mostrar más Leer menos
Institución
Grado

Vista previa del contenido

COS2611 2023 ASSIGNMENT 2
SOLUTION(100% working)
Link to the zipped file is provided at the end of this
document

Crystal Indigo!
Crystal Indigo!
Providing all solutions you need anytime
+27 76 626 8187




Copy and run the code and submit what you are suppose to submit

,Outputs:

,Question 1
// COS2611 Skeleton for Assessment 3
#include <iostream>
#include <fstream>
#include <string>
#include<vector>

//Add your student name and student number
//
//
//



using namespace std;

class TreeNode
{
//keep this class as is
public:

int value; //key or data
TreeNode* left;
TreeNode* right;

//constructors

TreeNode() {
value = 0;
left = NULL;
right = NULL;
} //default constructor

TreeNode(int v) {
value = v;
left = NULL;
right = NULL;
} //parametrized constructor

}; //TreeNode



class BST
{
public:
TreeNode* root;

//member functions

BST() {
root = NULL;

, }

bool isTreeEmpty()
{
if (root == NULL)
return true; //the tree is empty
else
return false; //the tree is not empty
}

void insertNode(TreeNode* new_node) {
if (root == NULL) {
root = new_node;
} //insert the root node
else {
TreeNode* temp = root;
while (temp != NULL) {
if (new_node->value == temp->value) {
cout << "Value Already exist," <<
"Insert another value!" << endl;
return;
}
else if ((new_node->value < temp->value) && (temp->left == NULL)) {
temp->left = new_node; //insert value to the left
break;
}
else if (new_node->value < temp->value) {
temp = temp->left;
}
else if ((new_node->value > temp->value) && (temp->right == NULL)) {
temp->right = new_node; //insert value to the right
break;
}
else {
temp = temp->right;
}
}
}
} //insertNode

Libro relacionado

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
13 de julio de 2023
Número de páginas
15
Escrito en
2022/2023
Tipo
OTRO
Personaje
Desconocido

Temas

$5.42
Accede al documento completo:
Comprado por 17 estudiantes

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Reseñas de compradores verificados

Se muestran los 3 comentarios
2 año hace

Running and working perfectly

2 año hace

2 año hace

5.0

3 reseñas

5
3
4
0
3
0
2
0
1
0
Reseñas confiables sobre Stuvia

Todas las reseñas las realizan usuarios reales de Stuvia después de compras verificadas.

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
CrystalIndigo University of South Africa (Unisa)
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
486
Miembro desde
5 año
Número de seguidores
226
Documentos
73
Última venta
5 meses hace
CrystalIndigo Solutions

providing all solutions to all computer science modules

4.1

51 reseñas

5
27
4
13
3
6
2
1
1
4

Documentos populares

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes