1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
//Assignment #8
//Cosimo Vilardo
//Program to maintain a list of the first team squad members of the Italian
//soccer team Juventus and store the info into 5 objects.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int NUMPLAYRS=50;
ifstream infile("Juventus_team.txt");
class personal_info {
public:
string first;
string last;
int age;
};
class player_info {
public:
string position;
int goals;
int assists;
};
class Juventus {
public:
player_info player;
personal_info personal;
};
Juventus team[NUMPLAYRS];
void readdata(Juventus team[], int &n);
void printall(Juventus team[], int n);
void bsort(Juventus team[], int n);
void findlastname(Juventus team[], int n, string lastname);
void printone(int count);
int main()
{
int n=1;
string searched_name;
readdata(team,n);
printall(team,n);
printall(team,n);
cout<<"Please enter the LAST name you will like to find: ";
cin>>searched_name;
findlastname(team, n, searched_name);
infile.close();
system("pause");
return 0;
}
//reads data from .txt file
void readdata(Juventus team[], int &n)
{
if(infile.is_open())
cout<<"opened successfully"<<endl<<endl;
else
cout<<"could not open"<<endl<<endl;
infile>>n;
for(int count; count<n; count++){
infile>>team[count].personal.first;
infile>>team[count].personal.last;
infile>>team[count].personal.age;
infile>>team[count].player.position;
infile>>team[count].player.goals;
infile>>team[count].player.assists;
}
cout<<"-----"<<n<<"-----";
return;
}
//prints all data inputed in function readdata
void printall(Juventus team[], int n)
{
for(int count=0;count<n;count++){
cout<<"First name: "<<team[count].personal.first<<endl;
cout<<"Last name: "<<team[count].personal.last<<endl;
cout<<"Age: "<<team[count].personal.age<<endl;
cout<<"Player Position"<<team[count].player.position<<endl;
cout<<"Goals scored this season: "<<team[count].player.goals<<endl;
cout<<"Jersey #: "<<team[count].player.assists<<endl<<endl;
}
return;
}
//sort
void bsort(Juventus team[], int n)
{
bool swapped = true;
int j = 0, temp, temp5, temp6;
string temp2, temp3, temp4;
while (swapped) {
swapped = false;
j++;
for (int i = 0; i < n - j; i++) {
if(team[i].personal.age>team[i+1].personal.age) {
temp=team[i].personal.age;
temp2=team[i].personal.first;
temp3=team[i].personal.last;
temp4=team[i].player.position;
temp5=team[i].player.goals;
temp6=team[i].player.assists;
team[i].personal.age = team[i+1].personal.age;
team[i].personal.first = team[i+1].personal.first;
team[i].personal.last = team[i+1].personal.last;
team[i].player.position = team[i+1].player.position;
team[i].player.goals = team[i+1].player.goals;
team[i].player.assists = team[i+1].player.assists;
team[i + 1].personal.age=temp;
team[i+1].personal.first = temp2;
team[i+1].personal.last = temp3;
team[i+1].player.position = temp4;
team[i+1].player.goals = temp5;
team[i+1].player.assists = temp6;
swapped = true;
}
}
}
return;
}
//search function
void findlastname(Juventus team[], int n, string lastname)
{
bool found=false;
for(int count=0;count<n;count++){
if(team[count].personal.last==lastname)
printone(count);
else
cout<<"Last name not found"<<endl;
}
return;
}
//printone
void printone(int count){
cout<<team[count].personal.first<<" ";
cout<<team[count].personal.last<<" ";
cout<<team[count].personal.age<<" ";
cout<<team[count].player.position<<" ";
cout<<team[count].player.goals<<" ";
cout<<team[count].player.assists<<endl;
return;
}
|