Advertisement
Guest User

My code

a guest
Aug 3rd, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1.  
  2. #include<fstream.h>
  3. #include<iomanip.h>
  4. #include<conio.h>
  5. #include<windows.h>
  6. #include<string.h>
  7. int flag=0; char ch;
  8. struct password
  9. {
  10.     char passs[25];
  11. };
  12. void enteringfirstpass()
  13. {
  14.  
  15.         password ok;
  16.         cout<<"Enter your ___ pass\n";
  17.         gets(ok.passs);
  18.         ofstream fio("password",ios::out,ios::binary);
  19.         fio.write((char*)&ok,sizeof(password));
  20.         fio.close();
  21.  
  22. }
  23. class question
  24. {
  25.     public:
  26.     char ques[1000];
  27.     char option1[50],option2[50],option3[50],option4[50];
  28.     int k;
  29.     int qno;
  30. };
  31.  
  32. void addquestion(void)
  33. {
  34.     question abc;
  35.     cout<<"Enter question number\n";
  36.     cin>>abc.qno;
  37.     cout<<abc.qno;
  38.  
  39.     ofstream fout;
  40.     fout.open("question.txt",ios::out|ios::binary);
  41.     cout<<"Enter Question!\n";
  42.     gets(abc.ques);
  43.     cout<<"Enter Options!\n";
  44.     gets(abc.option1);gets(abc.option2);gets(abc.option3);gets(abc.option4);
  45.     cout<<"Enter correct option number\n";
  46.     cin>>abc.k;
  47.     cout<<"dadalaa";
  48.     fout.write((char*)&abc,sizeof(abc));
  49.     fout.close();
  50.  
  51.     getch();
  52. }
  53. void dispsetting()
  54. {
  55.     char chkpass[30];int count=0;
  56.     password pass;
  57.     cout<<"Enter your password\n";
  58.     gets(chkpass);
  59.     ifstream fi("password.txt",ios::in|ios::binary);
  60.     fi.read((char*)&pass,sizeof(password));
  61.     if(strcmpi(chkpass,pass.passs)==0)
  62.     {
  63.         cout<<"  _|_|_|  _|_|_|_|  _|_|_|_|_|  _|_|_|_|_|  _|_|_|  _|      _|    _|_|_|"<<endl;
  64.         cout<<"_|        _|            _|          _|        _|    _|_|    _|  _|      "<<endl;
  65.         cout<<"  _|_|    _|_|_|        _|          _|        _|    _|  _|  _|  _|  _|_|"<<endl;
  66.         cout<<"     _|   _|            _|          _|        _|    _|    _|_|  _|    _|"<<endl;
  67.         cout<<"_|_|_|    _|_|_|_|      _|          _|      _|_|_|  _|      _|    _|_|_|"<<endl;
  68.         cout<<"\n\n\n";
  69.         cout<<"1. ADD QUESTION\n" ;
  70.         cout<<"2. DELETE QUESTION\n";
  71.         cout<<"3. MODIFY QUESTION\n";
  72.         cout<<"4. CHANGE PASSWORD\n";
  73.     }
  74.  
  75.     else
  76.     {
  77.         cout<<"ACCESS DENIED!!!Wrong Password\n";
  78.         while(strcmpi(chkpass,pass.passs)!=0)
  79.         {
  80.             cout<<"Please enter your passsword again\n";
  81.             gets(chkpass);
  82.         count++;
  83.         if(count==4)
  84.             {
  85.  
  86.                 cout<<"You have entered wrong password 5 times\n Program will now terminate!!\n";
  87.                 exit(0);
  88.             }
  89.         }
  90.     }
  91. }
  92. void pass()
  93. {   password pass;
  94.     char password[25];
  95.     cout<<"Change Password Menu \n";
  96.     cout<<"Do you want to change your password(y/n)\n";
  97.     char ch1;
  98.     cin>>ch1;
  99.     if(ch1=='y'||ch1=='Y')
  100.     {
  101.  
  102.         cout<<"Enter Old Password";
  103.         gets(password);
  104.         ifstream fi("password",ios::in|ios::binary);
  105.         fi.read((char*)& pass,sizeof(password));
  106.         fi.close();
  107.         if((strcmpi(password,pass.passs)==0))
  108.         {   ofstream fo("password",ios::out|ios::binary);
  109.             fo.write((char*)password,sizeof(password));
  110.             fo.close();
  111.         }
  112.     }
  113. }
  114. void main()
  115. {
  116.  
  117.  
  118.     enteringfirstpass();
  119.     addquestion();
  120.     pass();
  121.     dispsetting();
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement