c++ using structures and arrays in files help

help im stuck i want to get everything starting from the second place as the question says

Description:

After Dubai organized its first International Marathon, the organizing committee provided you with
a text file containing information on athletes’ performance during this competition. Each line in this
text file has the following information on a single athlete: first name (one word), last name (one
word), number, citizenship, and the time they took to finish the race. For example, the line:
Peter Gabrielle 3252 Kenya 127
refers to the athlete Peter Gabrielle, having the number 3252, from Kenya, and terminated the race
in 127 minutes.
The organizing committee is asking you to develop a C/C++ program that offers the following
features, from which, the user can select:
 The number of athletes who completed the race
 The athlete who won the first position
 The athlete who won the second position
Notes
 Assignments are individual works
 Teamwork not allowed
 If you reuse material from other sources (internet, books, papers…), you have to
cite appropriate sources.  The athlete who won the third position
 Which citizenship has the maximum number of athletes?
 Write all the above information into a text file.
Your program should provide the user with a menu from which the user can repeatedly select an
option. If the user presses ‘Q’ or ‘q’, the program terminates.

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

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>

using namespace std;

//Structure of athlete
struct athlete
{
       char f_name[10];
       char l_name[10];
       int jersey_num;
       char country[50];
       double seconds;
};

//Function to get the athletes from the file
int get_ath(athlete & A)
{
    ifstream thefile("ath.txt");
    int i=0;
    
    cout << endl;
    cout << endl;
    while(thefile >> A.f_name >> A.l_name >> A.jersey_num >> A.country >> A.seconds)
    {
                  cout << A.f_name << "  " << A.l_name << "  " << A.jersey_num << "  " << A.country << "  " << A.seconds << endl;
    }
    
    thefile.close();
}

//Function to get the 1st place
int first(athlete & A)
{
    ifstream theFile("ath.txt");
    double min = 10.0;
    int i=0;
    
    while(!theFile.eof())
    {
                         if(A.seconds < min)
                         {
                                min = A.seconds;
                         }
                         
                         cout << A.f_name << "  " << A.l_name << "  " << A.jersey_num << "  " << A.country << "  " << min << endl;
                         return 1;
                         i++;
    }
    
    theFile.close();
}

//Function to get 2nd place
int second(athlete & A)
{
    ifstream theFile("ath.txt");
    double min = 10.0 ;
    int i=0;
    
    while(!theFile.eof())
    {
                         if((A.seconds < 8)&&(A.seconds > 6))
                         {
                                min = A.seconds;
                         }
                         
                         cout << min << endl;
                         return 1;
    }
    
    theFile.close();
}

//-----------------------------------------        
int main()
{
    char con;
    do{
          athlete A;
          
          cout << "This is what is in the file : ";
          get_ath(A);
    
          int opt;
    
          cout << endl;
          cout << " Press 1 - The number of athletes who completed the race " << endl; 
          cout << " Press 2 - The athlete who won the first position " << endl; 
          cout << " Press 3 - The athlete who won the second position " << endl;
          cout << " Press 4 - The athlete who won the third position " << endl; 
          cout << " Press 5 - Which citizenship has the maximum number of athletes? " << endl;
          cout << " Press 6 - Write all the above information into a text file. " << endl;
    
          cout << endl;
          cout << "Please enter your option : ";
          cin >> opt;
    
          switch (opt)
          {
                 case 1: cout << "The number of athletes are 5! " << endl;
                 break;
                 case 2: first(A); 
                 break;
                 case 3: second(A);
                 break;
                 //case 4: get_third_place();
                 //break;
                // case 5: most_citizens(country , n);
                 //break;
                 //case 6:
                 //break;
          }
    
          cout << endl;
          cout << "Do you want to continue : ";
          cin >> con;
    
    }while(con == 'q' || con == 'Q');
    
    system ("PAUSE");
}
Topic archived. No new replies allowed.