Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 14th, 2005, 01:45 PM
Authorized User
 
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Programming assignment.

Thank youall for helping. Assignment complete.
Reply With Quote
  #2 (permalink)  
Old December 14th, 2005, 02:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Nicolas, A few minutes ago another student, presumably, from your class only,
posted the same query, presenting it differenly.
This is the link to that post

http://p2p.wrox.com/topic.asp?TOPIC_ID=37617

May be, you two can help each other out.

Regards
Ankur Verma
Reply With Quote
  #3 (permalink)  
Old December 14th, 2005, 07:59 PM
Registered User
 
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes but we both need help on this, weve tried helping each other with no luck. if anyone can help it would be much appreciated.

Reply With Quote
  #4 (permalink)  
Old December 15th, 2005, 02:56 PM
Authorized User
 
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My collegue and I are having a few problems with mainly the first half of the assignment and must meet deadline soon. Any kind of help would be appreciated... Thank you for viewing... Nicolas.

Reply With Quote
  #5 (permalink)  
Old December 15th, 2005, 03:05 PM
Authorized User
 
Join Date: Nov 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Post ur code where u r having problems

Reply With Quote
  #6 (permalink)  
Old December 15th, 2005, 06:49 PM
Authorized User
 
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem we are having is actually begining the assignment, we are not sure which enumerations or structs we need to apply to it, we have had difficulty understanding them, i will try to post what i have done so far tomorow as i do not have the information on my home P.C.
Thank you...

Reply With Quote
  #7 (permalink)  
Old December 16th, 2005, 10:51 AM
Authorized User
 
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi again,

This is what I have done so far, still have a long way to go, but its a start, irequire any help possible... thank you.


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

const int ACC_MAX = 5000 ;

enum MemberType { Annual, Quarterly = 12} ;

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

struct Book
{
  string Author;
  string Title;
};

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 Library_member
{
    Name name;
    Address address;
    MemberType member;
    Date date;
};


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

void read_clients()
{
    ifstream clientfile( "clients.dat" ) ;

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

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

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

        nMember = nRead + 1; //identifies the record number

        if ( clientfile )
        {
            cout << nMember << " "
                    << 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 << "\n";
    cout << nRead << " accounts read\n" ;

    clientfile.close() ;
};

void add_new_clients()
{
    ofstream clientfile( "clients.dat", ios::app ) ;

    Library_member member;
    int nRead = 0 ;
    //string text;
    string delimiter = "\t";
    //int nMember;
    int MembershipNo;

    cout << "Input new data client:\n\n";

    cout << "First Name: ";
    cin >> member.name.first_name;

    cout << "Surname: ";
    cin >> member.name.surname;

    cout << "House Number: ";
    cin >> member.address.house_no;

    cout << "Street Name: ";
    cin >> member.address.streetname;

    cout << "Street Type: ";
    cin >> member.address.streettype;

    cout << "Town: ";
    cin >> member.address.town;

    cout << "Member(0:Annual/12:Quarterly): ";
    cin >> MembershipNo; //i use MembershipNo instead of member.member

    cout << "Day: ";
    cin >> member.date.day;

    cout << "Month: ";
    cin >> member.date.month;

    cout << "Year: ";
    cin >> member.date.year;

    // append new data in clients.dat
    clientfile << member.name.first_name << delimiter
                    << member.name.surname << delimiter
                    << member.address.house_no << delimiter
                    << member.address.streetname << delimiter
                    << member.address.streettype << delimiter
                    << member.address.town << delimiter
                    << MembershipNo << delimiter
                    << member.date.day << delimiter
                    << member.date.month << delimiter
                    << member.date.year;

   clientfile.close() ;
};

void search_clients()
{
    Library_member member[ACC_MAX] ;
    int nRead = 0 ;
    int nFound = 0 ;
    int nMember;
    int MembershipNo;
    string name;

    cout << "Input client's first name or client's surname: ";
    cin >> name;

    cout << "\n";

    ifstream clientfile( "clients.dat" ) ;

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

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

        nMember = nRead + 1; //identifies the record number

        if ( clientfile )
        {
            if ( name == member[nRead].name.first_name || name == member[nRead].name.surname)
            {
                cout << nMember << " "
                        << 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";
                nFound++;
            }
            nRead++ ;
        }
    } while ( clientfile && nRead < ACC_MAX ) ;

    cout << "\n";
    cout << nFound << " records found\n" ;

    clientfile.close() ;
};

