473,699 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with C++ program

1 New Member
//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 1661

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

Similar topics

1
4079
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 Windows XP Professional. The other day, it worked just fne. Today it doesn't. I had this same problem a few weeks ago, but it mysteriously went away. Well, now it's back. What did I change? I have no idea. Lot's of stuff, I suppose. I don't...
0
3070
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 the context of a main window. The problem does not occur on HPUX or Linux. The following simple example code illustrates the problem and the work around I've come up with; However, I'd like, very much, to get rid of the kludgy work around....
0
2021
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 users So I designed the project as master Node that has all administration
6
7929
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 Internet Explorer connection settings (proxy:8080). However, as soon as this setting is enabled, the remoting program running on their pc stops communicating with the server it sends data to. I've disabled proxy setting on the affected pc, rebooted...
117
7208
by: Peter Olcott | last post by:
www.halting-problem.com
18
6169
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 strcat (mystract). Program below. However this appears not to have fixed the problem and I don't know why it shouldn't ? Any further help as to what else I am doing wrong will be appreciated regards
1
1837
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 concurrent users So I designed the project as master Node that has all administration project and about 10 client Nodes Those subscribers will login and I configured the replication at Server that can publish any change to the Nodes
8
9753
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 problem: my vb.net program has problems with UNC. If the UNC server is restarted or goes off-line, my VB.net program crashes. The code for UNC access to the file is included below and is put in the tick event of a form timer control running every...
9
13269
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 <hash_map>//from Standard template library //and some other headers
1
17547
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 another program for information passing. Upon receiving a particular "command" from the the information passing program, myProblemProgram will launch a separate thread to do individual communication with another file transfer program. The thread...
0
8685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8613
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8908
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.