Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int sz= 101;
- bool visited[sz];
- 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) /*or !visited[int(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);
- visited[id]= true;
- }
- int getId()
- {
- return id;
- }
- void setName()
- {
- cout << "Enter name : ";
- cin >> name ;
- }
- char* getName()
- {
- return name;
- }
- };
- int main()
- {
- for(int i=0 ; i<sz ;i++) visited[i]= false;
- Customer c1 ;
- ofstream out("data.txt", ios::out | ios::app );
- char ch='Y';
- do{
- c1.setId();
- visited[c1.getId()] = true;
- c1.setName();
- out.write( (char *)&c1 , sizeof(c1));
- cout <<"press Y to continue";
- cin >> ch ;
- }while(ch=='Y');
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement