Thread: Display problem

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    32

    Display problem

    The problem I am having is that it is not displaying anything other than the input feature.

    the code is as follows:
    Code:
    #include "input.h"
    #include <string>
    #include <vector>
    #include <iostream>
    using namespace std;
    
    class vecMath
    {
       private:
          vector<int> L;
       public:
          void addVector(vector<int> L);
          void display(ostream& out);
          void quickSort(vector<int>& L,int start, int stop);
          void quickSort(vector<int>& L);
          void swap(int& x,int& y);
          int vecMean(vector<int> L);
          int vecMed(vector<int> L);
       };
       
    void vecMath::quickSort(vector<int>& L,int start,int stop)
    {
       //cerr<<"SORTING"<<start<<""<<stop<<endl;
       bool finish=false;
       if(finish!=true)
       {
       if(start >= stop) 
       {finish=true;}
       int i=start-1,j=stop,lastSmall=start;
       bool doneLeft=false;
       while(doneLeft==false)
       {
          if(L[i]>L[start])
          {
             bool doneRight=false;
    	 while (doneRight==false)
    	 {
    	    if(L[j]<=L[start])
    	    {
    	       swap(L[i],L[j]);
    	       doneRight=true;
    	       lastSmall=i;
    	    }
    	    j--;
    	    if(j==i)
    	       doneRight=true;
    	 }
          }
          i++;
          if(L[i]<L[start]){
             lastSmall=i;
          }
          if(i>=j){
             doneLeft=true;
          }
          
       }
       swap(L[start],L[lastSmall]);
       quickSort(L,start,lastSmall-1);//sort the left side
       quickSort(L,lastSmall+1,stop);//sort the right side
       }
    }
    
    void vecMath::quickSort(vector<int>& L)
    {quickSort(L,0,L.size()-1);}
    
    void vecMath::swap(int& x,int& y)
    {
       int tmp=x;
       x=y;
       y=tmp;
    }
    
    void vecMath::addVector(vector<int> L)
    {
       char resp;
       do{
          int x=readInt("Number is:",true);
          L.push_back(x);
          cout<<"Do you have more values?(y/n)";
          do{
             cin.ignore(256,'\n');
    	 cin>>resp;
          }while(resp !='y'&&resp!='n');
       }while (resp=='y');
       quickSort(L);
    }
    
    int vecMath::vecMean(vector<int> L)
    {int mean=L[L.size()/2];
     return mean;}
    
    int vecMath::vecMed(vector<int> L)
    {int med=(L[L.size()/2]+L[(L.size()/2)-1])/2;
     return med;}
    
    void vecMath::display(ostream& out)
    {
       vector<int> L;
       int mean;
       int med;
       for(int i=0;i<L.size()-1;i++)
       {cout<<L[i]<<" "<<endl;}
       if(L.size()==1)
          out<<"The mean and median of your single number is "<<L[L.size()-1]<<endl;
       else{
       out<<"The mean of the list is "<<mean<<endl;
       out<<"The median of the list is "<<med<<endl;
       }
    }
    
    int main()
    {
       vecMath A;
       vector<int> L;
       A.vecMean(L);
       A.vecMed(L);
       A.addVector(L);
       for(int i=0;i<L.size();i++)
       {cout<<L[i]<<" "<<endl;}
       
       A.display(cout);
    
       L.clear();
       return 0;
    }
    if someone could please help i would be most appreciated
    i know that I am not supposed to post my entire program but i just have no clue as to what/where the problem is

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    32
    Ignore this problem, it has been fixed already

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. new problem with class
    By jrb47 in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2006, 08:39 AM
  2. Display problem
    By Birdhaus in forum C++ Programming
    Replies: 1
    Last Post: 09-06-2006, 03:52 PM
  3. Replies: 2
    Last Post: 06-21-2006, 04:23 AM
  4. Display problem
    By RoD in forum C++ Programming
    Replies: 11
    Last Post: 10-09-2002, 05:25 PM
  5. display problem after retrieving from text
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 01-29-2002, 06:48 AM

Tags for this Thread