Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 13.58.61.197
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/stutreeclient2.cpp
// Benjamin Freeman
// November 12, 2008

// stutreeclient2.cpp - test client for gradetree class

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

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

   	Gradetree grades, mygrades, yourgrades;
   
	int sum, ng, nc, lc, nfc, hi;
  
	float avg;
   	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);
   	grades.Insert (60);
	grades.Insert (45);
	grades.Insert (30);
	grades.Insert (9);
	
   	// Display picture of tree

   	grades.TreePicture ();

	// add grades
        sum=grades.SumGrades();
        cout << "\nThe sum of the grades is 1282, the program says: " << sum << endl;
        
        // total
        ng=grades.NumGrades();
        cout << "\nThe total number of grades is 18, the program says: " << ng << endl;
        
        // Average
        avg=grades.AvgGrade();
        cout << "\nThe average of grades is 71.2: " << avg << endl;
                
        // NodeCount
        nc=grades.NodeCount();
        cout << "\nThe number of nodes is 18, the program says: " << nc << endl;
        
        // LeafCount
        lc=grades.LeafCount();
        cout << "\nThe number of Leaf Nodes is 7, the program says: " << lc << endl;
        
        //NonLeafCount
        nfc=grades.NonLeafCount();
        cout << "\nThe number of Non Leaf Nodes is 11, the program says: " << nfc << endl;
        
        //Height
        hi=grades.Height(); 
        if(hi==-1)
                cout << "\nThe tree is empty\n";
	else
                cout << "\nThe height of the tree is 6, the program says: " << hi << endl;

	cout <<"\n-------------------------------------------------\n";

	//------------------------------------
	// This is a new tree
	//------------------------------------
   	cout << "\n--------This is a new tree.\n";
   	mygrades.Insert(90);
   	mygrades.Insert(92);
   	mygrades.Insert(77);
   	mygrades.Insert(85);
   	mygrades.Insert(90);
  	mygrades.Insert(40);
	
	cout << "\nThis is a picture of it.\n";
   	mygrades.TreePicture();

	// add grades
        sum=mygrades.SumGrades();
        cout << "\nThe sum of the grades is 474, the program says: " << sum << endl;
        
        // total
        ng=mygrades.NumGrades();
        cout << "\nThe total number of grades is 6, the program says: " << ng << endl;
        
        // Average
        avg=mygrades.AvgGrade();
        cout << "\nThe average of grades is 79, the program says: " << avg << endl;
        
        // NodeCount
        nc=mygrades.NodeCount();
        cout << "\nThe number of nodes is 5, the program says: " << nc << endl;
        
        // LeafCount
        lc=mygrades.LeafCount();
        cout << "\nThe number of Leaf Nodes is 3, the program says: " << lc << endl;
        
        //NonLeafCount
        nfc=mygrades.NonLeafCount();
        cout << "\nThe number of Non Leaf Nodes is 2, the program says: " << nfc << endl;
       
	//Height()
   	hi=mygrades.Height();
	if(hi==-1)
                cout << "\nThe tree is empty\n";
        else
   		cout << "\nThe height of the tree is 2, the program says: " << hi << endl;

	cout <<"\n-------------------------------------------------\n";

	//-------------------------------------------------
	//Let's compare the two trees, they should not match
	//-------------------------------------------------

	cout <<"\n--------Let's compare the trees\n";
	// SimilarTrees()  
        if( grades.SimilarTrees(mygrades) )   
                cout << "\nThe trees match\n";
        else
                cout << "\nThe trees don't match\n";
        

        // compare to the same tree, they should match
	cout << "\n--------Compare two trees that are the same\n";
        yourgrades=mygrades;
        
        if( mygrades.SimilarTrees(yourgrades) )
            cout << "\nThe trees match\n";
        else
             cout << "\nThe trees don't match\n";

	
	cout <<"\n-------------------------------------------------\n";

	//delete
	mygrades.Delete(77);
	mygrades.Delete(92);	
	mygrades.Delete(85);
        mygrades.Delete(40);

	cout << "\n--------This is the new tree with all but one deleted\n";
 	mygrades.TreePicture();

	//--------------------------------------------
       	// Test for just one node in the tree
	//--------------------------------------------
		
	cout << "\n--------Test for just one node in the tree\n";  
        // add grades
        sum=mygrades.SumGrades();
        cout << "\nThe sum of the grades is 180, the program says: " << sum << endl;
        
        // total
        ng=mygrades.NumGrades();
        cout << "\nThe total number of grades is 2: " << ng << endl;
        
        // Average
        avg=mygrades.AvgGrade();
        cout << "\nThe average of grades is 90: " << avg << endl;
        
        // NodeCount
        nc=mygrades.NodeCount();
        cout << "\nThe number of nodes is 1, the program says: " << nc << endl;
        
        // LeafCount
        lc=mygrades.LeafCount();
        cout << "\nThe number of Leaf Nodes is 1, the program says: " << lc << endl;
        
        //NonLeafCount
        nfc=mygrades.NonLeafCount();
        cout << "\nThe number of Non Leaf Nodes is 0, the program says: " << nfc << endl;

	//Height()
        hi=mygrades.Height();
	if(hi==-1)
        	cout << "\nThe tree is empty\n";
        else
	        cout << "\nThe height of the tree is 0, the program says: " << hi << endl;


	cout <<"\n-------------------------------------------------\n";
	mygrades.Delete(90);
	mygrades.Delete(90);

	//-------------------------------
	//Test for an empty node
	//-------------------------------

	cout <<"\n--------Test for an empty node\n";
	// add grades
        sum=mygrades.SumGrades();
        cout << "\nThe sum of the grades is 0, the program says: " << sum << endl;
	
        // Average
        avg=mygrades.AvgGrade();
        cout << "\nThere is no average so the answer is nan: " << avg << endl;   
        
        // NodeCount
        nc=mygrades.NodeCount();
        cout << "\nThe number of nodes is 0, the program says: " << nc << endl;
        
        // LeafCount
        lc=mygrades.LeafCount();
        cout << "\nThe number of Leaf Nodes is 0, the program says: " << lc << endl;
        
        //NonLeafCount
        nfc=mygrades.NonLeafCount();
        cout << "\nThe number of Non Leaf Nodes is 0, the program says: " << nfc << endl;
        
        //Height() 
        hi=mygrades.Height();
	if(hi==-1)
		cout << "\nThe tree is empty\n";
	else
        	cout << "\nThe height of the tree is: " << hi << endl;
        


 	
   	return 0;


}






Stv3n404 - 2023