ok... is it okay if i you help me expand my knowledge even more?
take a different example...
say i got a file of swimmers
e.g.
M
100 Free
50.24
Ian Thorpe
10/12/1960
10/02/2005
Wagga Wagga
1
M
100 Free
51.01
Grant Hackett
20/07/69
12/03/2005
Melbourne
2
M
100 Free
52.00
John Konrads
22/10/1970
14/04/2005
Adelaide
3
where the lines read
Sex M
Event eg 100 Free
Performance 50.24
Name Ian Thorpe
Date of birth 10/12/1960
Data of competition 10/2/2005
Venue Wagga Wagga
Position 1
lets make it interesting and say... we can put those files into a struct ...
e.g.
#include <iomanip>
#include <fstream>
#include <iostream>
using namespace std;
int main(){
fstream fs;
int const MAX = 11;
struct swim
{
char sex[2];
char eventtype[20];
char perf[20];
char name[20];
char dob[11];
char doc[11];
char venue[20];
char position[2];
};
swim record[MAX];
int count=0;
fs.open("c:\\swimmers.txt", ios::in);
if(fs.fail()) return 2;
while (!fs.eof() && count < MAX)
{
fs.getline(record[count].sex,2,'\n');
for(int i=0; i<1;i++)
fs.getline(record[count].eventtype,20,'\n');
for(int i=0; i<1;i++)
fs.getline(record[count].perf,20,'\n');
for(int i=0; i<1;i++)
fs.getline(record[count].name,21,'\n');
for(int i=0; i<1;i++)
fs.getline(record[count].doc,11,'\n');
for(int i=0; i<1;i++)
fs.getline(record[count].dob,11,'\n');
for(int i=0; i<1;i++)
fs.getline(record[count].venue,21,'\n');
for(int i=0; i<1;i++)
fs.getline(record[count].position,2,'\n');
for(int i=0; i<1;i++)
cout << record[count].sex << "\n";
cout << record[count].eventtype << "\n";
cout << record[count].perf << "\n";
cout << record[count].name << "\n";
cout << record[count].doc << "\n";
cout << record[count].dob << "\n";
cout << record[count].venue << "\n";
cout << record[count].position << "\n";
count++;
fs.close();
cout << record[6].name;
system("pause");
return 0;
}
<< moderator edit: added
code tags: [code][/code] >>
and i wanna make classes BASED on the events e.g.
Men or women denoted by M or W.The events are 100m Free, 200m Back, 400m Medley, 800m Back, 1500m Free.
therefore in total 10 classes...
and inside those classes i got a struct of each swimmer with the apprioate event
i was thinking something along the lines of
struct athlete{
name
performance
dob
doc
venue
position
}
struct record{
sex
event
name
performance
dob
doc
venue
position
}
const int MAXSIZE = 10;
class rank
{
string sex, event;
athlete data[maxsize];
int total;
public
rank (string &s, string &e);
string getsex();
string getevent();
int gettotal();
althelete 7getdata(int i );
void sort();
void add();
void replace(int, athlete&);
void remove(int position);
friend ostream &operator<<(ostream&, const rank&):
void save(ostream&);
};
so a user is prompted with an option of selecting 1) to select the event of the class.... e.g. 100 free male
when selected given the option to edit it
therefore when an event is selected in option 1 the appropriate object should be selected. Option 2 will involve searching the list of swimmers names in the object
whats a good way of approching this??
i was thinking develop a class and functions similar to the above...
with the apprioprate structs....
am i on the right track? any thoughts?