Help me please

J

Jinsu Jais

Hi all,

I am under high tension. Please help me in my project.
I could not complete it. It may have some irregular problems. I mean it
is not perfect. Please help me.

My project is the old one. The blood bank management system.
But I could not retrieve the saved record from it. Please implement a
data saving technique and witing for your suggestions on my project.
Please cooperate.

The source code is:


#include<fstream.h>
#include<string.h>
#include<stdlib.h>
#include<dos.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<iostream.h>

int save(int a);
int display(int a);
int edit(int a);
int del(int a);
int sort(int a);
int capfix(int a);
int save_to_disk(int a);
int SearchBlood_gr(int a,char Blood[]);

struct{
int id;
char name[20];
char dob[8];
char address[50];
char phone_no[12];
char blood_gr[3];
}
b[100];

int main()
{
int a = 0, cho;
ifstream ifile;
q:
clrscr();
cout<<"\n\n\n\t\t\t\tRetrieve The Records From\n\n"
<<"\t1:Hard Disk\n"
<<"\t2:Floppy Disk\n\n";
cout<<"Enter numeric choice: ";
cin>>cho;
switch (cho)
{
case 1:ifile.open("BloodBank.txt", ios::nocreate);
break;
case 2:ifile.open("A:\BloodBank.txt", ios::nocreate);
break;
default:
cout<<"\nNot a valid entry\n"<<endl;
getch();
goto q;
}
while(ifile.peek()!=EOF)
{
ifile>>b[a].id;
ifile>>b[a].name;
ifile>>b[a].dob;
ifile>>b[a].address;
ifile>>b[a].phone_no;
ifile>>b[a].blood_gr;
a++;
}

ifile.close();
while(1)
{
int choice;
char blood[3];
capfix(a);
sort(a);
q1:
clrscr();
cout<<"\n\t\t\t\tBLOOD BANK MANAGEMENT SYSTEM";
cout<<"\n\n\n\t\t* "<<a<<" entry(s)*"<<endl;
cout << "\n\n1. Add Details\n"
"2. Display Details\n"
"3. Save Changes\n"
"4. Query on Blood Group\n"
"5. Edit Details\n"
"6. Delete Details\n"
"7. Exit\n"
"\n\t\tEnter your Choice::\t ";

cin >> choice;

switch (choice)
{
case 1: a = save(a); break;
case 2: display(a); getch(); break;
case 5: edit(a); getch();break;
case 6: a=del(a); break;
case 7: exit(1); break;
case 3: save_to_disk(a); break;
case 4:
clrscr();
cout<<"\n\nEnter the blood group you want to
search\n(e.g.:for o+ve,
type o+ or O+;for ab+ve, type ab+ or AB+;)\n";
cin>>blood;
SearchBlood_gr(a,blood);
break;
default:
cout<<"\nNot a valid entry\n"<<endl;
getch();
goto q1;
}

}
return 0;

}
int save(int a)
{
char ex;

while(1)
{
clrscr();
b[a].id=a+1;
cout<<"\n\tEnter the name: ";
gets(b[a].name);
cout<<"\tEnter the date of birth
(e.g.:14-12-89;01-01-89;17-05-89)
:";
gets(b[a].dob);
cout<<"\tEnter the address: ";
gets(b[a].address);
cout<<"\tEnter their phone number: ";
gets(b[a].phone_no);
cout<<"\tEnter the blood group (e.g.: o+, O-, AB+, ab-)
:";
gets(b[a].blood_gr);
a++;
cout<<"\n\nWould you like to enter another
record?"<<endl
<<"(y) for yes and (n) for no:: ";
cin>>ex;
if(ex == 'n')
{return a;
break;}

}

return a;
}

int display(int a)
{
int c,d;
for(d = 0; d < a; d++)
for(c = 0; c < 20; c++)
if(c == 0)

b[d].name[c] = toupper(b[d].name[c]);


clrscr();
cout<<endl;
for(c = 0; c < a; c++)
{
cout<<b[c].id<<endl
<<b[c].name<<endl
<<b[c].dob<<endl
<<b[c].address<<endl
<<b[c].phone_no<<endl
<<b[c].blood_gr<<endl;
}
return 0;
}

