Advertisement
Guest User

Untitled

a guest
Jul 28th, 2021
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.31 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. #include<stdlib.h>
  6. #include<string.h>
  7. #include<ctime>
  8. using namespace std;
  9. void signIn();
  10. void signUp();
  11. void admin();
  12.  
  13. int main(){
  14. int choicE;
  15. cout<<"====================================================="<<endl;
  16. cout<<"=============College Management System==============="<<endl;
  17. cout<<"====================================================="<<endl;
  18. cout<<endl<<endl;
  19. cout<<"1) Student sign in"<<endl;
  20. cout<<"2) Student sign up"<<endl;
  21. cout<<"3) Admin"<<endl<<endl;
  22. cout<<"Enter Your Choice: ";
  23. cin>>choicE;
  24.  
  25. switch(choicE)
  26. {
  27. case 1:
  28. signIn();
  29. break;
  30. case 2:
  31. signUp();
  32. break;
  33. case 3:
  34. admin();
  35. break;
  36. default:
  37. system("cls");
  38. cout<<"Wrong choice!\nTry again!"<<endl;
  39. main();
  40.  
  41. }
  42.  
  43.  
  44. return 0;
  45. }
  46. void signIn(){
  47. int counter,id, acount;
  48. string user,pass,u,p,m;
  49. system("cls");
  50. cout<<"please enter the following details"<<endl;
  51. cout<<"USERNAME :";
  52. cin>>user;
  53. cout<<"PASSWORD :";
  54. cin>>pass;
  55.  
  56. ifstream f("student.txt");
  57. while(f>>id>>u>>m>>p)
  58. {
  59. if(u==user && p==pass)
  60.  
  61. {
  62. counter=1;
  63. system("cls");
  64. }else
  65. {
  66. cout<<"Either username or password is incorrect";
  67. main();
  68. }
  69. }
  70. f.close();
  71. if(counter==1)
  72. {
  73. int choiCe;
  74. cout<<"\nWelcome"<<user<<"!"<<endl<<endl;
  75. cout<<"1) Ask Question"<<endl;
  76. cout<<"2) Check Messages"<<endl;
  77. cout<<"3) Account info"<<endl;
  78. cout<<"Enter anything else to exit."<<endl<<endl;
  79. cout<<"Enter your choice: ";
  80. cin>>choiCe;
  81. cout<<endl;
  82. if(choiCe==1){
  83. string question;
  84. cout<<"Enter Your Question: "<<endl;
  85. cin>>question;
  86. getline(cin, question);
  87. cout<<question<<endl;
  88. ofstream g("question.txt",ios::app);
  89. g<<question<<endl;
  90. cout<<"Question will be answered shortly. Come back later!"<<endl;
  91.  
  92. }else if(choiCe==2){
  93.  
  94. string q,q2,a;
  95. int count;
  96. ifstream y("question.txt");
  97. ifstream x("answer.txt");
  98. while(y>>q && x>>q2>>a)
  99. {
  100. if(q==q2)
  101. {
  102. count=1;
  103. }
  104. }
  105. y.close();
  106. x.close();
  107. if(count==1){
  108. cout<<q2<<a;
  109. }
  110. }else if(choiCe==3){
  111.  
  112. ifstream h("student.txt");
  113. while(h>>id>>u>>m>>p){
  114. if(true){
  115. acount=1;
  116. }
  117. }
  118. h.close();
  119. if(acount==1){
  120.  
  121. int no;
  122. cout<<"Major: "<<m<<endl;
  123. cout<<"Username: "<<u<<endl;
  124. cout<<"Password: "<<p<<endl;
  125. cout<<"Press 1 to exit: ";
  126. cin>>no;
  127. if(no==1){ //16777216
  128. main();
  129. }
  130. }
  131. }else{
  132. main();
  133. }
  134.  
  135.  
  136. }
  137.  
  138. }
  139. void signUp(){
  140. string nuser,npass, nmajor;
  141. string fname, lname;
  142. system("cls");
  143. cout<<"Enter First Name: ";
  144. cin>>fname;
  145. cout<<"\nEnter Last Name: ";
  146. cin>>lname;
  147. cout<<"\nCreate a Username: ";
  148. cin>>nuser;
  149. cout<<"\nEnter Major: ";
  150. cin>>nmajor;
  151. cout<<"\nEnter the password: ";
  152. cin>>npass;
  153. int id=rand();
  154. ofstream i("student.txt",ios::app);
  155. i<<id<<' '<<nuser<<' '<<nmajor<<' '<<npass<<endl;
  156. system("cls");
  157. cout<<"\nRegistration Sucessful\n";
  158. cout<<"Your ID is: "<<id<<"\n Remember it!";
  159. main();
  160. }
  161. void admin()
  162. {
  163. int adpass, choIce;
  164. cout<<"Enter Password: "<<adpass<<endl;
  165. if(adpass==1234)
  166. {
  167. cout<<"1) View Student Info"<<endl;
  168. cout<<"2) Answer Questions"<<endl;
  169. cout<<"3) Exit"<<endl<<endl;
  170. cout<<"Enter your choice: "<<choIce;
  171.  
  172. if(choIce==1)
  173. {
  174. int aid,acount,id;
  175. string u,m,p;
  176. cout<<"Enter student ID"<<aid;
  177. ifstream j("student.txt");
  178. while(j>>id>>u>>m>>p){
  179. if(id==aid){
  180. acount=1;
  181. }
  182. }
  183. j.close();
  184. if(acount==1){
  185. int no;
  186. cout<<"Major: "<<m<<endl;
  187. cout<<"Username: "<<u<<endl;
  188. cout<<"Password: "<<p<<endl;
  189. cout<<"Press 1 to exit: "<<no;
  190. if(no==1){
  191. main();
  192. }
  193. }
  194. }else if(choIce==2)
  195. {
  196. fstream l("question.txt");
  197.  
  198. if(l.is_open()){
  199. cout<<l.rdbuf();
  200. }
  201. l.close();
  202. string q,a;
  203. cout<<"Enter the question you would like to answer:"<<endl;
  204. getline(cin,q);
  205. cout<<"Enter the answer:"<<endl;
  206. getline(cin,a);
  207. ofstream z("answer.txt",ios::app);
  208. z<<q<<a<<endl;
  209. }else{
  210. main();
  211. }
  212. }
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement