Code:
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cmath>
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;
initInfo info;
pac10 infoPac10;
big10 infoBig10;
int option;
int i, p;
int j = 0;
pac10 array[5000];
string nfl[32];
nfl [0] = "Baltimore Ravens";
nfl [1] = "Buffalo Bills";
nfl [2] = "Cincinnati Bengals";
nfl [3] = "Cleveland Browns";
nfl [4] = "Denver Broncos";
nfl [5] = "Houston Texans";
nfl [6] = "Indianapolis Colts";
nfl [7] = "Jacksonville Jaguars";
nfl [8] = "Kansas City Chiefs";
nfl [9] = "Miami Dolphins";
nfl [10] = "New England Patriots";
nfl [11] = "New York Jets";
nfl [12] = "Oakland Raiders";
nfl [13] = "Pittsburgh Steelers";
nfl [14] = "San Diego Chargers";
nfl [15] = "Tennessee Titans";
nfl [16] = "Arizona Cardinals";
nfl [17] = "Atlanta Falcons";
nfl [18] = "Carolina Panthers";
nfl [19] = "Chicago Bears";
nfl [20] = "Dallas Cowboys";
nfl [21] = "Detroit Lions";
nfl [22] = "Green Bay Packers";
nfl [23] = "Minnesota Vikings";
nfl [24] = "New Orleans Saints";
nfl [25] = "New York Giants";
nfl [26] = "Philadelphia Eagles";
nfl [27] = "San Francisco 49ers";
nfl [28] = "Seattle Seahawks";
nfl [29] = "St. Louis Rams";
nfl [30] = "Tampa Bay Buccaneers";
nfl [31] = "Washington Redskins";
string pac10[10];
pac10 [0] = "Arizona";
pac10 [1] = "Arizona State";
pac10 [2] = "California";
pac10 [3] = "Oregon";
pac10 [4] = "Oregon State";
pac10 [5] = "Southern California";
pac10 [6] = "Stanford";
pac10 [7] = "UCLA";
pac10 [8] = "Washington";
pac10 [9] = "Washington State";
string big10[11];
big10 [0] = "Illinois";
big10 [1] = "Indiana";
big10 [2] = "Iowa";
big10 [3] = "Michigan";
big10 [4] = "Michigan State";
big10 [5] = "Minnesota";
big10 [6] = "Northwestern";
big10 [7] = "Ohio State";
big10 [8] = "Penn State";
big10 [9] = "Purdue";
big10 [10] = "Wisconsin";
playersFile.open("players.txt");
if (playersFile.fail())
{
cout<<"An error occured while trying to open the file."<<endl;
system ("PAUSE");
exit (1);
}
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);
for (int n=0; n<10; n++)
{
if (pac10[n]==info.college)
file_op<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
for (int z=0; z<10; z++)
{
if (big10[z]==info.college)
file_op1<<info.firstName<<","<<info.lastName<<","<<info.yearsExp<<","<<info.college<<","<<info.nflTeam<<endl;
}
}
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..."<<endl;
cout<<"Try it again... Enter an option between 1 and 7: ";
cin>>option;
}
while (option < 1)
{
cout<<"There is no option lower than 1..."<<endl;
cout<<"Try it again... Enter an option between 1 and 7: "<<endl;
cin>>option;
}
if (option == 1)
{
cout<<"Baltimore Ravens percentage is: "<<(23.0/84)*100<<"%"<<endl;
cout<<"Buffalo Bills percentage is: "<<(19.0/72)*100<<"%"<<endl;
cout<<"Cincinnati Bengals percentage is: "<<(22.0/80)*100<<"%"<<endl;
cout<<"Cleveland Browns percentage is: "<<(25.0/87)*100<<"%"<<endl;
cout<<"Denver Broncos percentage is: "<<(34.0/87)*100<<"%"<<endl;
cout<<"Houston Texans percentage is: "<<(30.0/90)*100<<"%"<<endl;
cout<<"Indianapolis Colts percentage is: "<<(16.0/87)*100<<"%"<<endl;
cout<<"Jacksonville Jaguars percentage is: "<<(31.0/86)*100<<"%"<<endl;
cout<<"Kansas City Chiefs percentage is: "<<(34.0/85)*100<<"%"<<endl;
cout<<"Miami Dolphins percentage is: "<<(33.0/89)*100<<"%"<<endl;
cout<<"New England Patriots percentage is: "<<(29.0/83)*100<<"%"<<endl;
cout<<"New York Jets percentage is: "<<(22.0/80)*100<<"%"<<endl;
cout<<"Oakland Raiders percentage is: "<<(26.0/85)*100<<"%"<<endl;
cout<<"Pittsburgh Steelers percentage is: "<<(30.0/82)*100<<"%"<<endl;
cout<<"San Diego Chargers percentage is: "<<(16.0/87)*100<<"%"<<endl;
cout<<"Tennessee Titans percentage is: "<<(11.0/82)*100<<"%"<<endl;
cout<<"Arizona Cardinals percentage is: "<<(26.0/76)*100<<"%"<<endl;
cout<<"Atlanta Falcons percentage is: "<<(30.0/86)*100<<"%"<<endl;
cout<<"Carolina Panthers percentage is: "<<(27.0/86)*100<<"%"<<endl;
cout<<"Chicago Bears percentage is: "<<(23.0/86)*100<<"%"<<endl;
cout<<"Dallas Cowboys percentage is: "<<(21.0/74)*100<<"%"<<endl;
cout<<"Detroit Lions percentage is: "<<(28.0/85)*100<<"%"<<endl;
cout<<"Green Bay Packers percentage is: "<<(21.0/81)*100<<"%"<<endl;
cout<<"Minnesota Vikings percentage is: "<<(25.0/83)*100<<"%"<<endl;
cout<<"New Orleans Saints percentage is: "<<(36.0/86)*100<<"%"<<endl;
cout<<"New York Giants percentage is: "<<(24.0/85)*100<<"%"<<endl;
cout<<"Philadelphia Eagles percentage is: "<<(23.0/86)*100<<"%"<<endl;
cout<<"San Francisco 49ers percentage is: "<<(20.0/83)*100<<"%"<<endl;
cout<<"Seattle Seahawks percentage is: "<<(25.0/87)*100<<"%"<<endl;
cout<<"St. Louis Rams percentage is: "<<(27.0/80)*100<<"%"<<endl;
cout<<"Tampa Bay Buccaneers percentage is: "<<(27.0/89)*100<<"%"<<endl;
cout<<"Washington Redskins percentage is: "<<(29.0/84)*100<<"%"<<endl;
}
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 == 3)
{
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);
for (int t=0; t<3500; t++)
{
array[t] = infoPac10;
}
}
int w, e;
pac10 temp;
for (w=1; w<3499; w++)
{
for(e = (w+1); e<3500; e++)
{
if (array[w].college<array[e].college)
{
temp.college = array[e].college;
array[e].college = array [w].college;
array [w].college = temp.college;
}
}
}
file_op.close();
}
if (option == 4)
{
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);
p = atoi(infoPac10.yearsExp);
if (p >= 5)
{
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();
}
if (option == 7)
{
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);
p = atoi(infoBig10.yearsExp);
if (p > 5)
{
cout<<infoBig10.firstName<<infoBig10.lastName<<", "<<infoBig10.yearsExp<<", "<<infoBig10.college<<endl;
}
}
file_op1.close();
}
return 0;
}