Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct initInfo
{
char number [5];
char lastName [20];
char firstName [20];
char position [5];
char yearsExp [5];
char college [20];
char nflTeam [30];
};
struct pac10
{
char firstName [20];
char lastName [20];
char yearsExp [5];
char college [30];
char nflTeam [50];
};
struct big10
{
char firstName [20];
char lastName [20];
char yearsExp [5];
char college [30];
char nflTeam [50];
};
int main()
{
fstream file_op("pac10.txt", ios::out);
fstream file_op1("big10.txt", ios::out);
ifstream playersFile;;
char *stopString;
initInfo info;
pac10 infoPac10;
big10 infoBig10;
int option;
int i;
int j = 0;
char pac101 [] = "Arizona";
char pac102 [] = "Arizona State";
char pac103 [] = "California";
char pac104 [] = "Oregon";
char pac105 [] = "Oregon State";
char pac106 [] = "Southern California";
char pac107 [] = "Stanford";
char pac108 [] = "UCLA";
char pac109 [] = "Washington";
char pac1010 [] = "Washington State";
char big101 [] = "Illinois";
char big102 [] = "Indiana";
char big103 [] = "Iowa";
char big104 [] = "Michigan";
char big105 [] = "Michigan State";
char big106 [] = "Minnesota";
char big107 [] = "Northwestern";
char big108 [] = "Ohio State";
char big109 [] = "Penn State";
char big1010 [] = "Purdue";
char big1011 [] = "Wisconsin";
playersFile.open("players.txt");
if (playersFile.fail())
{
cout<<"An error occured while trying to open the file."<<endl;
system ("PAUSE");
exit (1);
}
cout<<"File opened"<<endl;
while (!playersFile.eof())
{
playersFile.getline(info.number, 11, ',');
playersFile.getline(info.lastName, 20, ',');
playersFile.getline(info.firstName, 20, ',');
playersFile.getline(info.position, 20, ',');
playersFile.getline(info.yearsExp, 5, ',');
playersFile.getline(info.college, 50, ',');
playersFile.getline(info.nflTeam, 40);
/*
cout<<"number is: "<<info.number<<endl;
cout<<"last name is: "<<info.lastName<<endl;
cout<<"first name is: "<<info.firstName<<endl;
cout<<"position is: "<<info.position<<endl;
cout<<"years exp: "<<info.yearsExp<<endl;
cout<<"college is: "<<info.college<<endl;
cout<<"nfl is: "<<info.nflTeam<<endl;
*/
//compares for PAC10 colleges, if they go to a pac10 school, writes to a file
if (strcmp(pac101, info.college)==0)
{
file_op<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(pac102, info.college) == 0)
{
file_op<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(pac103, info.college) == 0)
{
file_op<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(pac104, info.college) == 0)
{
file_op<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(pac105, info.college) == 0)
{
file_op<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(pac106, info.college) == 0)
{
file_op<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(pac107, info.college) == 0)
{
file_op<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(pac108, info.college) == 0)
{
file_op<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(pac109, info.college) == 0)
{
file_op<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(pac1010, info.college) == 0)
{
file_op<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
//compares for big10 colleges, if they go to a big10 school, writes info down to a file
if (strcmp(big101, info.college) == 0)
{
file_op1<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(big102, info.college) == 0)
{
file_op1<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(big103, info.college) == 0)
{
file_op1<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(big104, info.college) == 0)
{
file_op1<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(big105, info.college) == 0)
{
file_op1<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(big106, info.college) == 0)
{
file_op1<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(big107, info.college) == 0)
{
file_op1<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(big108, info.college) == 0)
{
file_op1<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(big109, info.college) == 0)
{
file_op1<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(big1010, info.college) == 0)
{
file_op1<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
if (strcmp(big1011, info.college) == 0)
{
file_op1<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
i = strtol(info.yearsExp, &stopString, 10);
if (i >= 5)
{
j++;
}
}
playersFile.close();
file_op.close();
file_op1.close();
cout<<"Enter an option number between 1 and 7: ";
cin>>option;
while (option > 7)
{
cout<<"Option must be lower than 7 dumbass...";
cout<<"Try it again... Enter an option between 1 and 7: ";
cin>>option;
}
while (option < 1)
{
cout<<"There is no option lower than 0 dumbass..."<<endl;
cout<<"Try it again... Enter an option between 1 and 7: "<<endl;
cin>>option;
}
if (option = 2)
{
file_op.open("pac10.txt");
while (!file_op.eof())
{
file_op.getline(infoPac10.firstName, 50, ',');
file_op.getline(infoPac10.lastName, 50, ',');
file_op.getline(infoPac10.yearsExp, 10, ',');
file_op.getline(infoPac10.college, 50, ',');
file_op.getline(infoPac10.nflTeam, 50);
cout<<infoPac10.firstName<<infoPac10.lastName<<", "<<infoPac10.yearsExp<<", "<<infoPac10.college<<endl;
}
file_op.close();
}
if (option = 5)
{
file_op1.open("big10.txt");
while (!file_op1.eof())
{
file_op1.getline(infoBig10.firstName, 50, ',');
file_op1.getline(infoBig10.lastName, 50, ',');
file_op1.getline(infoBig10.yearsExp, 10, ',');
file_op1.getline(infoBig10.college, 50, ',');
file_op1.getline(infoBig10.nflTeam, 50);
cout<<infoBig10.firstName<<infoBig10.lastName<<", "<<infoBig10.yearsExp<<", "<<infoBig10.college<<endl;
}
file_op1.close();
}
cout<<"Number of players with 5 more years of exp. are: "<<j<<endl;
return 0;
}