sidex15

4/23/2019 C++ Activity

Apr 23rd, 2019 (edited)
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.62 KB | None | 0 0
  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <iostream.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <fstream.h>
  7.  
  8. struct{
  9.  char user[20],pass[20],name[50],address[50],course[20],section[20];
  10. }mehh[50];
  11.  
  12. char input[50];
  13. int ctr=0,opt=0,len=0,flag=0;
  14.  
  15. void load(),save(),space(),unspace(),login(),reg(),view(),loginmenu();
  16.  
  17. void main(){
  18.  clrscr();
  19.  load();
  20.  cout<<"[1] Login\n[2] Register\n[3] Exit\n";
  21.  cin>>opt;
  22.  switch (opt){
  23.   case 1: login(); break;
  24.   case 2: reg(); break;
  25.   default: exit(0);
  26.  }
  27. }
  28.  
  29. void login(){
  30.  char luser[20],lpass[20];
  31.  clrscr();
  32.  cout<<"Username: ";
  33.  cin>>luser;
  34.  cout<<"Password: ";
  35.  cin>>lpass;
  36.  for (int m=0;m<ctr;m++){
  37.   if(!strcmp(luser,mehh[m].user)&&!strcmp(lpass,mehh[m].pass)){
  38.    loginmenu();
  39.    flag=1;
  40.   }
  41.  }
  42.  if(flag==0){
  43.   cout<<"Incorrect Username or Password...";
  44.   getch();
  45.   main();
  46.  }
  47. }
  48.  
  49. void reg(){
  50.  clrscr();
  51.  cout<<"Username: ";
  52.  cin>>mehh[ctr].user;
  53.  cout<<"Password: ";
  54.  cin>>mehh[ctr].pass;
  55.  cout<<"Name: ";
  56.  unspace();
  57.  strcpy(mehh[ctr].name,input);
  58.  cout<<"Address: ";
  59.  unspace();
  60.  strcpy(mehh[ctr].address,input);
  61.  cout<<"Course: ";
  62.  cin>>mehh[ctr].course;
  63.  cout<<"Section: ";
  64.  cin>>mehh[ctr].section;
  65.  cout<<"Login Successful";
  66.  getch();
  67.  ctr++;
  68.  save();
  69.  main();
  70. }
  71.  
  72. void loginmenu(){
  73.  clrscr();
  74.  cout<<"[1] View\n[2] Logout\n";
  75.  cin>>opt;
  76.  switch(opt){
  77.   case 1: view(); break;
  78.   case 2: main(); break;
  79.   default: main();
  80.  }
  81. }
  82.  
  83. void view(){
  84.  clrscr();
  85.  for(int n=0; n<ctr; n++){
  86.   cout<<"Id: "<<n+1<<endl<<endl;
  87.   cout<<"Username: "<<mehh[n].user<<endl;
  88.   cout<<"Password: "<<mehh[n].pass<<endl;
  89.   cout<<"Name: ";
  90.   strcpy(input,mehh[n].name);
  91.   space();
  92.   cout<<"Address: ";
  93.   strcpy(input,mehh[n].address);
  94.   space();
  95.   cout<<"Course: "<<mehh[n].course<<endl;
  96.   cout<<"Section: "<<mehh[n].section<<endl;
  97.   cout<<endl;
  98.  }
  99.  getch();
  100.  loginmenu();
  101. }
  102.  
  103. void load(){
  104.   ifstream read;
  105.   read.open("mehh.txt");
  106.   read>>ctr;
  107.   for (int i=0;i<ctr;i++){
  108.    read>>mehh[i].user>>mehh[i].pass>>mehh[i].name>>mehh[i].address>>mehh[i].course>>mehh[i].section;
  109.   }
  110.   read.close();
  111. }
  112.  
  113. void save(){
  114.  ofstream write;
  115.  write.open("mehh.txt");
  116.  write<<ctr<<endl;
  117.  for (int j=0;j<ctr;j++){
  118.  write<<mehh[j].user<<" "<<mehh[j].pass<<" "<<mehh[j].name<<" "<<mehh[j].address<<" "<<mehh[j].course<<" "<<mehh[j].section<<endl;
  119.  }
  120.  write.close();
  121. }
  122.  
  123. void unspace(){
  124.  gets(input);
  125.  len=strlen(input);
  126.  for (int k=0;k<len;k++){
  127.   if (input[k]==' '){
  128.    input[k]='_';
  129.   }
  130.  }
  131. }
  132.  
  133. void space(){
  134.  len=strlen(input);
  135.  for (int l=0;l<len;l++){
  136.   if (input[l]=='_'){
  137.    input[l]=' ';
  138.   }
  139.  }
  140.  cout<<input<<endl;
  141. }
Add Comment
Please, Sign In to add comment