I need help for opening file and print menu..

This is a discussion on I need help for opening file and print menu.. within the C++ Programming forums, part of the General Programming Boards category; I'm learning c++. But homework is too hard... I could build the body, but I can not build the functions... ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    5

    Question 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

    Code:
    #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;
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,710
    You may want start by studying these links: Functions I and Functions II.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-13-2013, 07:10 PM
  2. Replies: 6
    Last Post: 11-29-2011, 11:49 PM
  3. File opening
    By al_engler in forum C Programming
    Replies: 3
    Last Post: 12-27-2006, 04:46 PM
  4. file opening?
    By ssjnamek in forum C Programming
    Replies: 24
    Last Post: 03-01-2006, 07:15 AM
  5. going about opening a .chm file from a menu item
    By DarkViper in forum Windows Programming
    Replies: 4
    Last Post: 02-20-2004, 03:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21