1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include <iostream>
#include <cstdio>
#include <conio.h>
using namespace std;
main()
{
FILE *fp, *ft;
char another, choice;
struct student
{
int id;
string name;
int age;
char gender[7];
string address;
string blood_group;
string doc_name;
int amount;
char op_tr[1];
};
struct student e;
int xid;
int recsize;
int ifound;
fp=fopen("users.txt","rb+");
if (fp == NULL)
{
fp = fopen("users.txt","wb+");
if (fp==NULL)
{
puts("Cannot open file");
return 0;
}
}
recsize = sizeof(e);
while(1)
{
system("cls");
cout << "\t\t====== STUDENT DATABASE MANAGEMENT SYSTEM ======";
cout <<"\n\n ";
cout << "\n\n";
cout << "\n \t\t\t 1. Add Records";
cout << "\n \t\t\t 2. List Records";
cout << "\n \t\t\t 3. Search Record";
cout << "\n \t\t\t 4. Modify Records";
cout << "\n \t\t\t 5. Delete Records";
cout << "\n \t\t\t 6. Exit Program";
cout << "\n\n";
cout << "\t\t\t Select Your Choice :=> ";
fflush(stdin);
choice = getche();
switch(choice)
{
case '1' :
fseek(fp,0,SEEK_END);
another ='Y';
while(another == 'Y' || another == 'y')
{
cout << "\nEnter ID : ";
cin >> e.id;
cin.ignore();
cout <<"\nEnter Name: ";
getline(cin,e.name);
cout <<"\nEnter Age: ";
cin>>e.age;
cin.ignore();
cout <<"\nEnter Blood Group: ";
getline(cin,e.blood_group);
cin.ignore();
cout <<"\nEnter Address: ";
getline(cin,e.address);
cin.ignore();
cout <<"\nEnter Doctor Name: ";
getline(cin,e.doc_name);
cout <<"\nEnter Amount Paid: ";
cin>>e.amount;
cout <<"\nEnter Operation/Treatment: ";
cin>>e.op_tr;
fwrite(&e,recsize,1,fp);
cout << "\n Add Another Record (Y/N) ";
fflush(stdin);
another = getchar();
}
break;
case '2':
system("cls");
rewind(fp);
cout << "=== View the Records in the Database ===";
cout << "\n";
while (fread(&e,recsize,1,fp) == 1)
{
cout << "\n\n";
cout << e.id << endl;
cout << e.name << endl;
cout << e.age << endl;
cout << e.address << endl;
cout << e.blood_group<< endl;
cout << e.amount << endl;
cout << e.op_tr << endl;
cout << "\n ================================";
}
cout << "\n\n";
system("pause");
break;
default:
cout <<"BLAA"<<endl;
}
|