Geschrieben von Student*innen, die bestanden haben Sofort verfügbar nach Zahlung Online lesen oder als PDF Falsches Dokument? Kostenlos tauschen 4,6 TrustPilot
logo-home
Andere

COS assignment 2 solution

Bewertung
5,0
(3)
Verkauft
17
seiten
15
Hochgeladen auf
13-07-2023
geschrieben in
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)

Mehr anzeigen Weniger lesen
Hochschule
Kurs

Inhaltsvorschau

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

Verknüpftes buch

Schule, Studium & Fach

Hochschule
Kurs

Dokument Information

Hochgeladen auf
13. juli 2023
Anzahl der Seiten
15
geschrieben in
2022/2023
Typ
ANDERE
Person
Unbekannt

Themen

4,68 €
Vollständigen Zugriff auf das Dokument erhalten:
Von 17 Studierenden gekauft

Falsches Dokument? Kostenlos tauschen Innerhalb von 14 Tagen nach dem Kauf und vor dem Herunterladen kannst du ein anderes Dokument wählen. Du kannst den Betrag einfach neu ausgeben.
Geschrieben von Student*innen, die bestanden haben
Sofort verfügbar nach Zahlung
Online lesen oder als PDF

Bewertungen von verifizierten Käufern

Alle 3 Bewertungen werden angezeigt
2 Jahr vor

Running and working perfectly

2 Jahr vor

2 Jahr vor

5,0

3 rezensionen

5
3
4
0
3
0
2
0
1
0
Zuverlässige Bewertungen auf Stuvia

Alle Bewertungen werden von echten Stuvia-Benutzern nach verifizierten Käufen abgegeben.

Lerne den Verkäufer kennen

Seller avatar
Bewertungen des Ansehens basieren auf der Anzahl der Dokumente, die ein Verkäufer gegen eine Gebühr verkauft hat, und den Bewertungen, die er für diese Dokumente erhalten hat. Es gibt drei Stufen: Bronze, Silber und Gold. Je besser das Ansehen eines Verkäufers ist, desto mehr kannst du dich auf die Qualität der Arbeiten verlassen.
CrystalIndigo University of South Africa (Unisa)
Folgen Sie müssen sich einloggen, um Studenten oder Kursen zu folgen.
Verkauft
486
Mitglied seit
5 Jahren
Anzahl der Follower
226
Dokumente
73
Zuletzt verkauft
5 Jahren vor
CrystalIndigo Solutions

providing all solutions to all computer science modules

4,1

51 rezensionen

5
27
4
13
3
6
2
1
1
4

Kürzlich von dir angesehen.

Warum sich Studierende für Stuvia entscheiden

on Mitstudent*innen erstellt, durch Bewertungen verifiziert

Geschrieben von Student*innen, die bestanden haben und bewertet von anderen, die diese Studiendokumente verwendet haben.

Nicht zufrieden? Wähle ein anderes Dokument

Kein Problem! Du kannst direkt ein anderes Dokument wählen, das besser zu dem passt, was du suchst.

Bezahle wie du möchtest, fange sofort an zu lernen

Kein Abonnement, keine Verpflichtungen. Bezahle wie gewohnt per Kreditkarte oder Sofort und lade dein PDF-Dokument sofort herunter.

Student with book image

“Gekauft, heruntergeladen und bestanden. So einfach kann es sein.”

Alisha Student

Häufig gestellte Fragen