473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

problem with C++ program

//BLOOD BANK MANAGEMENT SYSTEM//
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<fstream.h>
  4. #include<string.h>
  5. #include<stdio.h>
  6. #include<process.h>
  7. fstream file;
  8. fstream file1;
  9. class donor
  10. { int num;
  11.   char name[20];
  12.   char dob[9];
  13.   char address[30];
  14.   int phone_no;
  15.   char blood_gr;
  16.   public:
  17.   void accept();
  18.   void display();
  19.   void query();
  20.   void modify();
  21.   void del();
  22.   char return_group()
  23.   {return blood_gr;}
  24.   int return_num()
  25.   {return num;}
  26. }s1;
  27.  
  28. void donor::accept()
  29. {
  30.   file.open("Don.dat",ios::app|ios::in|ios::out|ios::binary);
  31.   clrscr();
  32.   cout<<"\t\t\tDONOR DETAILS";
  33.   cout<<"\nEnter Donor no:  ";
  34.   cin>>num;
  35.   cout<<"\nEnter Name: ";
  36.   gets(name);
  37.   cout<<"\nEnter Address : ";
  38.   gets(address);
  39.   cout<<"\nEnter Date of Birth : ";
  40.   gets(dob);
  41.   cout<<"\nEnter Phone Number : ";
  42.   cin>>phone_no;
  43.   cout<<"\nEnter Blood Group : ";
  44.   cin>>blood_gr;
  45.   file.write((char *)&s1,sizeof(s1));
  46.   getch();
  47.   file.close();
  48. };
  49.  
  50. void donor::display()
  51. {
  52.    file.open("Don.dat",ios::app|ios::in|ios::out|ios::binary|ios::beg);
  53.    while(!file.eof())
  54.   {file.read((char *)&s1,sizeof(s1));
  55.   clrscr();
  56.   cout<<"\t\t\tDONOR DETAILS";
  57.   cout<<"\n\nDonor no : ";
  58.   cout<<num;
  59.   cout<<"\n\nNAME : ";
  60.   puts(name);
  61.   cout<<"\n\nAddress : ";
  62.   puts(address);
  63.   cout<<"\n\nDate Of Birth : ";
  64.   puts(dob);
  65.   cout<<"\n\nPhone Number : ";
  66.   cout<<phone_no;
  67.   cout<<"\n\n\nBlood Group : ";
  68.   cout<<blood_gr;
  69.   getch();
  70.   }
  71.   file.close();
  72. };
  73.  
  74. void donor::modify()
  75. {
  76.   file.open("Don.dat",ios::app|ios::in|ios::out|ios::beg|ios::binary);
  77.   int recno;
  78.   long pos;
  79.   char nam[20];
  80.   char dob1[9];
  81.   char address1[30];
  82.   int phone_no1;
  83.   char blood_gr1;
  84.   cout<<"\nEnter the record number you want to modify : ";
  85.   cin>>recno;
  86.   while(!file.eof())
  87.   {pos=file.tellg();
  88.   file.read((char *)&s1,sizeof(s1));
  89.   if(s1.return_num()==recno)
  90.   {
  91.    cout<<"\nEnter Name: ";
  92.    gets(nam);
  93.    cout<<"\nEnter Address : ";
  94.    gets(address1);
  95.    cout<<"\nEnter Date of Birth : ";
  96.    gets(dob1);
  97.    cout<<"\nEnter Phone Number : ";
  98.    cin>>phone_no1;
  99.    cout<<"\nEnter Blood Group : ";
  100.    cin>>blood_gr1;
  101.    name[20]=nam[20];
  102.    address[30]=address1[30];
  103.    dob[9]=dob1[9];
  104.    phone_no=phone_no1;
  105.    blood_gr=blood_gr1;
  106.    file.seekg(pos);
  107.    file.write((char *)&s1,sizeof(s1));
  108.    break;
  109.    }
  110.    }
  111.    getch();
  112.    file.close();
  113.    }
  114.  
  115. void donor::query()
  116. {
  117.  file.open("Don.dat",ios::app|ios::in|ios::out|ios::beg|ios::binary);
  118.  char bldgr;
  119.  cout<<"Enter the blood group you want to query\n ";
  120.  cin>>bldgr;
  121.   while(!file.eof())
  122.   {
  123.   file.read((char *)&s1,sizeof(s1));
  124.  if(s1.return_group()==bldgr)
  125.  {
  126.  s1.display();
  127.  getch();
  128.  break;
  129.  }
  130.  }
  131.  file.close();
  132.  };
  133.  
  134. void donor::del()
  135. {
  136.   file.open("Don.dat",ios::app|ios::in|ios::out|ios::beg|ios::binary);
  137.   file1.open("temp.dat",ios::app|ios::in|ios::out|ios::beg|ios::binary);
  138.   int rec;
  139.   char found='f',confirm='n';
  140.   cout<<"\nEnter the record number you wish to delete : ";
  141.   cin>>rec;
  142.   while(!file.eof())
  143.   { file.read((char *)&s1,sizeof(s1));
  144.     if(s1.return_num()==rec)
  145.     { s1.display();
  146.       found='t';
  147.       cout<<"\nAre you sure you want to delete this record? (y/n) ";
  148.       cin>>confirm;
  149.       if(confirm=='n')
  150.        file1.write((char *)&s1,sizeof(s1));
  151.      }
  152.      else
  153.        file1.write((char *)&s1,sizeof(s1));
  154.     }
  155.     if(found=='f')
  156.     cout<<"\nRecord not found";
  157.     file.close();
  158.     file1.close();
  159.     remove("Don.dat");
  160.     rename("temp.dat","Don.dat");
  161. }
  162.  
  163. void main()
  164. {
  165.   int ch;
  166.   do
  167.    {
  168.      clrscr();
  169.      cout<<"\t\t\tBLOOD BANK MANAGEMENT PROGRAM";
  170.      cout<<"\n\n\tDONOR DETAILS\n";
  171.      cout<<"\n\n\t1: Append Records";
  172.      cout<<"\n\n\t2: Display Records";
  173.      cout<<"\n\n\t3: Query on blood group";
  174.      cout<<"\n\n\t4: Modify existing Records";
  175.      cout<<"\n\n\t5: Delete existing Records";
  176.      cout<<"\n\n\t6: End the program";
  177.      cout<<"\n\nEnter your choice (1-6) : ";
  178.      cin>>ch;
  179.      switch(ch)
  180.     {
  181.       case 1:
  182.       s1.accept();
  183.       break;
  184.       case 2:
  185.       s1.display();
  186.       break;
  187.       case 3:
  188.       s1.query();
  189.       break;
  190.       case 4:
  191.       s1.modify();
  192.       break;
  193.       case 5:
  194.       s1.del();
  195.       break;
  196.       case 6:
  197.       cout<<"\nEnd of the program";
  198.       getch();
  199.       break;
  200.     }
  201.    }while(ch!=6);
  202. }
  203.  

In the above program the query and the delete function goes on endlessly displaying the record.while int display function the same record gets displayed twice.also in modify function the new details are not being overwritten .they are being added as a new record.Please help me out.Thanks in advacne.This program was coded using TURBO C++ V3.0.
Aug 26 '07 #1
0 1643

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Robertb | last post by:
I'm driving myself crazy trying to figure this one out. So much so that I think I'm within walking distance now! The program is written and compiled in Visual Basic 6 with SP5. The OS is...
0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
0
by: Refky Wahib | last post by:
Hi I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million concurrent...
6
by: harry | last post by:
Hi, I have a program that runs on multiple client pc's. Occasionally one or more of those pc's use VPN to connect to another corporate network. When using VPN they need to set proxy server in...
117
by: Peter Olcott | last post by:
www.halting-problem.com
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
1
by: Refky Wahib | last post by:
Hi Actually I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
9
by: Prasad | last post by:
HI, I am a beginner in VC++.. I am trying to write a Win32 console application in visual studio.. I am using following header files.. #include <STRING> using namespace std; #include...
1
by: Mr. Beck | last post by:
Hello, Please Help..... I have been working with some tcp/ip socket communication within a C# program recently. Basicly, I have a program (myProblemProgram) that has a socket connected to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.