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)
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)