Guest User

Untitled

a guest
Oct 30th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. int adminView();
  9. int studentView();
  10. int studentLogin();
  11. int checkCredentials(string userName, string password);
  12. int getAllStudentsbyRollNo();
  13. int deleteAllStudents();
  14. int deleteStudentbyRollno();
  15. int checkListOfStudentsRegistered();
  16. int checkPresenseCountbyRollno();
  17. int getListOfStudentsWithTheirPresenseCount();
  18. int registerStudent();
  19. int adminLogin();
  20. int registerStudent();
  21. int markMyAttendance(string username);
  22. int countMyAttendance(string username);
  23. int delay();
  24.  
  25. int delay()
  26. {
  27. for(int i = 0; i<3; i ++)
  28. {
  29. cout<<"\n Saving Records ...";
  30. for(int ii = 0; ii<20000; ii ++)
  31. {
  32. for(int iii = 0; iii<20000; iii ++)
  33. {
  34.  
  35. }
  36. }
  37. }
  38.  
  39. cout<<"\n Exiting Now ...";
  40. for(int i = 0; i<3; i ++){
  41. for(int ii = 0; ii<20000; ii ++) {
  42. for(int iii = 0; iii<20000; iii ++){
  43. }
  44. }
  45. }
  46.  
  47. return 0;
  48. }
  49.  
  50. int adminView()
  51. {
  52. int goBack = 0;
  53. while(1)
  54. {
  55. system("cls");
  56. cout<<"\n 1 Register a Student";
  57. cout<<"\n 2 Delete All students name registered";
  58. cout<<"\n 3 Delete student by rollno";
  59. cout<<"\n 4 Check List of Student registered by userame";
  60. cout<<"\n 5 Check presense count of any student by Roll No";
  61. cout<<"\n 6 Get List of student with their attendance count";
  62. cout<<"\n 0. Go Back <- \n";
  63. int choice;
  64.  
  65. cout<<"\n Enter you choice: ";
  66. cin>>choice;
  67.  
  68. switch(choice)
  69. {
  70. case 1: registerStudent();break;
  71. case 2: deleteAllStudents(); break;
  72. case 3: deleteStudentbyRollno(); break;
  73. case 4: checkListOfStudentsRegistered(); break;
  74. case 5: checkPresenseCountbyRollno(); break;
  75. case 6: getListOfStudentsWithTheirPresenseCount(); break;
  76. case 0: goBack = 1;break;
  77. default: cout<<"\n Invalid choice. Enter again ";
  78. getchar();
  79. }
  80.  
  81. if(goBack == 1)
  82. {
  83. break; //break the loop
  84. }
  85.  
  86. }
  87.  
  88.  
  89. return 0;
  90.  
  91. }
  92.  
  93. int studentLogin()
  94. {
  95. system("cls");
  96. cout<<"\n -------------------- Student Login -----------------";
  97. studentView();
  98. delay();
  99. return 0;
  100. }
  101.  
  102.  
  103. int adminLogin()
  104. {
  105. system("cls");
  106. cout<<"\n -------------------- Admin Login -----------------";
  107.  
  108. string username;
  109. string password;
  110.  
  111. cout<<"\n Enter username : ";
  112. cin>>username;
  113. cout<<"\n Enter password : ";
  114. cin>>password;
  115.  
  116. if(username=="admin" && password=="admin@2")
  117. {
  118. adminView();
  119. getchar();
  120. delay();
  121. }
  122. else
  123. {
  124. cout<<"\n Error ! Invalid Credintials..";
  125. cout<<"\n Press any key for main menu ";
  126. getchar();getchar();
  127. }
  128.  
  129. return 0;
  130.  
  131. }
  132.  
  133.  
  134. int checkStudentCredentials(string username, string password)
  135. {
  136. // read file line by line & check if username-password.dat exist?
  137. // if it exsist return 1 else 0
  138.  
  139. ifstream read;
  140. read.open("db.dat");
  141.  
  142. if (read) {
  143. // The file exists, and is open for input
  144. int recordFound = 0;
  145. string line;
  146. string temp = username +".dat";
  147. cout<<"\n file name is : "<<temp;
  148. while(getline(read, line)) {
  149. if(line == temp)
  150. {
  151. recordFound = 1;
  152. break;
  153. }
  154. }
  155.  
  156. if(recordFound == 0)
  157. return 0;
  158. else
  159. return 1;
  160. }
  161. else
  162. {
  163. return 0;
  164. }
  165.  
  166. }
  167.  
  168.  
  169.  
  170.  
  171.  
  172. int getAllStudentsbyName()
  173. {
  174. cout<<"\n List of All Students by their Name \n";
  175.  
  176. cout<<"\n Please any key to continue..";
  177. getchar();getchar();
  178.  
  179. return 0;
  180.  
  181. }
  182.  
  183. int getAllStudentsbyRollNo()
  184. {
  185. cout<<"\n List of All Students by their Roll No \n";
  186.  
  187. cout<<"\n Please any key to continue..";
  188. getchar();getchar();
  189.  
  190. return 0;
  191.  
  192. }
  193.  
  194. int deleteStudentbyRollno()
  195. {
  196.  
  197. cout<<"\n Delete any Student by their Roll No \n";
  198.  
  199. cout<<"\n Please any key to continue..";
  200. getchar();getchar();
  201.  
  202. return 0;
  203. }
  204.  
  205.  
  206. int checkPresenseCountbyRollno()
  207. {
  208.  
  209. cout<<"\n Check presense count of any Student by Roll No \n";
  210.  
  211. cout<<"\n Please any key to continue.." ;
  212. getchar();getchar();
  213.  
  214. return 0;
  215.  
  216. }
  217.  
  218. int checkAllPresenseCountbyRollno()
  219. {
  220. cout<<"\n Check presense count of All Students by Roll No & Name \n";
  221.  
  222. cout<<"\n Please any key to continue.." ;
  223. getchar();getchar();
  224.  
  225. return 0;
  226. }
  227.  
  228. int studentView()
  229. {
  230. cout<<"\n ---------------- Student Login----------------- \n";
  231.  
  232. string username, password;
  233.  
  234. cout<<"\n Enter username : ";
  235. cin>>username;
  236.  
  237. cout<<"\n Enter password : ";
  238. cin>>password;
  239.  
  240. int res = checkStudentCredentials(username, password);
  241.  
  242. if(res == 0)
  243. {
  244. cout<<"\n Invalid Credentials !!";
  245. cout<<"\n Press any key for Main Menu..";
  246. getchar(); getchar();
  247. return 0;
  248. }
  249.  
  250. int goBack = 0;
  251. while(1)
  252. {
  253. system("cls");
  254.  
  255. cout<<"\n 1 Mark Attendance fo Today ";
  256. cout<<"\n 2 Count my Attendance";
  257. cout<<"\n 0. Go Back <- \n";
  258. int choice;
  259.  
  260. cout<<"\n Enter you choice: ";
  261. cin>>choice;
  262.  
  263. switch(choice)
  264. {
  265. case 1: markMyAttendance(username); break;
  266. case 2: countMyAttendance(username); break;
  267. case 0: goBack = 1;break;
  268. default: cout<<"\n Invalid choice. Enter again ";
  269. getchar();
  270. }
  271.  
  272. if(goBack == 1)
  273. {
  274. break; //break the loop
  275. }
  276.  
  277. }
  278.  
  279. }
  280.  
  281. int markMyAttendance(string username)
  282. {
  283. cout<<"\n Mark Attendance for today !!";
  284.  
  285. cout<<"\n Please any key to continue..";
  286.  
  287. getchar();getchar();
  288.  
  289. return 0;
  290. }
  291.  
  292. int countMyAttendance(string username)
  293. {
  294. cout<<"\n Count my attendace for today !!";
  295.  
  296. cout<<"\n Please any key to continue..";
  297.  
  298. getchar();getchar();
  299.  
  300. return 0;
  301. }
  302.  
  303. int deleteAllStudents()
  304. {
  305. cout<<"\n In delete all students !!";
  306.  
  307. cout<<"\n Please any key to continue..";
  308.  
  309. getchar(); getchar();
  310. return 0;
  311. }
  312.  
  313.  
  314. int checkListOfStudentRegistered()
  315. {
  316. cout<<"\n List of All registered registered !!";
  317.  
  318. cout<<"\n Please any key to continue..";
  319. getchar(); getchar();
  320. return 0;
  321. }
  322.  
  323. int getListOfStudentsWithTheirPresenseCount()
  324. {
  325. cout<<"\n All Students with their Presense count !!";
  326.  
  327. cout<<"\n Please any key to continue..";
  328. getchar(); getchar();
  329. return 0;
  330. }
  331.  
  332. int checkListOfStudentsRegistered(){
  333. cout<<"\n ---------- Check List of Student Registered by Username----------- ";
  334.  
  335. //check if record already exist..
  336. ifstream read;
  337. read.open("db.dat");
  338.  
  339. if(read)
  340. { int recordFound =0;
  341. string line;
  342. while(getline(read, line)) {
  343.  
  344. char name[100];
  345. strcpy(name, line.c_str());
  346. char onlyname[100];
  347. strncpy(onlyname, name, (strlen(name) - 4));
  348. cout<<" \n " << onlyname;
  349.  
  350. }
  351. read.close();
  352. }
  353. else
  354. {
  355. cout<<"\n No Record found :(";
  356. }
  357.  
  358.  
  359. cout<<"\n Please any key to continue..";
  360. getchar(); getchar();
  361. return 0;
  362. }
  363.  
  364.  
  365. int registerStudent()
  366. {
  367. cout<<"\n ----- Form to Register Student ---- \n";
  368.  
  369. string name, username, password, rollno, address, father, mother;
  370.  
  371. cout<<"\n Enter Name : "; cin>>name;
  372.  
  373. cout<<"\n Enter Username : "; cin>>username;
  374.  
  375.  
  376. cout<<"\n Enter password : "; cin>>password;
  377.  
  378. cout<<"\n Enter rollno : "; cin>>rollno;
  379. getchar();
  380.  
  381. char add[100];
  382. cout<<"\n Enter address : "; cin.getline(add, 100);
  383.  
  384. cout<<"\n Enter father : "; cin>>father;
  385.  
  386. cout<<"\n Enter mother : "; cin>>mother;
  387.  
  388. //check if record already exist..
  389. ifstream read;
  390. read.open("db.dat");
  391.  
  392. if(read)
  393. { int recordFound =0;
  394. string line;
  395. while(getline(read, line)) {
  396. if(line == username+".dat" )
  397. {
  398. recordFound = 1 ;
  399. break;
  400. }
  401. }
  402. if(recordFound == 1)
  403. {
  404. cout<<"\n Username already Register. Please choose another username ";
  405. getchar(); getchar();
  406. delay();
  407. read.close();
  408. return 0;
  409. }
  410. }
  411. read.close();
  412.  
  413. ofstream out;
  414. out.open("db.dat", ios::app);
  415. out<<username+".dat"<<"\n";
  416. out.close();
  417.  
  418. ofstream out1;
  419. string temp = username+".dat";
  420. out1.open(temp.c_str());
  421. out1<<name<<"\n"; out1<<username<<"\n"; out1<<password<<"\n";
  422. out1<<rollno<<"\n"; out1<<add<<"\n"; out1<<father<<"\n";
  423. out1<<mother<<"\n";
  424. out1.close();
  425.  
  426. cout<<"\n Student Registered Successfully !!";
  427.  
  428. cout<<"\n Please any key to continue..";
  429. getchar(); getchar();
  430. return 0;
  431. }
  432.  
  433.  
  434.  
  435.  
  436.  
  437. int main(int argc, char** argv) {
  438.  
  439. while(1)
  440. {
  441. system("cls");
  442.  
  443. cout<<"\t\t\t\t\t Attendance Management System \n";
  444. cout<<"-------------------------------------------------------------------------\n\n";
  445.  
  446. cout<<"1. Student Login\n";
  447. cout<<"2. Admin Login\n";
  448.  
  449. cout<<"0. Exit\n";
  450. int choice;
  451.  
  452. cout<<"\n Enter you choice: ";
  453. cin>>choice;
  454.  
  455. switch(choice)
  456. {
  457. case 1: studentLogin(); break;
  458. case 2: adminLogin(); break;
  459. case 0:
  460. while(1)
  461. {
  462. system("cls");
  463. cout<<"\n Are you sure, you want to exit? y | n \n";
  464. char ex;
  465. cin>>ex;
  466. if(ex == 'y' || ex == 'Y')
  467. exit(0);
  468. else if(ex == 'n' || ex == 'N')
  469. {
  470. break;
  471. }
  472. else{
  473.  
  474. cout<<"\n Invalid choice !!!";
  475. getchar();
  476. }
  477.  
  478.  
  479. } break;
  480.  
  481. default: cout<<"\n Invalid choice. Enter again ";
  482. getchar();
  483.  
  484. }
  485.  
  486. }
  487.  
  488. return 0;
  489. }
Add Comment
Please, Sign In to add comment