#include <iostream>
#include <fstream>
#include <string>
using namespace std;
// player node for linkedlist
class Player {
public :
int id;
string name;
string position;
int age;
float salary;
Player* next;
Player( ) : id( 0 ) , name( " " ) , position( " " ) , age( 0 ) , salary( 0.0 ) , next( NULL ) { }
} ;
// player linkedlist
class team {
public :
int rank;
string name;
string president;
Player* head;
team( ) : rank( 0 ) , name( "" ) , president( "" ) , head( NULL ) { }
// function to insert newnode(add new player)
void addPlayer( int id, string name, string position, int age, float salary) {
Player* newPlayer = new Player( ) ;
newPlayer- > id = id;
newPlayer- > name = name;
newPlayer- > position = position;
newPlayer- > age = age;
newPlayer- > salary = salary;
if ( head == NULL ) {
head = newPlayer;
} else {
Player* temp = head;
while ( temp- > next ! = NULL ) {
temp = temp- > next;
}
temp- > next = newPlayer;
}
}
void readTeamFromFile( string fileName) {
ifstream inputFile( fileName) ;
if ( ! inputFile.is_open ( ) ) {
cout << "Unable to open file " << endl;
return ;
}
string line;
while ( getline( inputFile, line) ) {
// Find positions of commas
/*19,nada mohamed
pos1 -> 1->9->, =2;
pos2->1->9->,->n->a->d->a->space->m->o->h->a->m->e->d->,=15
*/
size_t pos1 = line.find ( "," ) ;
size_t pos2 = line.find ( "," , pos1 + 1 ) ;
size_t pos3 = line.find ( "," , pos2 + 1 ) ;
size_t pos4 = line.find ( "," , pos3 + 1 ) ;
// Extract data from the line
/*pos1+1 skip first comma 19|,n/ada
pos1=| & pos1+1=/ , pos2-pos1 find space between tow comma & -1 without second comma*/
int id = stoi( line.substr ( 0 , pos1) ) ; //stoi convert string into int num
string name = line.substr ( pos1 + 1 , pos2 - pos1 - 1 ) ;
string position = line.substr ( pos2 + 1 , pos3 - pos2 - 1 ) ;
int age = stoi( line.substr ( pos3 + 1 , pos4 - pos3 - 1 ) ) ;
float salary = stof( line.substr ( pos4 + 1 ) ) ;
// Add the player to the linked list
addPlayer( id, name, position, age, salary) ;
}
inputFile.close ( ) ;
}
void displayPlayers( ) {
Player* temp = head;
if ( temp== NULL ) {
cout << "No players in the team." << endl;
return ;
}
while ( temp) {
cout << temp- > id << "," << temp- > name<< "," << temp- > position << "," << temp- > age << "," << temp- > salary << endl;
temp = temp- > next;
}
}
} ;
int main( ) {
team team1, team2, team3, team4, team5, team6, team7, team8, team9;
// Read and display data for each team manually without using a loop
cout << "Team 1 (El Bank Al-ahly):******" << endl;
team1.readTeamFromFile ( "El Bank Al-ahly.txt" ) ;
team1.displayPlayers ( ) ;
cout << "Team 2 (Elgouna):*******" << endl;
team2.readTeamFromFile ( "Elgouna.txt" ) ;
team2.displayPlayers ( ) ;
cout << "Team 3 (Enppi):******" << endl;
team3.readTeamFromFile ( "Enppi.txt" ) ;
team3.displayPlayers ( ) ;
cout << "Team 4 (Ghazl elmahala):*****" << endl;
team4.readTeamFromFile ( "Ghazl elmahala.txt" ) ;
team4.displayPlayers ( ) ;
cout << "Team 5 (Haraas elhodod):******" << endl;
team5.readTeamFromFile ( "Haraas elhodod.txt" ) ;
team5.displayPlayers ( ) ;
cout << "Team 6 (ismaaily):*******" << endl;
team6.readTeamFromFile ( "ismaaily.txt" ) ;
team6.displayPlayers ( ) ;
cout << "Team 7 (Modern):********" << endl;
team7.readTeamFromFile ( "Modern.txt" ) ;
team7.displayPlayers ( ) ;
cout << "Team 8 (pharco):**********" << endl;
team8.readTeamFromFile ( "pharco.txt" ) ;
team8.displayPlayers ( ) ;
cout << "Team 9 (ZED):**********" << endl;
team9.readTeamFromFile ( "ZED.txt" ) ;
team9.displayPlayers ( ) ;
return 0 ;
}
ICNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxzdHJpbmc+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Ci8vIHBsYXllciBub2RlIGZvciBsaW5rZWRsaXN0CmNsYXNzIFBsYXllciB7CnB1YmxpYzoKICAgIGludCBpZDsKICAgIHN0cmluZyBuYW1lOwogICAgc3RyaW5nIHBvc2l0aW9uOwogICAgaW50IGFnZTsKICAgIC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QogICAgICAgICAgICB0ZW1wLT5uZXh0ID0gbmV3UGxheWVyOwogICAgICAgIH0KICAgIH0KCiAgICB2b2lkIHJlYWRUZWFtRnJvbUZpbGUoIHN0cmluZyBmaWxlTmFtZSkgewogICAgICAgIGlmc3RyZWFtIGlucHV0RmlsZShmaWxlTmFtZSk7CgogICAgICAgIGlmICghaW5wdXRGaWxlLmlzX29wZW4oKSkgewogICAgICAgICAgICBjb3V0IDw8ICJVbmFibGUgdG8gb3BlbiBmaWxlICI8PCBlbmRsOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfQoKICAgICAgICBzdHJpbmcgbGluZTsKICAgICAgICB3aGlsZSAoZ2V0bGluZShpbnB1dEZpbGUsIGxpbmUpKSB7CiAgICAgICAgICAgIC8vIEZpbmQgcG9zaXRpb25zIG9mIGNvbW1hcwogICAgICAgICAgICAvKjE5LG5hZGEgbW9oYW1lZAogICAgICAgICAgICBwb3MxIC0+IDEtPjktPiwgPTI7CiAgICAgICAgICAgIHBvczItPjEtPjktPiwtPm4tPmEtPmQtPmEtPnNwYWNlLT5tLT5vLT5oLT5hLT5tLT5lLT5kLT4sPTE1CiAgICAgICAgICAgICovCiAgICAgICAgICAgIHNpemVfdCBwb3MxID0gbGluZS5maW5kKCIsIik7CiAgICAgICAgICAgIHNpemVfdCBwb3MyID0gbGluZS5maW5kKCIsIiwgcG9zMSArIDEpOwogICAgICAgICAgICBzaXplX3QgcG9zMyA9IGxpbmUuZmluZCgiLCIsIHBvczIgKyAxKTsKICAgICAgICAgICBzaXplX3QgcG9zNCA9IGxpbmUuZmluZCgiLCIsIHBvczMgKyAxKTsKICAgICAgICAgICAgLy8gRXh0cmFjdCBkYXRhIGZyb20gdGhlIGxpbmUKICAgICAgICAgICAgIC8qcG9zMSsxIHNraXAgZmlyc3QgY29tbWEgMTl8LG4vYWRhCiAgICAgICAgICAgIHBvczE9fCAmIHBvczErMT0vICwgcG9zMi1wb3MxIGZpbmQgc3BhY2UgYmV0d2VlbiB0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