Limited_Ice

main

May 16th, 2021
671
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //  David Hawkins
  2. //  SDEV-345-81 Data Structures and Algorithmns
  3. //  5/14/2021
  4.  
  5. /*
  6.  
  7. This program is a program of my choice (a database for part numbers using a binary tree) that
  8. demonstrates the following C++ features.
  9.  
  10. --1) A main function that utilizes minimum code to drive the program. Coding details shall be in appropriately-implemented classes.
  11.  
  12. --2) At least three class modules, one abstract base class and two associated derived classes.
  13.  
  14. --3) At least one example of an overloaded constructor.
  15.         The constructor for partnum executes in a unique manner when creating the root node for the database because the root node will not have
  16.         a value for the pointer to the parent node.
  17.  
  18. --4) At least one polymorphic method.
  19.         Many of the private methods in the partnum class are polymorphic.  The "ismember" function in the partnum class has two variations to act as a check
  20.         during other class functions.
  21.  
  22. --5) At least one pointer and one reference.
  23.         A binary tree is built entirely out of pointers and references.  The tree deletes itself upon exiting (if closed from the menu) to avoid
  24.         hanging pointers and mempry leak.
  25.  
  26. --6) Demonstrate correct use of public, private and protected keywords.
  27.         The polymorphic functions in the partnum class can only be called by the simple public version.  I attempted to keep as much of the logic
  28.         private to the class as possible for ease of use in the main function.
  29.  
  30. */
  31.  
  32. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  33. //  Header Files and Libraries
  34.  
  35. using namespace std;
  36.  
  37. #include <iostream>
  38. #include <iomanip>
  39. #include <fstream>
  40. #include <vector>
  41. #include "partnum.h"
  42. #include "shapes.h"
  43. #include "DavidFunctions.h"
  44.  
  45. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  46. //  Main Function
  47.  
  48. int main() {
  49.     int choice;
  50.     int partnumber, quantity;
  51.     partnum* root = nullptr;
  52.     triangle* mytri = nullptr;
  53.     rectangle* myrec = nullptr;
  54.     intro(80);
  55.     ifstream save;
  56.     save.open("partdatabase.txt");
  57.     if (save) {
  58.         save >> partnumber;
  59.         save >> quantity;
  60.         root = new partnum(partnumber, quantity);
  61.         do {
  62.             save >> partnumber;
  63.             save >> quantity;
  64.             root->build(partnumber, quantity);
  65.         } while (!save.eof());
  66.     }
  67.     save.close();
  68.     cin.sync();
  69.  
  70.  
  71.     while (true) {
  72.         pad();
  73.         cout << "What would you like to do?\n\n1) Look up a part\n\n2) change a parts quantity\n\n3) Add a new part to the database" <<
  74.             "\n\n4) Save Changes\n\n5) Exit Program\n\n6) Remove Database from Machine\n\n7) Play with Shapes" << endl;
  75.         pad();
  76.         cout << "Your selection: ";
  77.         cin >> choice;
  78.         pad();
  79.         switch (choice) {
  80.         case 1:
  81.             if (root == nullptr)
  82.                 cout << "There are no parts in the database" << endl;
  83.             else
  84.                 root->search();
  85.             break;
  86.         case 2:
  87.             if (root == nullptr)
  88.                 cout << "There are no parts in the database" << endl;
  89.             else
  90.                 root->change();
  91.             pad();
  92.             break;
  93.         case 3:
  94.             cout << "You chose to add a new part\n\nenter the part number: ";
  95.             cin >> partnumber;
  96.             cout << "enter the quantity: ";
  97.             cin >> quantity;
  98.             if (root == nullptr) {
  99.                 root = new partnum(partnumber, quantity);
  100.             }
  101.             else {
  102.                 root->addnewpart(partnumber, quantity);
  103.             }
  104.             pad();
  105.             break;
  106.         case 4:
  107.             if (root != nullptr)
  108.                 root->initsave();
  109.             break;
  110.         case 5:
  111.             if (root != nullptr) {
  112.                 root->initdel();
  113.                 delete root;
  114.                 root = nullptr;
  115.             }
  116.             exit(0);
  117.         case 6:
  118.             if (root != nullptr) {
  119.                 root->initsave();
  120.                 delete root;
  121.                 root = nullptr;
  122.             }
  123.             remove("partdatabase.txt");
  124.             break;
  125.         case 7:
  126.             choice = chooseshape();
  127.             switch (choice) {
  128.             case 1:
  129.                 mytri = new triangle();
  130.                 break;
  131.             case 2:
  132.                 myrec = new rectangle();
  133.                 break;
  134.             case 3:
  135.                 system("cls");
  136.                 cin.sync();
  137.                 break;
  138.             }
  139.             break;
  140.         default:
  141.             cout << "Use correct inputs, select using the number \"1\", \"2\",\"3\", \"4\", or \"5\"." << endl;
  142.             pad();
  143.         }
  144.     }
  145.  
  146.     return 0;
  147. }
  148.  
RAW Paste Data