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 ***