Urgent Help required

Discussion in 'C++' started by Jinsu Jais, Oct 21, 2006.

  1. Jinsu Jais

    Jinsu Jais Guest

    Dear guys,

    I am a student who had started learning Turbo c++ yet one year. I know
    only the basics of the c++. But now its my turn to make a project in
    our school. So I decided to start a project which doesn't use any
    graphical support in c++. So I prefer a Blood Bank management system.
    But I am not sure that is my project is perfect. So my friends, PLEASE
    HELP ME TO MAKE A PERFECT ERROR-FREE PROJECT. Also advice me some other
    projects with the codes so that I can implement it. I am adding my code
    here.
    NEED AN URGENT REPLY TO : or

    Jinsu M Jais



    // A BLOOD BANK MANAGEMENT SYSTEM

    #include<fstream.h>
    #include<string.h>
    #include<stdlib.h>
    #include<stdio.h>
    #include<conio.h>
    class DONOR
    {
    char name[20];
    char dob[9];
    char address[30];
    int phone_no;
    char blood_gr[4];
    public:
    DONOR()
    {
    phone_no=0;
    }
    void accept();
    void display();
    void save();
    char *return_group();
    };
    char *DONOR::return_group()
    {
    return blood_gr;
    }
    void DONOR::accept()
    {
    clrscr();
    cout<<"\t\t\tDONOR DETAILS";
    cout<<"\nEnter NAME: ";
    gets(name);
    cout<<"\nEnter Address : ";
    gets(address);
    cout<<"\nEnter Date of Birth : ";
    gets(dob);
    cout<<"\nEnter Phone Number : ";
    cin>>phone_no;
    cout<<"\nEnter Blood Group : ";
    gets(blood_gr);
    }
    void DONOR::display()
    {
    clrscr();
    cout<<"\t\t\tDONOR DETAILS";
    cout<<"\nNAME : ";
    puts(name);
    cout<<"\nAddress : ";
    puts(address);
    cout<<"\nDate Of Birth : ";
    puts(dob);
    cout<<"\nPhone Number : "<<phone_no;
    cout<<"\nBlood Group : ";
    puts(blood_gr);
    getch();
    }
    void DONOR::save()
    {
    fstream dfile;
    DONOR DD;
    dfile.open("DONOR.dat",ios::app);
    dfile.write((char *)&DD,sizeof(DD));
    dfile.close();
    }
    class node
    {
    DONOR record;
    public:
    node *next;
    void append();
    void display();
    void save();
    void query(char b_group[40]);
    node()
    {
    next=NULL;
    }
    };
    void node::append()
    {
    record.accept();
    next=NULL;
    }
    void node::display()
    {
    record.display();
    }
    void node::save()
    {
    record.save();
    }
    void node::query(char b_group[40])
    {
    if(strcmp(record.return_group(),b_group)==0)
    display();
    }
    class list
    {
    node *first,*last;
    public:
    list()
    {
    first=NULL;
    last=NULL;
    }
    void append();
    void save(node *ptr);
    void display();
    void query();
    void open();
    };
    void list::save(node *ptr)
    {
    ptr->save();
    }
    void list::append()
    {
    node *ptr;
    ptr=new node;
    ptr->append();
    if(first==NULL)
    first=last=ptr;
    else
    {
    last->next=ptr;
    last=ptr;
    }
    save(ptr);
    }
    void list::display()
    {
    node *ptr;
    ptr=first;
    while(ptr!=NULL)
    {
    ptr->display();
    ptr=ptr->next;
    }
    }
    void list::query()
    {
    clrscr();
    char b_group[4];
    node *ptr;
    cout<<"\t\tDONOR DETAILS";
    cout<<"\nBlood Group : ";
    cin>>b_group;
    for(ptr=first;ptr;ptr=ptr->next)
    ptr->query(b_group);
    }
    void main()
    {
    int ch;
    list LIST;
    do
    {
    clrscr();
    cout<<"\t\t\tDONOR DETAILS";
    cout<<"\n\t1: Append Records";
    cout<<"\n\t2: Display Records";
    cout<<"\n\t3: Query on blood group";
    cout<<"\n\t4: End the program";
    cout<<"\n\nEnter your choice : ";
    cin>>ch;
    switch(ch)
    {
    case 1:
    LIST.append();
    break;
    case 2:
    LIST.display();
    break;
    case 3:
    LIST.query();
    break;
    case 4:
    cout<<"\nEnd of the program";
    getch();
    break;
    }
    }while(ch!=4);
    }
     
    Jinsu Jais, Oct 21, 2006
    #1
    1. Advertising

  2. Jinsu Jais

    StreamKid Guest

    so...

    1) at the beggining, in class DONOR, i guess you want the first part
    (name, dob, address, etc) private, but you haven't written the
    private: keyword anywhere, and they aren't always by default private
    (depends on the compiler). you can change it to:
    class DONOR {
    private:
    char name[20];
    // ...
    public:
    // what you 've already declared as public

    2) although in c its legal to have void main, in c++ int must return
    int.

    there may be more bugs, but i'm not so expirienced either, so i didnt'
    find them..
     
    StreamKid, Oct 21, 2006
    #2
    1. Advertising

  3. Jinsu Jais

    Daniel T. Guest

    In article <>,
    "Jinsu Jais" <> wrote:

    > Dear guys,
    >
    > I am a student who had started learning Turbo c++ yet one year. I know
    > only the basics of the c++. But now its my turn to make a project in
    > our school. So I decided to start a project which doesn't use any
    > graphical support in c++. So I prefer a Blood Bank management system.
    > But I am not sure that is my project is perfect. So my friends, PLEASE
    > HELP ME TO MAKE A PERFECT ERROR-FREE PROJECT. Also advice me some other
    > projects with the codes so that I can implement it. I am adding my code
    > here.
    > NEED AN URGENT REPLY TO : or
    >
    > Jinsu M Jais
    >
    >
    >
    > // A BLOOD BANK MANAGEMENT SYSTEM
    >
    > #include<fstream.h>
    > #include<string.h>
    > #include<stdlib.h>
    > #include<stdio.h>


    The above are the wrong headers for standard C++. They should be:

    #include <fstream>
    #include <string>
    #include <cstdlib>
    #include <cstdio>

    > #include<conio.h>


    The above header doesn't exist in C++

    > class DONOR
    > {
    > char name[20];
    > char dob[9];
    > char address[30];
    > int phone_no;
    > char blood_gr[4];


    Learn about std::string and use it above.

    > public:
    > DONOR()
    > {
    > phone_no=0;
    > }


    Use an initialization list and initialize *all* your variables, not just
    phone_no.

    http://www.parashift.com/c -faq-lite/ctors.html#faq-10.6

    > void accept();
    > void display();
    > void save();
    > char *return_group();


    Probably should return const char*.

    Make sure your functions are const correct in general.

    http://www.parashift.com/c -faq-lite/const-correctness.html

    > };
    > char *DONOR::return_group()
    > {
    > return blood_gr;
    > }


    Make the above "const char*"

    > void DONOR::accept()
    > {
    > clrscr();


    "clrscr" is not standard C++

    > cout<<"\t\t\tDONOR DETAILS";
    > cout<<"\nEnter NAME: ";
    > gets(name);
    > cout<<"\nEnter Address : ";
    > gets(address);
    > cout<<"\nEnter Date of Birth : ";
    > gets(dob);
    > cout<<"\nEnter Phone Number : ";
    > cin>>phone_no;
    > cout<<"\nEnter Blood Group : ";
    > gets(blood_gr);
    > }


    Use "cin" instead of "gets" in the above.

    > void DONOR::display()
    > {
    > clrscr();
    > cout<<"\t\t\tDONOR DETAILS";
    > cout<<"\nNAME : ";
    > puts(name);
    > cout<<"\nAddress : ";
    > puts(address);
    > cout<<"\nDate Of Birth : ";
    > puts(dob);
    > cout<<"\nPhone Number : "<<phone_no;
    > cout<<"\nBlood Group : ";
    > puts(blood_gr);
    > getch();


    There is no "getch" in standard C++

    > }


    Use "cout" instead of "puts" in the above.

    > void DONOR::save()
    > {
    > fstream dfile;
    > DONOR DD;
    > dfile.open("DONOR.dat",ios::app);
    > dfile.write((char *)&DD,sizeof(DD));
    > dfile.close();


    Your trying to save a blank DONOR object. Write 'this' instead of '&DD'.
    Better would be to use the put-to operator (<<) for each parameter, like
    you do with cout.

    http://www.parashift.com/c -faq-lite/serialization.html

    > }
    > class node
    > {
    > DONOR record;
    > public:
    > node *next;
    > void append();
    > void display();
    > void save();
    > void query(char b_group[40]);
    > node()
    > {
    > next=NULL;
    > }
    > };
    > void node::append()
    > {
    > record.accept();
    > next=NULL;
    > }
    > void node::display()
    > {
    > record.display();
    > }
    > void node::save()
    > {
    > record.save();
    > }
    > void node::query(char b_group[40])
    > {
    > if(strcmp(record.return_group(),b_group)==0)
    > display();
    > }
    > class list
    > {
    > node *first,*last;
    > public:
    > list()
    > {
    > first=NULL;
    > last=NULL;
    > }
    > void append();
    > void save(node *ptr);
    > void display();
    > void query();
    > void open();
    > };
    > void list::save(node *ptr)
    > {
    > ptr->save();
    > }
    > void list::append()
    > {
    > node *ptr;
    > ptr=new node;
    > ptr->append();
    > if(first==NULL)
    > first=last=ptr;
    > else
    > {
    > last->next=ptr;
    > last=ptr;
    > }
    > save(ptr);
    > }
    > void list::display()
    > {
    > node *ptr;
    > ptr=first;
    > while(ptr!=NULL)
    > {
    > ptr->display();
    > ptr=ptr->next;
    > }
    > }
    > void list::query()
    > {
    > clrscr();
    > char b_group[4];
    > node *ptr;
    > cout<<"\t\tDONOR DETAILS";
    > cout<<"\nBlood Group : ";
    > cin>>b_group;
    > for(ptr=first;ptr;ptr=ptr->next)
    > ptr->query(b_group);
    > }


    Dump the node and list classes and use std::list instead.

    > void main()
    > {
    > int ch;
    > list LIST;
    > do
    > {
    > clrscr();


    No such function in standard C++

    > cout<<"\t\t\tDONOR DETAILS";
    > cout<<"\n\t1: Append Records";
    > cout<<"\n\t2: Display Records";
    > cout<<"\n\t3: Query on blood group";
    > cout<<"\n\t4: End the program";
    > cout<<"\n\nEnter your choice : ";
    > cin>>ch;
    > switch(ch)
    > {
    > case 1:
    > LIST.append();
    > break;
    > case 2:
    > LIST.display();
    > break;
    > case 3:
    > LIST.query();
    > break;
    > case 4:
    > cout<<"\nEnd of the program";
    > getch();
    > break;
    > }
    > }while(ch!=4);
    > }


    --
    There are two things that simply cannot be doubted, logic and perception.
    Doubt those, and you no longer have anyone to discuss your doubts with,
    nor any ability to discuss them.
     
    Daniel T., Oct 21, 2006
    #3
  4. Jinsu Jais

    David Harmon Guest

    On 21 Oct 2006 02:39:24 -0700 in comp.lang.c++, "StreamKid"
    <> wrote,
    >1) at the beggining, in class DONOR, i guess you want the first part
    >(name, dob, address, etc) private, but you haven't written the
    >private: keyword anywhere, and they aren't always by default private
    >(depends on the compiler). you can change it to:
    >class DONOR {
    >private:


    According to the standard, they are private. It would take a pretty
    wacky compiler to get that wrong.

    See "[7.8] What's the difference between the keywords struct and
    class?" in Marshall Cline's C++ FAQ. You can read the FAQ at:
    http://www.parashift.com/c -faq-lite/
     
    David Harmon, Oct 21, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dinesh Upare

    help required urgent

    Dinesh Upare, Aug 13, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,017
    Carl Prothman [MVP]
    Aug 13, 2003
  2. Replies:
    1
    Views:
    516
    kameshwar_kaushik
    Jan 29, 2006
  3. Dinesh Upare

    help required urgent

    Dinesh Upare, Aug 13, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    355
    Tommy
    Aug 13, 2003
  4. CGuy
    Replies:
    4
    Views:
    587
    Saravana
    Oct 1, 2003
  5. maadhuu

    urgent help in Qt required

    maadhuu, May 19, 2005, in forum: C++
    Replies:
    3
    Views:
    429
    Duane Hebert
    May 19, 2005
Loading...

Share This Page