everything pdf -define a data structure that is useful for modeling a given problem.
Recitation: Min & Max Heaps We’re going to need this one soon Topics: • • • • OOP in C++ Use of pointers Memory management Node linked data structure Outcomes: • • Identify, construct, and clearly define a data structure that is useful for modeling a given problem. Define data structures (types) such as heaps, balanced trees, hash tables. Description In this recitation assignment you will build a simple data structure known as a MinHeap. It will then be used to solve a problem. Use the following Guidelines: • • • • • Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). Keep identifiers to a reasonably short length. User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent. Use white space to make your program more readable. Important Note: All submitted assignments must begin with the descriptive comment block. To avoid losing trivial points, make sure this comment header is included in every assignment you submit, and that it is updated accordingly from assignment to assignment. February 2024 Programming Assignment: Instructions: We will be looking at and implementing a min-heap and a max-heap. The heap is a simple data structure that can be created either with an array or a tree like structure The heap has two major functions: • • add things to the heap remove the highest priority item from the heap Both heaps will be implemented with a template and put into the same .hpp file. Files: • minmaxheap_lastname.hpp Code Style: For yours, the instructors’, and the graders’ sake, keep your code well organized. Use proper indentation, variable names, and segmentation. ** BIG GIANT NOTE – TEMPLATES AND FILES ** When you use a templated type in C++, ALL templated code must be done in the .hpp file. This means that ALL of your methods will be defined in the .hpp file as well as your class. You should still forward declare Classes above and then implement the Methods below. Your .hpp file should have both, your LinkedList and Node classes, and their method definitions. Remember to use your :: operator correctly. Feel free to use friendship if needed. Tutorial – Exception Handling With data structures, often we must deal with PEBCAK errors (Problem Exists Between Chair and Keyboard). If we include a method in a Linked List that has the user add “at an index” we must account for that user giving a bad value, such as a negative number or one that is too large. C++ has added exception handling to the std:: namespace and it is fairly similar to Java exception handling. Syntax: try { //code goes here } catch(/*exception type*/) { //catch code } We raise an exception with the throw command: throw ; A big difference between Java and C++ is that you can throw just about anything. throw “an error happened”; throw std::out_of_range(); throw -1; Examples: #include using std::cout; using std::cin; using std::endl; #include using std::cout; using std::cin; using std::endl; int divide(int numerator, int denominator) { if(denominator = 0) { throw std::runtime_error(“Can’t divide by zero!”); } int divide(int numerator, int denominator) { if(denominator = 0) { throw “Can’t divide by Zero!”; } } return numerator / denominator; int main(int argc, char const *argv[]) { int numerator; int denominator; cout > numerator >> denominator; try { int test = divide(numerator, denominator); } catch(const std::runtime_error& err) { std::cerr > denominator; try { int test = divide(numerator, denominator); } catch(const char* messsage) { std::cerr
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.