int SearchBlood_gr(int a,char Blood[])
{
int c,flag=0;
clrscr();

cout<<endl<<endl;
for(c = 0; c < a; c++)
{
if((stricmp(Blood,b[c].blood_gr)==0))
{
cout<<b[c].id<<endl
<<b[c].name<<endl
<<b[c].dob<<endl
<<b[c].address<<endl
<<b[c].phone_no<<endl
<<b[c].blood_gr<<endl;
flag=1;
}
}
if(flag!=1)
cout<<"\n Not available";

getch();

return 0;
}
int sort(int a)
{
char subN[20], subA[20], subPh[20],db[12],bgr[10];
int c, e, n;
for(c = 0; c < a; c++)
{
for(e = 0; e < a; e++)
{
n = strcmp(b[c].name, b[e].name);
if(n < 0)
{
strcpy(subN, b[c].name);
strcpy(db, b[c].dob);
strcpy(subA, b[c].address);
strcpy(subPh, b[c].phone_no);
strcpy(bgr, b[c].blood_gr);
strcpy(b[c].name, b[e].name);
strcpy(b[c].dob, b[e].dob);
strcpy(b[c].address,
b[e].address);
strcpy(b[c].phone_no,
b[e].phone_no);
strcpy(b[c].blood_gr,
b[e].blood_gr);
strcpy(b[e].name, subN);
strcpy(b[e].dob, db);
strcpy(b[e].address, subA);
strcpy(b[e].phone_no, subPh);
strcpy(b[e].blood_gr, bgr);
}
}
b[c].id = c+1;
}

return 0;
}

int capfix(int a)
{
int d, c;
for(d = 0; d < a; d++)
{
for(c = 0; c < 20; c++)
{
if(c == 0)
{
b[d].name[c] = toupper(b[d].name[c]);
}
else if( c >= 1)
{
b[d].name[c] = tolower(b[d].name[c]);
}
}
}
return 0;
}

int save_to_disk(int a)
{
int choice, z;
clrscr();
cout<<"\nSave To\n\n"
<<"1. Hard Disk\n"
<<"2. Floppy Disk\n\n"
<<"Enter Numeric Choice:";
cin>>choice;
ofstream ofile;

switch(choice)
{
case 1: ofile.open("BloodBank.txt", ios::trunc);
break;
case 2: ofile.open("A:\BloodBank.txt", ios::trunc);
if(ofile.fail())
{cout<<"error writting to Floppy\n\n";
return 0;}
break;
default: cout<<"not a valid entry"<<endl;
return 0;
}
for(z = 0; z < a; z++)
{
ofile<<b[z].id<<endl
<<b[z].name<<endl
<<b[z].dob<<endl
<<b[z].address<<endl
<<b[z].phone_no<<endl
<<b[z].blood_gr;
if(z == a-1)
return 0;
else
ofile<<endl;
}
return 0;
}

int edit(int a)
{
clrscr();
if( a <= 0)
{ cout<<"\n\n\t\tNothing to Edit!\n";
return a;}
int idno, c;
cout<<"\n\n\tEnter ID number that you wish to edit: ";
cin>>idno;
if(idno > a || idno < 0)
{ cout<<"\nNot valid ID!\n";
return a;}
for(c = 0; c <= a; c++)
{
if(idno == b[c].id)
{ cout<<b[c].id<<endl<<b[c].name<<"\t "<<"NEW
Name: ";
cin>>b[c].name;
cout<<endl<<b[c].dob<<"\t "<<"NEW Date of
Birth: ";
cin>>b[c].dob;
cout<<endl<<b[c].address<<"\t "<<"NEW Address:
";
cin>>b[c].address;
cout<<endl<<b[c].phone_no<<"\t "<<"NEW Phone
Number: ";
cin>>b[c].phone_no;
cout<<endl<<b[c].blood_gr<<"\t "<<"NEW Blood
Group: ";
cin>>b[c].blood_gr;
}
}
return 0;
}
int del(int a)
{
int idno, c;
clrscr();
if( a <= 0)
{ cout<<"\n\n\t\tNothing to delete!\n";
getch();
return a;}
cout<<"\n\n\t\tEnter ID number that you wish to delete: ";
cin>>idno;
if(idno > a || idno < 0)
{ cout<<"\n\n\tNot valid ID!\n";
return a;}
for(c = 0; c < a; c++)
{
if(idno == b[c].id)
{
strcpy(b[c].name, b[a-1].name);
strcpy(b[c].dob, b[a-1].dob);
strcpy(b[c].address, b[a-1].address);
strcpy(b[c].phone_no, b[a-1].phone_no);
strcpy(b[c].blood_gr, b[a-1].blood_gr);
}
}
return --a;
}


