Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Overig

COS assignment 2 solution

Beoordeling
5,0
(3)
Verkocht
17
Pagina's
15
Geüpload op
13-07-2023
Geschreven 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)

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

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

Gekoppeld boek

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
13 juli 2023
Aantal pagina's
15
Geschreven in
2022/2023
Type
OVERIG
Persoon
Onbekend

Onderwerpen

€4,69
Krijg toegang tot het volledige document:
Gekocht door 17 studenten

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kan je een ander document kiezen. Je kan het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Beoordelingen van geverifieerde kopers

Alle 3 reviews worden weergegeven
2 jaar geleden

Running and working perfectly

2 jaar geleden

2 jaar geleden

5,0

3 beoordelingen

5
3
4
0
3
0
2
0
1
0
Betrouwbare reviews op Stuvia

Alle beoordelingen zijn geschreven door echte Stuvia-gebruikers na geverifieerde aankopen.

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
CrystalIndigo University of South Africa (Unisa)
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
486
Lid sinds
5 jaar
Aantal volgers
226
Documenten
73
Laatst verkocht
5 maanden geleden
CrystalIndigo Solutions

providing all solutions to all computer science modules

4,1

51 beoordelingen

5
27
4
13
3
6
2
1
1
4

Populaire documenten

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via Bancontact, iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo eenvoudig kan het zijn.”

Alisha Student

Veelgestelde vragen