Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- #include <iostream.h>
- #include <string.h>
- #include <stdlib.h>
- #include <fstream.h>
- struct{
- char user[20],pass[20],name[50],address[50],course[20],section[20];
- }mehh[50];
- char input[50];
- int ctr=0,opt=0,len=0,flag=0;
- void load(),save(),space(),unspace(),login(),reg(),view(),loginmenu();
- void main(){
- clrscr();
- load();
- cout<<"[1] Login\n[2] Register\n[3] Exit\n";
- cin>>opt;
- switch (opt){
- case 1: login(); break;
- case 2: reg(); break;
- default: exit(0);
- }
- }
- void login(){
- char luser[20],lpass[20];
- clrscr();
- cout<<"Username: ";
- cin>>luser;
- cout<<"Password: ";
- cin>>lpass;
- for (int m=0;m<ctr;m++){
- if(!strcmp(luser,mehh[m].user)&&!strcmp(lpass,mehh[m].pass)){
- loginmenu();
- flag=1;
- }
- }
- if(flag==0){
- cout<<"Incorrect Username or Password...";
- getch();
- main();
- }
- }
- void reg(){
- clrscr();
- cout<<"Username: ";
- cin>>mehh[ctr].user;
- cout<<"Password: ";
- cin>>mehh[ctr].pass;
- cout<<"Name: ";
- unspace();
- strcpy(mehh[ctr].name,input);
- cout<<"Address: ";
- unspace();
- strcpy(mehh[ctr].address,input);
- cout<<"Course: ";
- cin>>mehh[ctr].course;
- cout<<"Section: ";
- cin>>mehh[ctr].section;
- cout<<"Login Successful";
- getch();
- ctr++;
- save();
- main();
- }
- void loginmenu(){
- clrscr();
- cout<<"[1] View\n[2] Logout\n";
- cin>>opt;
- switch(opt){
- case 1: view(); break;
- case 2: main(); break;
- default: main();
- }
- }
- void view(){
- clrscr();
- for(int n=0; n<ctr; n++){
- cout<<"Id: "<<n+1<<endl<<endl;
- cout<<"Username: "<<mehh[n].user<<endl;
- cout<<"Password: "<<mehh[n].pass<<endl;
- cout<<"Name: ";
- strcpy(input,mehh[n].name);
- space();
- cout<<"Address: ";
- strcpy(input,mehh[n].address);
- space();
- cout<<"Course: "<<mehh[n].course<<endl;
- cout<<"Section: "<<mehh[n].section<<endl;
- cout<<endl;
- }
- getch();
- loginmenu();
- }
- void load(){
- ifstream read;
- read.open("mehh.txt");
- read>>ctr;
- for (int i=0;i<ctr;i++){
- read>>mehh[i].user>>mehh[i].pass>>mehh[i].name>>mehh[i].address>>mehh[i].course>>mehh[i].section;
- }
- read.close();
- }
- void save(){
- ofstream write;
- write.open("mehh.txt");
- write<<ctr<<endl;
- for (int j=0;j<ctr;j++){
- write<<mehh[j].user<<" "<<mehh[j].pass<<" "<<mehh[j].name<<" "<<mehh[j].address<<" "<<mehh[j].course<<" "<<mehh[j].section<<endl;
- }
- write.close();
- }
- void unspace(){
- gets(input);
- len=strlen(input);
- for (int k=0;k<len;k++){
- if (input[k]==' '){
- input[k]='_';
- }
- }
- }
- void space(){
- len=strlen(input);
- for (int l=0;l<len;l++){
- if (input[l]=='_'){
- input[l]=' ';
- }
- }
- cout<<input<<endl;
- }
Add Comment
Please, Sign In to add comment