Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- class Customer
- {
- int id ;
- char name[20];
- public :
- bool searchId(int val)
- {
- ifstream in ("data.txt", ios:: in);
- if(in.is_open())
- {
- Customer c1;
- while(!in.eof())
- {
- in.read( (char *)& c1, sizeof(c1));
- if(c1.id== val) return true;
- }
- }
- else cout << "Cann't open the file ";
- in.close();
- return false;
- }
- bool validId( double val){
- return ( val > 0 and int(val)== val and (!searchId(val) )) ;
- }
- void setId()
- {
- double x ;
- cout << "Enter ID : ";
- cin >> x;
- while(!validId(x) )
- {
- cout <<"Invalid Id , please try again \n";
- cout << "Enter ID : ";
- cin >> x;
- }
- id = int(x);
- }
- int getId()
- {
- return id;
- }
- void setName()
- {
- cout << "Enter name : ";
- cin >> name ;
- }
- char* getName()
- {
- return name;
- }
- };
- int main()
- {
- Customer c1 ;
- char ch='Y';
- do{
- ofstream out("data.txt", ios::out | ios::app );
- c1.setId();
- c1.setName();
- out.write( (char *)&c1 , sizeof(c1));
- cout <<"press Y to continue";
- cin >> ch ;
- out.close();
- }while(ch=='Y');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement