SlideShare uma empresa Scribd logo
1 de 11
Baixar para ler offline
In C++
Follow all code styling and submission instructions as outlined for previous labs. Write a program
to do the following: Use the same input seed data you used for Lab 4 (your BST homework) as
seed input data into a hash table. Declare a hash table of size 29 elements. To hash your currency
objects into the hash table, use the pseudorandom hash scheme - (m*w + n*f) % size - where size
= 29, m = 2, n = 3, w = whole value, f = fractional value. For collision resolution, use quadratic
probing in the same direction always. Remember to circle around to the start of the array if
needed. Your main will first load the data into the hash table and print the number of data items
loaded, load factor and number of collisions. Then it will ask the user in a loop to enter a Krone to
search for. If the Krone object is found in the hash table, it will print the index where found,
otherwise it will print 'Invalid Data'. Then it will ask the user if they want to check again or end the
program. To submit, upload your code files and screenshot of the console only. For
documentation, only name blocks and existing documentation in your Krone class are needed.
#include<iostream>
#include<fstream>
using namespace std;
class Node
{
public:
float value;
Node * left;
Node * right;
Node (float value)
{
this->value = value;
right = NULL;
left = NULL;
}
};
using namespace std;
int
main ()
{
BST bst;
ofstream outputFile ("output.txt");
// Seed the tree with 20 Krone objects
bst.insertNode (Krone (57, 12));
bst.insertNode (Krone (23, 44));
bst.insertNode (Krone (87, 43));
bst.insertNode (Krone (68, 99));
bst.insertNode (Krone (111, 22));
bst.insertNode (Krone (44, 55));
bst.insertNode (Krone (77, 77));
bst.insertNode (Krone (18, 36));
bst.insertNode (Krone (543, 21));
bst.insertNode (Krone (20, 21));
bst.insertNode (Krone (345, 67));
bst.insertNode (Krone (36, 18));
bst.insertNode (Krone (48, 48));
bst.insertNode (Krone (101, 0));
bst.insertNode (Krone (11, 0));
bst.insertNode (Krone (21, 0));
bst.insertNode (Krone (51, 0));
bst.insertNode (Krone (1, 0));
bst.insertNode (Krone (251, 0));
bst.insertNode (Krone (151, 0));
// Perform breadth-first traversal
queue < BSTNode * >bfsQueue;
bfsQueue.push (bst.getRoot ());
while (!bfsQueue.empty ())
{
BSTNode * currNode = bfsQueue.front ();
bfsQueue.pop ();
if (currNode != nullptr)
{
cout << currNode->getData () << " ";
outputFile << currNode->getData () << " ";
bfsQueue.push (currNode->getLeft ());
bfsQueue.push (currNode->getRight ());
}
}
cout << endl;
outputFile << endl;
// Perform in-order traversal
bst.printInOrder (outputFile);
// Perform pre-order traversal
bst.printPreOrder (outputFile);
// Perform post-order traversal
bst.printPostOrder (outputFile);
// Interactivity for adding/searching/deleting nodes
char choice;
do
{
cout <<
"nEnter 'a' to add a Krone object, 's' to search for a Krone object, 'd' to delete a Krone object, 'p' to
print data, or 'q' to quit: ";
cin >> choice;
if (choice == 'a')
{
Krone krone;
cout << "Enter a Krone object in the format 'x.y': ";
cin >> krone;
if (cin.fail ())
{
cout << "Invalid input. Ignoring this Krone object." << endl;
cin.clear ();
cin.ignore (numeric_limits < streamsize >::max (), 'n');
}
else
{
bst.insertNode (krone);
cout << "Krone object added." << endl;
}
}
else if (choice == 's')
{
Krone krone;
cout << "Enter a Krone object to search for in the format 'x.y': ";
cin >> krone;
if (cin.fail ())
{
cout << "Invalid input. Ignoring this Krone object." << endl;
cin.clear ();
cin.ignore (numeric_limits < streamsize >::max (), 'n');
}
else
{
BSTNode * foundNode = bst.searchNode (krone);
if (foundNode == nullptr)
{
cout << "Krone object not found
}
class BinaryTree
{
private:
Node * insertHelper (Node * current, float value)
{
if (current == NULL)
{
return new Node (value);
}
if (value < current->value)
{
current->left = insertHelper (current->left, value);
}
else if (value > current->value)
{
current->right = insertHelper (current->right, value);
}
else
{
return current;
}
return current;
}
bool searchNode (Node * current, float value)
{
if (current == NULL)
{
return false;
}
if (value == current->value)
{
return true;
}
return value < current->value ? searchNode (current->left,
value) :
searchNode (current->right, value);
}
Node * deleteHelper (Node * root, float key)
{
if (root == NULL)
return root;
if (key < root->value)
root->left = deleteHelper (root->left, key);
else if (key > root->value)
root->right = deleteHelper (root->right, key);
else
{
if (root->left == NULL)
return root->right;
else if (root->right == NULL)
return root->left;
root->value = minValue (root->right);
root->right = deleteHelper (root->right, root->value);
}
return root;
}
public:
Node * root;
void insert (float value)
{
root = insertHelper (root, value);
}
bool find (int value)
{
return searchNode (root, value);
}
void update (float old, float new_)
{
if (this->find (old))
{
this->delete_ (old);
this->insert (new_);
}
cout << "Element to be updated not found";
}
int minValue (Node * root)
{
int min = root->value;
while (root->left != NULL)
{
min = root->left->value;
root = root->left;
}
return min;
}
void delete_ (int key)
{
root = deleteHelper (root, key);
}
void postOrder (Node * node)
{
if (node != NULL)
{
postOrder (node->left);
postOrder (node->right);
cout << " " << node->value;
}
}
void preOrder (Node * node)
{
if (node != NULL)
{
cout << " " << node->value;
preOrder (node->left);
preOrder (node->right);
}
}
void inOrder (Node * node)
{
if (node != NULL)
{
inOrder (node->left);
cout << " " << node->value;
inOrder (node->right);
}
}
};
int
main ()
{
BinaryTree bt;
ifstream file;
file.open ("input.txt");
if (!file.is_open ())
{
cout << "File not found check file info" << endl;
}
else
{
string temp;
while (getline (file, temp))
{
temp.replace (0, 1, "");
float value = stof (temp);
bt.insert (value);
}
}
bt.preOrder (bt.root);
bt.postOrder (bt.root);
bt.inOrder (bt.root);
file.close ();
return 0;
}
#ifndef Krone_H
#define Krone_H
#include <iostream>
#include "currency.cpp"
using namespace std;
// derived class Krone from Currency class
class Krone : public Currency
{
private:
string currencyName;
public:
Krone()
{
currencyName = "Krone";
}
Krone(double value) : Currency(value)
{
currencyName = "Krone";
}
void print()
{
Currency::print();
cout << " " << currencyName << " ";
}
};
#endif

Mais conteúdo relacionado

Semelhante a In C++ Follow all code styling and submission instructions a.pdf

Boost.Interfaces
Boost.InterfacesBoost.Interfaces
Boost.Interfacesmelpon
 
I need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdfI need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdfallurafashions98
 
LeetCode April Coding Challenge
LeetCode April Coding ChallengeLeetCode April Coding Challenge
LeetCode April Coding ChallengeSunil Yadav
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfaksachdevahosymills
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListPTCL
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)Ankit Gupta
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfillyasraja7
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdfsudhirchourasia86
 
#include ctype.h #include stdio.h #include string.hstati.pdf
#include ctype.h #include stdio.h #include string.hstati.pdf#include ctype.h #include stdio.h #include string.hstati.pdf
#include ctype.h #include stdio.h #include string.hstati.pdfapleather
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02nikomatsakis
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python TricksBryan Helmig
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesOXUS 20
 

Semelhante a In C++ Follow all code styling and submission instructions a.pdf (20)

08 binarysearchtrees 1
08 binarysearchtrees 108 binarysearchtrees 1
08 binarysearchtrees 1
 
Boost.Interfaces
Boost.InterfacesBoost.Interfaces
Boost.Interfaces
 
I need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdfI need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdf
 
LeetCode April Coding Challenge
LeetCode April Coding ChallengeLeetCode April Coding Challenge
LeetCode April Coding Challenge
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Arrays
ArraysArrays
Arrays
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdf
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
 
C program
C programC program
C program
 
#include ctype.h #include stdio.h #include string.hstati.pdf
#include ctype.h #include stdio.h #include string.hstati.pdf#include ctype.h #include stdio.h #include string.hstati.pdf
#include ctype.h #include stdio.h #include string.hstati.pdf
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat Sheet
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
 

Mais de adithyaups

In Drosophila white eyes w and yellow body y are both r.pdf
In Drosophila white eyes w and yellow body y are both r.pdfIn Drosophila white eyes w and yellow body y are both r.pdf
In Drosophila white eyes w and yellow body y are both r.pdfadithyaups
 
In Drosophila vestigial wings is an autosomal recessive tra.pdf
In Drosophila vestigial wings is an autosomal recessive tra.pdfIn Drosophila vestigial wings is an autosomal recessive tra.pdf
In Drosophila vestigial wings is an autosomal recessive tra.pdfadithyaups
 
In Java Please Write a program AirplanSeatingAssignment.pdf
In Java Please   Write a program AirplanSeatingAssignment.pdfIn Java Please   Write a program AirplanSeatingAssignment.pdf
In Java Please Write a program AirplanSeatingAssignment.pdfadithyaups
 
In java Develop a menubased shapemaker using randomly gen.pdf
In java Develop a menubased shapemaker using randomly gen.pdfIn java Develop a menubased shapemaker using randomly gen.pdf
In java Develop a menubased shapemaker using randomly gen.pdfadithyaups
 
IN JAVA Develop a menubased shapemaker using randomly g.pdf
IN JAVA   Develop a menubased shapemaker using randomly g.pdfIN JAVA   Develop a menubased shapemaker using randomly g.pdf
IN JAVA Develop a menubased shapemaker using randomly g.pdfadithyaups
 
In hindsight Bitcoin experienced a speculative bubble Whic.pdf
In hindsight Bitcoin experienced a speculative bubble Whic.pdfIn hindsight Bitcoin experienced a speculative bubble Whic.pdf
In hindsight Bitcoin experienced a speculative bubble Whic.pdfadithyaups
 
in Figure 233 shows the different types Filiform papillae .pdf
in Figure 233 shows the different types Filiform papillae .pdfin Figure 233 shows the different types Filiform papillae .pdf
in Figure 233 shows the different types Filiform papillae .pdfadithyaups
 
In his analysis of the Dell fraud for Forbes Edward Hess co.pdf
In his analysis of the Dell fraud for Forbes Edward Hess co.pdfIn his analysis of the Dell fraud for Forbes Edward Hess co.pdf
In his analysis of the Dell fraud for Forbes Edward Hess co.pdfadithyaups
 
In his efforts to mobilize action learning and change in th.pdf
In his efforts to mobilize action learning and change in th.pdfIn his efforts to mobilize action learning and change in th.pdf
In his efforts to mobilize action learning and change in th.pdfadithyaups
 
In humans being a tongue roller R is dominant to being a .pdf
In humans being a tongue roller R is dominant to being a .pdfIn humans being a tongue roller R is dominant to being a .pdf
In humans being a tongue roller R is dominant to being a .pdfadithyaups
 
In HBS case studies Nextel Peru and Globalization of Cost of.pdf
In HBS case studies Nextel Peru and Globalization of Cost of.pdfIn HBS case studies Nextel Peru and Globalization of Cost of.pdf
In HBS case studies Nextel Peru and Globalization of Cost of.pdfadithyaups
 
in gibi g mesafesinin yksek olduu lkelerde alanlarn a.pdf
in gibi g mesafesinin yksek olduu lkelerde alanlarn a.pdfin gibi g mesafesinin yksek olduu lkelerde alanlarn a.pdf
in gibi g mesafesinin yksek olduu lkelerde alanlarn a.pdfadithyaups
 
In Figure 83 there are black squiggles in the RER compar.pdf
In Figure 83 there are black squiggles in the RER compar.pdfIn Figure 83 there are black squiggles in the RER compar.pdf
In Figure 83 there are black squiggles in the RER compar.pdfadithyaups
 
In early 2015 Ford Motor F had a book value of equity of .pdf
In early 2015 Ford Motor F had a book value of equity of .pdfIn early 2015 Ford Motor F had a book value of equity of .pdf
In early 2015 Ford Motor F had a book value of equity of .pdfadithyaups
 
In dogs locus B determines pigment color Bblack bbrown p.pdf
In dogs locus B determines pigment color Bblack bbrown p.pdfIn dogs locus B determines pigment color Bblack bbrown p.pdf
In dogs locus B determines pigment color Bblack bbrown p.pdfadithyaups
 
In Block 1 Week 3 there is a description of various social.pdf
In Block 1 Week 3 there is a description of various social.pdfIn Block 1 Week 3 there is a description of various social.pdf
In Block 1 Week 3 there is a description of various social.pdfadithyaups
 
In each of the following cases report the appropriate diagn.pdf
In each of the following cases report the appropriate diagn.pdfIn each of the following cases report the appropriate diagn.pdf
In each of the following cases report the appropriate diagn.pdfadithyaups
 
In Db class we have two attributesinstance variables with t.pdf
In Db class we have two attributesinstance variables with t.pdfIn Db class we have two attributesinstance variables with t.pdf
In Db class we have two attributesinstance variables with t.pdfadithyaups
 
In descriptive statistics the term standard error refers .pdf
In descriptive statistics the term standard error refers .pdfIn descriptive statistics the term standard error refers .pdf
In descriptive statistics the term standard error refers .pdfadithyaups
 
In catastropheFamine phase the action required is Action r.pdf
In catastropheFamine phase the action required is Action r.pdfIn catastropheFamine phase the action required is Action r.pdf
In catastropheFamine phase the action required is Action r.pdfadithyaups
 

Mais de adithyaups (20)

In Drosophila white eyes w and yellow body y are both r.pdf
In Drosophila white eyes w and yellow body y are both r.pdfIn Drosophila white eyes w and yellow body y are both r.pdf
In Drosophila white eyes w and yellow body y are both r.pdf
 
In Drosophila vestigial wings is an autosomal recessive tra.pdf
In Drosophila vestigial wings is an autosomal recessive tra.pdfIn Drosophila vestigial wings is an autosomal recessive tra.pdf
In Drosophila vestigial wings is an autosomal recessive tra.pdf
 
In Java Please Write a program AirplanSeatingAssignment.pdf
In Java Please   Write a program AirplanSeatingAssignment.pdfIn Java Please   Write a program AirplanSeatingAssignment.pdf
In Java Please Write a program AirplanSeatingAssignment.pdf
 
In java Develop a menubased shapemaker using randomly gen.pdf
In java Develop a menubased shapemaker using randomly gen.pdfIn java Develop a menubased shapemaker using randomly gen.pdf
In java Develop a menubased shapemaker using randomly gen.pdf
 
IN JAVA Develop a menubased shapemaker using randomly g.pdf
IN JAVA   Develop a menubased shapemaker using randomly g.pdfIN JAVA   Develop a menubased shapemaker using randomly g.pdf
IN JAVA Develop a menubased shapemaker using randomly g.pdf
 
In hindsight Bitcoin experienced a speculative bubble Whic.pdf
In hindsight Bitcoin experienced a speculative bubble Whic.pdfIn hindsight Bitcoin experienced a speculative bubble Whic.pdf
In hindsight Bitcoin experienced a speculative bubble Whic.pdf
 
in Figure 233 shows the different types Filiform papillae .pdf
in Figure 233 shows the different types Filiform papillae .pdfin Figure 233 shows the different types Filiform papillae .pdf
in Figure 233 shows the different types Filiform papillae .pdf
 
In his analysis of the Dell fraud for Forbes Edward Hess co.pdf
In his analysis of the Dell fraud for Forbes Edward Hess co.pdfIn his analysis of the Dell fraud for Forbes Edward Hess co.pdf
In his analysis of the Dell fraud for Forbes Edward Hess co.pdf
 
In his efforts to mobilize action learning and change in th.pdf
In his efforts to mobilize action learning and change in th.pdfIn his efforts to mobilize action learning and change in th.pdf
In his efforts to mobilize action learning and change in th.pdf
 
In humans being a tongue roller R is dominant to being a .pdf
In humans being a tongue roller R is dominant to being a .pdfIn humans being a tongue roller R is dominant to being a .pdf
In humans being a tongue roller R is dominant to being a .pdf
 
In HBS case studies Nextel Peru and Globalization of Cost of.pdf
In HBS case studies Nextel Peru and Globalization of Cost of.pdfIn HBS case studies Nextel Peru and Globalization of Cost of.pdf
In HBS case studies Nextel Peru and Globalization of Cost of.pdf
 
in gibi g mesafesinin yksek olduu lkelerde alanlarn a.pdf
in gibi g mesafesinin yksek olduu lkelerde alanlarn a.pdfin gibi g mesafesinin yksek olduu lkelerde alanlarn a.pdf
in gibi g mesafesinin yksek olduu lkelerde alanlarn a.pdf
 
In Figure 83 there are black squiggles in the RER compar.pdf
In Figure 83 there are black squiggles in the RER compar.pdfIn Figure 83 there are black squiggles in the RER compar.pdf
In Figure 83 there are black squiggles in the RER compar.pdf
 
In early 2015 Ford Motor F had a book value of equity of .pdf
In early 2015 Ford Motor F had a book value of equity of .pdfIn early 2015 Ford Motor F had a book value of equity of .pdf
In early 2015 Ford Motor F had a book value of equity of .pdf
 
In dogs locus B determines pigment color Bblack bbrown p.pdf
In dogs locus B determines pigment color Bblack bbrown p.pdfIn dogs locus B determines pigment color Bblack bbrown p.pdf
In dogs locus B determines pigment color Bblack bbrown p.pdf
 
In Block 1 Week 3 there is a description of various social.pdf
In Block 1 Week 3 there is a description of various social.pdfIn Block 1 Week 3 there is a description of various social.pdf
In Block 1 Week 3 there is a description of various social.pdf
 
In each of the following cases report the appropriate diagn.pdf
In each of the following cases report the appropriate diagn.pdfIn each of the following cases report the appropriate diagn.pdf
In each of the following cases report the appropriate diagn.pdf
 
In Db class we have two attributesinstance variables with t.pdf
In Db class we have two attributesinstance variables with t.pdfIn Db class we have two attributesinstance variables with t.pdf
In Db class we have two attributesinstance variables with t.pdf
 
In descriptive statistics the term standard error refers .pdf
In descriptive statistics the term standard error refers .pdfIn descriptive statistics the term standard error refers .pdf
In descriptive statistics the term standard error refers .pdf
 
In catastropheFamine phase the action required is Action r.pdf
In catastropheFamine phase the action required is Action r.pdfIn catastropheFamine phase the action required is Action r.pdf
In catastropheFamine phase the action required is Action r.pdf
 

Último

latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answersdalebeck957
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 

Último (20)

latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 

In C++ Follow all code styling and submission instructions a.pdf

  • 1. In C++ Follow all code styling and submission instructions as outlined for previous labs. Write a program to do the following: Use the same input seed data you used for Lab 4 (your BST homework) as seed input data into a hash table. Declare a hash table of size 29 elements. To hash your currency objects into the hash table, use the pseudorandom hash scheme - (m*w + n*f) % size - where size = 29, m = 2, n = 3, w = whole value, f = fractional value. For collision resolution, use quadratic probing in the same direction always. Remember to circle around to the start of the array if needed. Your main will first load the data into the hash table and print the number of data items loaded, load factor and number of collisions. Then it will ask the user in a loop to enter a Krone to search for. If the Krone object is found in the hash table, it will print the index where found, otherwise it will print 'Invalid Data'. Then it will ask the user if they want to check again or end the program. To submit, upload your code files and screenshot of the console only. For documentation, only name blocks and existing documentation in your Krone class are needed. #include<iostream> #include<fstream> using namespace std; class Node { public: float value; Node * left; Node * right; Node (float value) { this->value = value; right = NULL; left = NULL; } }; using namespace std; int main () { BST bst;
  • 2. ofstream outputFile ("output.txt"); // Seed the tree with 20 Krone objects bst.insertNode (Krone (57, 12)); bst.insertNode (Krone (23, 44)); bst.insertNode (Krone (87, 43)); bst.insertNode (Krone (68, 99)); bst.insertNode (Krone (111, 22)); bst.insertNode (Krone (44, 55)); bst.insertNode (Krone (77, 77)); bst.insertNode (Krone (18, 36)); bst.insertNode (Krone (543, 21)); bst.insertNode (Krone (20, 21)); bst.insertNode (Krone (345, 67)); bst.insertNode (Krone (36, 18)); bst.insertNode (Krone (48, 48)); bst.insertNode (Krone (101, 0)); bst.insertNode (Krone (11, 0)); bst.insertNode (Krone (21, 0)); bst.insertNode (Krone (51, 0)); bst.insertNode (Krone (1, 0)); bst.insertNode (Krone (251, 0)); bst.insertNode (Krone (151, 0)); // Perform breadth-first traversal queue < BSTNode * >bfsQueue;
  • 3. bfsQueue.push (bst.getRoot ()); while (!bfsQueue.empty ()) { BSTNode * currNode = bfsQueue.front (); bfsQueue.pop (); if (currNode != nullptr) { cout << currNode->getData () << " "; outputFile << currNode->getData () << " "; bfsQueue.push (currNode->getLeft ()); bfsQueue.push (currNode->getRight ()); } } cout << endl; outputFile << endl; // Perform in-order traversal bst.printInOrder (outputFile); // Perform pre-order traversal bst.printPreOrder (outputFile); // Perform post-order traversal bst.printPostOrder (outputFile); // Interactivity for adding/searching/deleting nodes char choice; do {
  • 4. cout << "nEnter 'a' to add a Krone object, 's' to search for a Krone object, 'd' to delete a Krone object, 'p' to print data, or 'q' to quit: "; cin >> choice; if (choice == 'a') { Krone krone; cout << "Enter a Krone object in the format 'x.y': "; cin >> krone; if (cin.fail ()) { cout << "Invalid input. Ignoring this Krone object." << endl; cin.clear (); cin.ignore (numeric_limits < streamsize >::max (), 'n'); } else { bst.insertNode (krone); cout << "Krone object added." << endl; } } else if (choice == 's') { Krone krone; cout << "Enter a Krone object to search for in the format 'x.y': "; cin >> krone; if (cin.fail ()) { cout << "Invalid input. Ignoring this Krone object." << endl;
  • 5. cin.clear (); cin.ignore (numeric_limits < streamsize >::max (), 'n'); } else { BSTNode * foundNode = bst.searchNode (krone); if (foundNode == nullptr) { cout << "Krone object not found } class BinaryTree { private: Node * insertHelper (Node * current, float value) { if (current == NULL) { return new Node (value); } if (value < current->value) { current->left = insertHelper (current->left, value); } else if (value > current->value) { current->right = insertHelper (current->right, value); } else { return current;
  • 6. } return current; } bool searchNode (Node * current, float value) { if (current == NULL) { return false; } if (value == current->value) { return true; } return value < current->value ? searchNode (current->left, value) : searchNode (current->right, value); } Node * deleteHelper (Node * root, float key) { if (root == NULL) return root; if (key < root->value) root->left = deleteHelper (root->left, key); else if (key > root->value) root->right = deleteHelper (root->right, key); else {
  • 7. if (root->left == NULL) return root->right; else if (root->right == NULL) return root->left; root->value = minValue (root->right); root->right = deleteHelper (root->right, root->value); } return root; } public: Node * root; void insert (float value) { root = insertHelper (root, value); } bool find (int value) { return searchNode (root, value); } void update (float old, float new_) { if (this->find (old)) { this->delete_ (old);
  • 8. this->insert (new_); } cout << "Element to be updated not found"; } int minValue (Node * root) { int min = root->value; while (root->left != NULL) { min = root->left->value; root = root->left; } return min; } void delete_ (int key) { root = deleteHelper (root, key); } void postOrder (Node * node) { if (node != NULL) {
  • 9. postOrder (node->left); postOrder (node->right); cout << " " << node->value; } } void preOrder (Node * node) { if (node != NULL) { cout << " " << node->value; preOrder (node->left); preOrder (node->right); } } void inOrder (Node * node) { if (node != NULL) { inOrder (node->left); cout << " " << node->value; inOrder (node->right); } }
  • 10. }; int main () { BinaryTree bt; ifstream file; file.open ("input.txt"); if (!file.is_open ()) { cout << "File not found check file info" << endl; } else { string temp; while (getline (file, temp)) { temp.replace (0, 1, ""); float value = stof (temp); bt.insert (value); } } bt.preOrder (bt.root); bt.postOrder (bt.root); bt.inOrder (bt.root); file.close (); return 0; } #ifndef Krone_H #define Krone_H #include <iostream>
  • 11. #include "currency.cpp" using namespace std; // derived class Krone from Currency class class Krone : public Currency { private: string currencyName; public: Krone() { currencyName = "Krone"; } Krone(double value) : Currency(value) { currencyName = "Krone"; } void print() { Currency::print(); cout << " " << currencyName << " "; } }; #endif