I need help

This is a discussion on I need help within the C++ Programming forums, part of the General Programming Boards category; Code: void ShuffleExchangeSort(mainStruct& mouse) { bool bvar; //this variable will be used to indicate if the list is ordered. //Some ...

  1. #16
    Registered User
    Join Date
    Sep 2005
    Posts
    18
    Code:
    void ShuffleExchangeSort(mainStruct& mouse)
    {
      	bool bvar;					//this variable will be used to indicate if the list is ordered.
        //Some looping structure.
        {
          	bvar=true;
        }
    }
    When i compare the times would i just use a > or< or would i use some sort of swap function?
    Wow this is too advanced for me...

  2. #17
    Registered User
    Join Date
    Sep 2005
    Posts
    18
    I have come up with this conclusion for the sort function:
    Code:
    void ShuffleExchangeSort(mainStruct& mouse)
    {
      	int k;
      	bool bvar;					//this variable will be used to indicate if the list is ordered.
        
          	k=0;
          	bvar=true;
            
    	while(k<N-1 && bvar)
        {
          bvar=false;
          k++;
          for(int i=0; i<n-k; j++)
          {
            if(list[i].number > list[i+1].number)
            swap(list,i,i+1);
            bvar=true;
          }
        }
    }
    I looked at a piece of code from class and am getting errors, do i need other functions?

  3. #18
    Registered User
    Join Date
    Sep 2005
    Posts
    18
    Here is my most up to date piece of code:
    Code:
    #include <iostream>	//for console IO
    #include <fstream>	//for file IO
    #include <string>	//for the string class
    using namespace std;
    
    struct mainStruct		//this holds our data
    {
    	string name;	//it contains a name
    	string time;	//and a time
    };
    struct teamStruct		//this holds our data
    {
      	string team;	//it contains a name
    };
    
    void ReadMainData(mainStruct& mouse);	//read in the data
    void ReadTeamData(teamStruct& cat);		//read in the data
    void ShuffleExchangeSort();				//sorts the information
    
    int number;
    const int Size=50;
    
    
    int main()
    {	
    	//std::ofstream out;	//you never used this...
    	mainStruct mouse;	//instantiate a struct
        teamStruct cat;		//instantiate a struct
    	//you do realize that after this runs, you'll be left with the last name
    	//in the data file, right?
    	ReadMainData(mouse);	//you don't specify datatype when calling
    	//cout<<mouse.name;	//output a name
        ReadTeamData(cat);
    	
    	return 0; 
    }
    
    void ReadMainData(mainStruct& mouse)
    {
    	fstream input("main.run");	//open the file for reading
    	char*line=new char[25];		//create space for a char*
    	
    	while(input.get(line,25))		//take in the 25-char name
    	{
    		mouse.name.assign(line);	//assign the name to the string in the struct
        	input>>mouse.time;		//take in and assign the time to the struct
    		input.ignore(32000,'\n');	//ignore up to the next newline
            cout<<mouse.name<<" "<<mouse.time<<endl;
      	}
    
    	input.close();				//close the input file
    	delete[]line;				//free the memory from the char*
      	cout<<mouse.time << endl;	//ouptut the time (consider relocating this)
    }
    
    void ReadTeamData(teamStruct& cat)
    {
      	fstream input("teams.dat");	//open the file for reading
        char*line=new char[31];		//create space for a char*
        
    	while(input.get(line,31))		//take in the 31-char name
        {
          cat.team.assign(line);	//assign the name to the string in the struct
          		getline(input,cat.team,' ');	//take in and assign the team name to the struct
          input.ignore(32000,'/n');	//ignore up to the next newline
          cout << cat.team <<endl;
        }
        
    	input.close();					//close the input file
        delete[]line;					//free the memory from the char*
        cout<<cat.team<<endl;			//output the team
    }
    
    void Swap(mainStruct mouse[Size], int Rec1, int Rec2 )
    {
    mainStruct Temp;
    
    Temp = List[Rec1];
    List[Rec1] = List[Rec2];
    List[Rec2] = Temp;
    }
    
    void ShuffleExchangeSort(mainStruct& mouse)
    {
      	int k;
        int n;
      	bool bvar;					//this variable will be used to indicate if the list is ordered.
        
          	k=0;
            n=100;
          	bvar=true;
            
    	while(k<n-1 && bvar)
        {
          bvar=false;
          k++;
          for(int i=0; i<n-k; i++)
          {
            if(mouse[i].time > mouse[i+1].time)
            {
            swap(mouse,i,i+1);
            bvar=true;
            }
          }
        }
    }
    I am getting these errors though:
    bcc32.exe -v newcode

    Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
    newcode.cpp:
    Error E2451 newcode.cpp 78: Undefined symbol 'List' in function Swap(mainStruct *,int,int)
    Warning W8057 newcode.cpp 81: Parameter 'mouse' is never used in function Swap(mainStruct *,int,int)
    Warning W8057 newcode.cpp 81: Parameter 'Rec1' is never used in function Swap(mainStruct *,int,int)
    Warning W8057 newcode.cpp 81: Parameter 'Rec2' is never used in function Swap(mainStruct *,int,int)
    Error E2094 newcode.cpp 99: 'operator+' not implemented in type 'mainStruct' for arguments of type 'int' in function ShuffleExchangeSort(mainStruct &)
    Error E2094 newcode.cpp 99: 'operator+' not implemented in type 'mainStruct' for arguments of type 'int' in function ShuffleExchangeSort(mainStruct &)
    Error E2285 newcode.cpp 101: Could not find a match for 'swap<charT,traits,Allocator>(mainStruct,int,int)' in function ShuffleExchangeSort(mainStruct &)
    Warning W8057 newcode.cpp 106: Parameter 'mouse' is never used in function ShuffleExchangeSort(mainStruct &)
    *** 4 errors in Compile ***

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21