I need help for opening file and print menu..

I'm learning c++. But homework is too hard...
I could build the body, but I can not build the functions...
It's about opening text file that has information about girl's name, height, weight, age.
I coded.. but I don't know how to create functions...
PLZ help with beautiful comment!!


<text file> - contents of txt file...!
Andy 167 47 22
Sindy 168 51 21
Kim 170 50 23
Suuny 159 45 23
Jessica 163 45 23
Tifany 163 50 23
Lyn 162 45 23
May 167 47 23
Elle 160 46 23

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
#include <iostream>
#include <fstream>
using namespace std;
struct PERSON{
 char name[10];
 int height;
 int weight;
 int age;
 PERSON *next;
 };
void InputPerson(PERSON &p_sPerson);
void PrintPerson();
void swap(PERSON *x, PERSON *y);
void SortByHeight();
void SortByWeight();
void SortByAge();
PERSON *head;
int main()
{
 ifstream file;
 PERSON data;
 char buf[20];
 int menu;
 file.open("girls generation.txt");
 //read file
 while(!file.eof())
 {
  file >> buf;
  strcpy(data.naem, buf);
  file >> buf;
  data.height = atoi(buf);
  file >> buf;
  data.weight = atoi(buf);
  file >> buf;
  data.age = atoi(buf);
  data.next=NULL;
  //data load
  InputPerson(data);
 }
 file.close();
 //print data
 PrintPerson();
 while(true)
 {
  //menu
  cout << "1. print order of height\n";
  cout << "2. print order of weight\n";
  cout << "3. print order of age\n";
  cout << "4. finish the program\n";
  cin >> menu;
  if(menu == 4)
  {
   case 1:
    SortByHeight();
    PrintPerson();
    break;
   case 2:
    SortByWeight();
    PrintPerson();
    break;
   case 3:
    SortByAge();
    PrintPerson();
    break;
   default:
    cout <<"You choose wrong number\n";
    continue;
  }
 }
 return 0;
}

Topic archived. No new replies allowed.