Waiting for your reply : (e-mail address removed)
 
V

Victor Bazarov

Jinsu said:
I am under high tension. Please help me in my project.
I could not complete it. It may have some irregular problems.
[..]

Please contact your instructor/teacher and explain your problem
to him/her. Ask him/her for help. Ask for an extension. We
cannot and will not do your course work. One of purposes of
your studying is to learn to deal with the situations like this
(high tension, lack of time) in the right way. Asking someone
to do your work for you is _not_ the right way.

If you have irregular problems with your code, see FAQ 5.8 and
follow _all_ of its recommendations. Keep in mind that you
would really be much better off if you take this up with your
instructor/teacher.

V
 
O

osmium

Jinsu Jais said:
I am under high tension. Please help me in my project.
I could not complete it. It may have some irregular problems. I mean it
is not perfect. Please help me.

My project is the old one. The blood bank management system.
But I could not retrieve the saved record from it. Please implement a
data saving technique and witing for your suggestions on my project.
Please cooperate.

The source code is:


#include<fstream.h>
#include<string.h>
#include<stdlib.h>
#include<dos.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<iostream.h>

There are two problems as far as the members of this group are concerned,
you are using an old compiler and you are using non standard headers (conio
and dos). I tried to compile your program and got three pages of errors,
though I have no reason to believe it doesn't compile perfectly for you.
The end result is your chance of getting a specific answer here are pretty
close to zero.

I could probably patch most of the problems I saw but I don't have the
patience to do so. The program looks like it was written by someone who has
a fair handle on what he/she/it was doing. But I was unwilling to do the
burrowing necessary to find the problem area. I suggest this: Look at the
file produced with a text editor. Does it look pretty good? If so, write a
little throw away program that reads write and reads stuff from a disk, be
sure you do not use (write) a binary file. Using your new found knowledge,
find and fix your problem. If you post your throw away thing, someone will
probably help you, it will be small enough to be tractable.

<snip>
 
D

Daniel T.

"Jinsu Jais said:
Hi all,

I am under high tension. Please help me in my project.
I could not complete it. It may have some irregular problems. I mean it
is not perfect. Please help me.

My project is the old one. The blood bank management system.
But I could not retrieve the saved record from it. Please implement a
data saving technique and witing for your suggestions on my project.
Please cooperate.

I suggest you read the faqs in this section:
http://www.parashift.com/c++-faq-lite/serialization.html

especially
http://www.parashift.com/c++-faq-lite/serialization.html#faq-36.7

Start with this:

struct Data {
int id;
char name[20];
char dob[9]; // note! dob should have at least 9 characters!
char address[50];
char phone_no[12];
char blood_gr[3];
};

ostream& operator<<( ostream& os, const Data& d )
{
return os << d.id << '\n'
<< d.name << '\n'
<< d.dob << '\n'
<< d.address << '\n'
<< d.phone_no << '\n'
<< d.blood_gr << '\n';
}

istream& operator>>( istream& is, Data& d )
{
// write implementation here
return is;
}

int main()
{
Data data;
data.id = 1;
strcpy( data.name, "Jinsu Jais" );
strcpy( data.dob, "01-09-07" );
strcpy( data.address, "1600 Pennsylvania Ave. NW" );
strcpy( data.phone_no, "555-1212" );
strcpy( data.blood_gr, "O+" );
stringstream storage;
storage << data;
cout << storage.str();

Data data2;
storage >> data2;
assert( data2.id == 1 );
assert( strcmp( data2.name, "Jinsu Jais" ) == 0 );
assert( strcmp( data2.dob, "01-09-07" ) == 0 );
assert( strcmp( data2.address, "1600 Pennsylvania Ave. NW" ) == 0 );
assert( strcmp( data2.phone_no, "555-1212" ) == 0 );
assert( strcmp( data2.blood_gr, "O+" ) == 0 );
cout << "Great job!\n";
}

Add code where it says "write implementation here" until you can get the
program to print "Great job!". Look up especially "getline"

Once you got that working, it's a simple matter of putting "myfile >>
myData;" in the right spot.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top