Thread: help needed
View Single Post
  #2 (permalink)  
Old December 18th, 2004, 02:53 PM
grime grime is offline
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Seems like know one is interested in helping me.
I have managed to do the 1st and the second one fro the previous post.
I have saved a file from which the program is ment to read the client details but it only reads 3 of the clients when in the file their are 4 clients saved. pls will someone have a look at my code and try help me solve the tasks. Thanks.

#include <iostream>
#include <fstream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <string>
using namespace std;

const int ACC_MAX = 1000 ;

enum MemberType { Annual, Quarterly } ;

//enum Month { Jan, Feb, Mar, Apr, May, Jun,
// Jul, Aug, Sep, Oct, Nov, Dec } ;

struct Date
{
   int day;
   int month;
   int year;
};

struct Name
{
    string first_name;
    string surname;
};


struct Address
{
    string house_no;
    string streetname;
    string streettype;
    string town;
};

struct GymMember
{
    Name name;
    Address address;
    MemberType member;
    Date date;
};


void process( GymMember a )
{
   switch( a.member )
   {
      case Quarterly:
         a.date.month += 1;
         break ;
      case Annual:
         a.date.year += 1;
         break ;
   }
}

void main1()// int argc, char* argv[] )
{
   // assert( argc >= 2 ) ;
   ifstream clientfile( "clients.dat" ) ;

   GymMember member[ACC_MAX] ;
   int nRead = 0 ;
    string text;
    int nMember;
    int MembershipNo;

    clientfile >> nMember >> text >> text >> text;

   // read data from file and store in the array 'member'
   do
   {
      clientfile >> member[nRead].name.first_name
                    >> member[nRead].name.surname
                    >> member[nRead].address.house_no
                    >> member[nRead].address.streetname
                    >> member[nRead].address.streettype
                    >> member[nRead].address.town
                    >> MembershipNo >> text >> text
                    >> member[nRead].date.day
                    >> member[nRead].date.month
                    >> member[nRead].date.year;

    if ( MembershipNo == 12)
        member[nRead].member = Quarterly;
    else
        member[nRead].member = Annual;

      if ( clientfile )
      {
         cout << member[nRead].name.first_name << " "
                    << member[nRead].name.surname << " "
                    << member[nRead].address.house_no << " "
                    << member[nRead].address.streetname << " "
                    << member[nRead].address.streettype << " "
                    << member[nRead].address.town << " "
                    << member[nRead].member << ". "
                    << member[nRead].date.day << " "
                    << member[nRead].date.month << " "
                    << member[nRead].date.year << " \n";
         nRead++ ;
      }
   } while ( clientfile && nRead < ACC_MAX ) ;

   cout << nRead << " accounts read\n" ;
   // printf("dfdasf");
   clientfile.close() ;


};

void main()// int argc)//, char* argv[] )

{
    int menu_selection;

    cout << "\n"
            << "================================================= ================\n"
            << " Welcome to Joe's Gym filing system\n"
            << " Bellow is the main menu for Joe's filing system\n"
            << " Thank you for choosing Alparsla associates\n"
            << "================================================= ================\n"
            << " \n"
            << " \n"
            << "Select 1: To view current clients\n"
            << "Select 2: To enrol new clients\n"
            << "Select 3: To perform a search through the data for\n"
            << " clients whose membership is about to run out\n"
            << "Select 4: Exit this program\n\n";
    {
        int c;

        while ((c = getchar()) != EOF)
            putchar(c);
    }
{
    /*decalare a pointer*/
    FILE *fp;
    /* open a file and point clients to it */
    fp = fopen(clients,r);
}


    cin >> menu_selection;

    switch (menu_selection)
    {
    case 1:
        cout << "\n";
        clients = fopen(clients,r);
        cout << "\n";
        main();
    case 2:
        break;
    case 3:
        break;
    case 4:
        cout << "Thank you for choosing Alparsla associates\n";
        cout << " \n";
        cout << "This program was written by\n";
        cout << "Samet Alparslan\n";
        //exit(1);
        break;
    }
}
Reply With Quote