void search_book()

{
  struct books_t;
{
  string title;
  int year;
}

 int main ()
{
  string mystr;

  books_t abook;
  books_t * pbook;
  pbook = &abook;

  cout << "Enter title: ";
  getline (cin, pbook->title);
  cout << "Enter ISBN: ";
  getline (cin, mystr);
  (stringstream) mystr >> pbook->year;

  cout << "\nYou have entered:\n";
  cout << pbook->title;
  cout << " (" << pbook->year << ")\n";

  return 0;
}
}

int main()
{
    int menu_selection;

    cout << "\n"
            << "================================================= ===============\n"
            << " Welcome to The public library system\n"
            << " Bellow is the main menu for the library filing system\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 details\n"
        << "Select 4: To search for a Book\n"
            << "Select 5: Exit this program\n\n";


    cin >> menu_selection;

    switch (menu_selection)
    {
    case 1:
        cout << "\n";
        read_clients();
        cout << "\n";
        main();
        break;
    case 2:
        cout << "\n";
        add_new_clients();
        cout << "\n";
        main();
        break;
    case 3:
        cout << "\n";
        search_clients();
        cout << "\n";
        main();
        break;
    case 4:
      cout << "\n";
      search_book();
      cout << "\n";
      main();
      break;
    case 5:
        break;
    }
}

any help would be appreciated, i still have to perform a search for a list of users i have been given and list a number of books they have rented out and other parts included in the assignment instructions above.

Any help would be much appreciated, thanks for your help...
Nicolas


Reply With Quote
  #8 (permalink)  
Old December 16th, 2005, 12:19 PM
Authorized User
 
Join Date: Nov 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Replace C headers with C++ one's
Code:
C headers                   C++ headers
-------------------------------------------
#include <assert.h>         #include <cassert>
#include <stdlib.h>         #include <cstdlib>
#include <time.h>           #include <ctime>
why in this world are u using two main() in the code
Reply With Quote
  #9 (permalink)  
Old December 16th, 2005, 12:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Nicolas, Quite a progress since your last post, I must say!!
It’s a “Programmer to Programmer” forum but at this point I don’t see any problem chipping in helping you out.

Looking at the code, however, I can say the program has a few problems
and must not be compiling error free.
1 Remove one of the two definitions of main, the first one is not making much sense
2 extra curly braces lying about like the one in search_book function.

For searching you need to structure your storage to make it more manageable.
One of the ways is to index the users and books entries based on their IDs an ISBNs respectively.
U can leave the user storage file and book storage files pretty much the way they are with a little change here there may be. Just make an index file atop for each of them and your searching problem will be solved. This design is clean, resource friendly, gives good performance and highly scalable.

Other way would be to go with the current design only, and load the whole file in some data structure and perform the search in that data structure only. Once the file is loaded, the program would perform reasonably well (based on the configuration of the comp, off course) but will take time to load itself. Not a clean design, scalability –not an issue, but is resource hungry.

And yes, your classmate can use some help, so help him.

Regards
Ankur Verma
Reply With Quote
  #10 (permalink)  
Old December 16th, 2005, 12:48 PM
Authorized User
 
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the tip, ive applied it to my program, but i also have to many compilation errors in which i am having trouble fixing, also I am having trouble completing the program as i do not know how to complete it.
Thanks for yuur advice and help...
Nicolas

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
please help me out with this assignment... vaidehi BOOK: Beginning Linux Programming, 4th Edition ISBN 978-0-470-14762-7 3 September 10th, 2008 03:57 PM
Illegal Assignment Broodmdh Classic ASP Basics 2 August 22nd, 2008 06:21 AM
assignment pooja85jain SQL Language 1 September 2nd, 2006 11:09 AM
Java assignment greeny Java Basics 0 November 29th, 2005 08:29 AM
Java assignment greeny JSP Basics 0 November 29th, 2005 08:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.