Hey, i've wrote a script that will test three diffrent sorting methods and display how much time each method took to complete in order to compare the diffrent methods. The problem is that i'm suppose to show the results inside a 2 dimentional graph, and i'm not that much of an expert in c++ and zero knowledge in c++ graphics, so i was wondering if someone could help me out, i'm using visual studio 2008.

here's what i have:

#include<ctime>
#include <cstdlib> 
  using std::rand;                                                      
  using std::srand;
#include<iostream>
 using namespace std;
 
void BubbleSort (int *q , int n)
{
     int permut , i , aux;
     do
     {
         permut = 0;
         for(i=0 ; i<n-1; i++)
            if(q[i]>q[i+1])
            {
                aux = q[i];
                q[i] = q[i+1];
                q[i+1] = aux;
                permut = 1;
            }   
      }while(permut==1);      
}

void SelectionSort (int *q , int n)
{
     int i , j , aux , imin;
     for(i=0 ; i<n-1 ; i++)
        {
            imin = i ;
            for(j=i+1 ; j<n ;j++)
               if(q[j] < q[imin])
                  imin = j;
            if(imin!=i)
            {
                aux = q[imin];
                q[imin] = q[i];
                q[i] = aux;
            }
        }
}     

void InsertionSort (int*q , int n)
{
     int i , j , k , newVal;
     for(i=0 ; i<n ; i++)
     {
         newVal = rand();
         j=0;
         while((j < i) && (q[j] <= newVal))
            j++;
         for(k=i-1 ; k>=j ; k--)
            q[k+1] = q[k];
         q[j]=newVal;
     }
}   
                
 

int main()
{
    double av1=0 , av2=0 , av3=0;
    int i , j;
    const int n1=10000 , n2=20000 , n3=30000;
    int a1[n1] , b1[n1] , c1[n1];
    int a2[n2] , b2[n2] , c2[n2];
    int a3[n3] , b3[n3] , c3[n3];
    
    srand(0);
    
    for(i=0 ; i<10 ;i++)
    {
       for(j=0; j<n1; j++)
          a1[j] = rand();      
          
       for(j=0; j<n2; j++)
          a2[j] = rand(); 
          
       for(j=0; j<n3; j++)
          a3[j] = rand();
          
       clock_t t1=clock();
       BubbleSort(a1,n1);
       clock_t t2=clock();
       av1+=double(t2-t1);  
       
       clock_t t3=clock();
       BubbleSort(a2,n2);
       clock_t t4=clock();
       av2+=double(t4-t3);
       
       clock_t t5=clock();
       BubbleSort(a3,n3);
       clock_t t6=clock();
       av3+=double(t6-t5); 
       
    }
    cout<<"The average time of Bubble Sorting for 10000 elements is "<<av1/10<<endl;
    cout<<"The average time of Bubble Sorting for 20000 elements is "<<av2/10<<endl;
    cout<<"The average time of Bubble Sorting for 30000 elements is "<<av3/10<<endl;
    cout<<endl<<endl;
    
    av1=av2=av3=0; 
     
     for(i=0 ; i<10 ;i++)
    {
       for(j=0; j<1000; j++)
          b1[j] = rand();      
          
       for(j=0; j<2000; j++)
          b2[j] = rand(); 
          
       for(j=0; j<3000; j++)
          b3[j] = rand();
          
       clock_t t1=clock();
       SelectionSort(b1,n1);
       clock_t t2=clock();
       av1+=double(t2-t1);  
       
       clock_t t3=clock();
       SelectionSort(b2,n2);
       clock_t t4=clock();
       av2+=double(t4-t3);
       
       clock_t t5=clock();
       SelectionSort(b3,n3);
       clock_t t6=clock();
       av3+=double(t6-t5); 
       
    }
    cout<<"The average time of Selection Sorting for 10000 elements is "<<av1/10<<endl;
    cout<<"The average time of Selection Sorting for 20000 elements is "<<av2/10<<endl;
    cout<<"The average time of Selection Sorting for 30000 elements is "<<av3/10<<endl;
    cout<<endl<<endl;
    
    av1=av2=av3=0;
     
    clock_t t1=clock();
    InsertionSort(c1,n1);
    clock_t t2=clock();
    av1+=double(t2-t1); 
    
    clock_t t3=clock();
    InsertionSort(c2,n2);
    clock_t t4=clock();
    av2+=double(t4-t3);
    
    clock_t t5=clock();
    InsertionSort(c3,n3);
    clock_t t6=clock();
    av3+=double(t6-t5);
    
    cout<<"The average time of Insertion Sorting for 10000 elements is "<<av1/10<<endl;
    cout<<"The average time of Insertion Sorting for 20000 elements is "<<av2/10<<endl;
    cout<<"The average time of Insertion Sorting for 30000 elements is "<<av3/10<<endl;
    cout<<endl<<endl;
     
   system("PAUSE"); 
 return 0;       
}

What i'm looking for is somekind of a plugin or a script that will display these results inside a graph(in a pop up window maybe?!!)

Regards

Recommended Answers

All 3 Replies

Good luck on finding a plug in or script. There are three options I can think of. 1) You can search the net and try to find something. 2) You can hang around here (or some other site) until someone gives you a reference. 3) You can work something up yourself. C++ doesn't come with native support for graphics, though there are graphics programs written in C++. Learning to use them has a learning curve so don't expect to become an expert overnight. If your project isn't due for another week or two and you don't have anything else to do but this, then you can probably do it. If you want referals for one of the graphics programs post the request (or search the board/site) and you will probably get several suggesstions. The alternative is to write a program using ASCII characters, which you already have all the necessary skills to do. All it takes is a nested loop to display the relative values obtained from av1, av2, and av3. That should allow you to do something like this:

av1 | *************
av2 | *****
av3 | *********

where each * represents 0.1 seconds, or whatever. It may not be the most sophiscticated 2 dimensional graph, but it is something you can do without learning anything new.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.