Guest User

CS Project

a guest
Jan 23rd, 2017
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.42 KB | None | 0 0
  1. #include<fstream.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. #include<stdio.h>
  5. #include<string.h>
  6. #include<iomanip.h>
  7. #include<ctype.h>
  8. class practical
  9. {
  10. int adno;
  11. char name[100];
  12. char projname[100];
  13. float projmark;
  14. float vivamark;
  15. float progmark;
  16. float assignmark;
  17. float totmark;
  18. public:
  19. void input()
  20. {
  21. cout<<"\n\t\t\tEnter Admission Number: ";
  22. cin>>adno;
  23. cout<<"\t\t\tEnter Name of Student: ";
  24. gets(name);
  25. cout<<"\t\t\tEnter Name of Project: ";
  26. gets(projname);
  27. cout<<"\t\t\tEnter Marks obtained in VIVA: ";
  28. cin>>vivamark;
  29. cout<<"\t\t\tEnter Marks obtained from Project: ";
  30. cin>>projmark;
  31. cout<<"\t\t\tEnter Marks obtained from Program: ";
  32. cin>>progmark;
  33. cout<<"\t\t\tEnter Marks obtained from Assignment: ";
  34. cin>>assignmark;
  35. totmark=vivamark+projmark+progmark+assignmark;
  36. }
  37. void output()
  38. {
  39. cout<<setw(5)<<adno<<setw(10)<<name<<setw(15)<<projname<<setw(10)<<vivamark<<setw(10)<<projmark<<setw(10)<<progmark<<setw(10)<<assignmark<<setw(10)<<totmark<<endl;
  40. }
  41. int getad()
  42. {
  43. return adno;
  44. }
  45. char* getname()
  46. {
  47. return name;
  48. }
  49. char* getproj()
  50. {
  51. return projname;
  52. }
  53. float getviva()
  54. {
  55. return vivamark;
  56. }
  57. float getprojmk()
  58. {
  59. return projmark;
  60. }
  61. float getprogmk()
  62. {
  63. return progmark;
  64. }
  65. float getassign()
  66. {
  67. return assignmark;
  68. }
  69. float gettotal()
  70. {
  71. return totmark;
  72. }
  73. void modify()
  74. {
  75. cout<<"\t\t\tEnter Name of Student: ";
  76. gets(name);
  77. cout<<"\t\t\tEnter Name of Project: ";
  78. gets(projname);
  79. cout<<"\t\t\tEnter Marks obtained in VIVA: ";
  80. cin>>vivamark;
  81. cout<<"\t\t\tEnter Marks obtained from Project: ";
  82. cin>>projmark;
  83. cout<<"\t\t\tEnter Marks obtained from Program: ";
  84. cin>>progmark;
  85. cout<<"\t\t\tEnter Marks obtained from Assignment: ";
  86. cin>>assignmark;
  87. totmark=vivamark+projmark+progmark+assignmark;
  88. }
  89. };
  90. void header()
  91. {
  92. clrscr();
  93. cout<<"******************************** Display Details *****************************\n";
  94. cout<<"\n"<<setw(5)<<"Ad NO"<<setw(10)<<"Name"<<setw(15)<<"Proj.Name"<<setw(10)<<"VivaMark"<<setw(10)<<"Proj.Mark"<<setw(10)<<"Prog.Mark"<<setw(10)<<"Ass.Mark"<<setw(10)<<"Tot.Mark"<<endl;
  95. }
  96.  
  97. void addrec()
  98. {
  99. clrscr();
  100. fstream f1;
  101. f1.open("practical.dat",ios::app|ios::binary);
  102. practical p1;
  103. p1.input();
  104. f1.write((char*)&p1,sizeof(p1));
  105. f1.close();
  106. }
  107. void disprec()
  108. {
  109. clrscr();
  110. fstream f1;
  111. f1.open("practical.dat",ios::in|ios::binary);
  112. practical p1;
  113. header();
  114. if(f1==NULL)
  115. cout<<"Error in Loading"<<endl;
  116. else
  117. {
  118. int x=0;
  119. while(f1.read((char*)&p1,sizeof(p1)))
  120. {
  121. p1.output();
  122. x++;
  123. }
  124. cout<<"\n\n\n\t\t\tTotal Number of Students: "<<x<<endl;
  125. }
  126. f1.close();
  127. }
  128. void sadno()
  129. {
  130. clrscr();
  131. fstream f1;
  132. practical p1;
  133. f1.open("practical.dat",ios::in|ios::binary);
  134. if(f1==NULL)
  135. cout<<"\t\t\tError in Loading"<<endl;
  136. else
  137. {
  138. int a,x=0;
  139. cout<<"\t\t\tEnter Admission Number to search for: ";
  140. cin>>a;
  141. header();
  142. while(f1.read((char*)&p1,sizeof(p1)))
  143. {
  144. if(p1.getad()==a)
  145. {
  146. p1.output();
  147. x=1;
  148. }
  149. }
  150. if(x==0)
  151. cout<<"\n\n\n\t\t\tAdmission Number does not exist"<<endl;
  152. }
  153. f1.close();
  154. }
  155. void sname()
  156. {
  157. clrscr();
  158. fstream f1;
  159. practical p1;
  160. f1.open("practical.dat",ios::in|ios::binary);
  161. if(f1==NULL)
  162. cout<<"\t\t\tError in Loading"<<endl;
  163. else
  164. {
  165. int x=0;
  166. char name[100];
  167. cout<<"\t\t\tEnter Name to search for: ";
  168. gets(name);
  169. header();
  170. while(f1.read((char*)&p1,sizeof(p1)))
  171. {
  172. if(strcmpi(p1.getname(),name)==0)
  173. {
  174. p1.output();
  175. x=1;
  176. }
  177. }
  178. if(x==0)
  179. cout<<"\n\n\t\t\tName does not exist"<<endl;
  180. }
  181. f1.close();
  182. }
  183.  
  184. void sproj()
  185. {
  186. clrscr();
  187. fstream f1;
  188. practical p1;
  189. f1.open("practical.dat",ios::in|ios::binary);
  190. if(f1==NULL)
  191. cout<<"\t\t\tError in Loading"<<endl;
  192. else
  193. {
  194. int x=0;
  195. char proj[100];
  196. cout<<"\t\t\tEnter Project Name to search for: ";
  197. gets(proj);
  198. header();
  199. while(f1.read((char*)&p1,sizeof(p1)))
  200. {
  201. if(strcmpi(p1.getproj(),proj)==0)
  202. {
  203. p1.output();
  204. x=1;
  205. }
  206. }
  207. if(x==0)
  208. cout<<"\n\n\t\t\tProject Name does not exist"<<endl;
  209. }
  210. f1.close();
  211. }
  212. void rangemark()
  213. {
  214. clrscr();
  215. fstream f1;
  216. practical p1;
  217. f1.open("practical.dat",ios::in|ios::binary);
  218. if(f1==NULL)
  219. cout<<"\t\t\tError in Loading"<<endl;
  220. else
  221. {
  222. int x=0;
  223. int minmk,maxmk;
  224. cout<<"\t\t\tEnter Minimum Mark: ";
  225. cin>>minmk;
  226. cout<<"\t\t\tEnter Maximum Mark: ";
  227. cin>>maxmk;
  228. header();
  229. while(f1.read((char*)&p1,sizeof(p1)))
  230. {
  231. if(p1.gettotal()>=minmk && p1.gettotal()<=maxmk)
  232. {
  233. p1.output();
  234. ++x;
  235. }
  236. }
  237. if(x==0)
  238. cout<<"\n\n\t\t\tNo Student in Range"<<endl;
  239. else
  240. cout<<"\n\n\t\t\t"<<x<<" is the no. of Students who secured within "<<minmk<<" - "<<maxmk<<endl;
  241. }
  242.  
  243. f1.close();
  244. }
  245. void topper_lower()
  246. {
  247. clrscr();
  248. fstream f1;
  249. practical p1,min,max;
  250. f1.open("practical.dat",ios::in|ios::binary);
  251. if(f1==NULL)
  252. cout<<"\t\t\tError in Loading"<<endl;
  253. else
  254. {
  255.  
  256. f1.read((char*)&p1,sizeof(p1)) ;
  257. min=max=p1;
  258. while(f1.read((char*)&p1,sizeof(p1)))
  259. {
  260. if(p1.gettotal()>max.gettotal())
  261. {
  262. max=p1;
  263. }
  264. if(p1.gettotal()<min.gettotal())
  265. {
  266. min=p1;
  267. }
  268. }
  269. cout<<"\n\n\t\t\tHighest Scorer: "<<endl;
  270. header();
  271. max.output();
  272. cout<<"\n\n\n\n\t\t\tLowest Scorer: "<<endl;
  273. header();
  274. min.output();
  275. }
  276.  
  277. f1.close();
  278. }
  279. void fail()
  280. {
  281. clrscr();
  282. fstream f1;
  283. practical p1;
  284. f1.open("practical.dat",ios::in|ios::binary);
  285. if(f1==NULL)
  286. cout<<"\t\t\tError in Loading"<<endl;
  287. else
  288. {
  289. int x=0;
  290. header();
  291. while(f1.read((char*)&p1,sizeof(p1)))
  292. {
  293. if(p1.gettotal()<=10)
  294. {
  295. p1.output();
  296. ++x;
  297. }
  298. }
  299. if(x==0)
  300. cout<<"\n\n\t\t\tNo Student Failed"<<endl;
  301. else
  302. cout<<"\n\n\t\t\t"<<x<<" number of Students failed"<<endl;
  303. }
  304. f1.close();
  305. }
  306. void removerec()
  307. {
  308. clrscr();
  309. fstream f1,f2;
  310. practical p1;
  311. f1.open("practical.dat",ios::in|ios::binary);
  312. f2.open("temp.dat",ios::out|ios::binary);
  313. if(f1==NULL)
  314. cout<<"\t\t\tError in Loading"<<endl;
  315. else
  316. {
  317. int a,x=0;
  318. cout<<"\t\t\tEnter Admission Number to Delete: ";
  319. cin>>a;
  320. while(f1.read((char*)&p1,sizeof(p1)))
  321. {
  322. if(p1.getad()!=a)
  323. {
  324. f2.write((char *)&p1,sizeof(p1));
  325.  
  326. }
  327. else
  328. {
  329. clrscr();
  330. char ch;
  331. x=1;
  332. header();
  333. p1.output();
  334. cout<<"\n\n\t\t\tConfirm Delete (Y/N): ";
  335. cin>>ch;
  336. if(ch!='y'&&ch!='Y')
  337. {
  338. f2.write((char *)&p1,sizeof(p1));
  339. cout<<"\n\n\t\t\tRecord Not Deleted ";
  340. }
  341. else
  342. cout<<"\n\n\t\t\tRecord Deleted ";
  343. }
  344. }
  345. if(x==0)
  346. cout<<"\n\n\t\t\tAdmission Number does not exist."<<endl;
  347. f1.close();
  348. f2.close();
  349. remove("practical.dat");
  350. rename("temp.dat","practical.dat");
  351. }
  352. f1.close();
  353. }
  354. void modifyrec()
  355. {
  356. clrscr();
  357. fstream f1;
  358. practical p1;
  359. f1.open("practical.dat",ios::in|ios::out|ios::binary);
  360. if(f1==NULL)
  361. cout<<"\t\t\tError in Loading"<<endl;
  362. else
  363. {
  364. int a,x=0,pos;
  365. cout<<"\t\t\tEnter Admission Number for Edit : ";
  366. cin>>a;
  367. while(f1.read((char*)&p1,sizeof(p1)))
  368. {
  369. if(p1.getad()==a)
  370. {
  371. cout<<"\n\t\t\tDetails of "<<a<<" are follows "<<endl;
  372. header();
  373. p1.output();
  374. cout<<"\n\t\t\tEnter new value for "<<endl;
  375. p1.modify();
  376. pos=f1.tellp();
  377. f1.seekp(pos-sizeof(p1));
  378. f1.write((char *)&p1,sizeof(p1));
  379. x=1;
  380. }
  381. }
  382.  
  383. if(x==0)
  384. cout<<"\n\n\t\t\tAdmission Number does not exist"<<endl;
  385. }
  386. f1.close();
  387. }
  388. void mainmenu()
  389. {
  390. clrscr();
  391. int a;
  392.  
  393. clrscr();
  394. do
  395. {
  396. clrscr();
  397. cout<<endl<<endl<<endl<<endl<<endl<<endl<<"\t\t";
  398. for(int i=1;i<50;i++)
  399. cout<<"*";
  400. cout<<endl;
  401. cout<<"\t\t*\t1-Add Record\t\t\t\t*"<<endl;
  402. cout<<"\t\t*\t2-Display Record\t\t\t*"<<endl;
  403. cout<<"\t\t*\t3-Search by Admission Number\t\t*"<<endl;
  404. cout<<"\t\t*\t4-Search by Student Name\t\t*"<<endl;
  405. cout<<"\t\t*\t5-Search by Project Name\t\t*"<<endl;
  406. cout<<"\t\t*\t6-Search by Mark Range\t\t\t*"<<endl;
  407. cout<<"\t\t*\t7-Display Highest & Lowest Records\t*"<<endl;
  408. cout<<"\t\t*\t8-Display Records of Failed Students\t*"<<endl;
  409. cout<<"\t\t*\t9-Delete Record\t\t\t\t*"<<endl;
  410. cout<<"\t\t*\t10-Modify Record\t\t\t*"<<endl;
  411. cout<<"\t\t";
  412. for(i=1;i<50;i++)
  413. cout<<"*";
  414. cout<<endl;
  415.  
  416. cout<<"\t\t\t\tEnter your option:\n\t\t\t\t";
  417. cin>>a;
  418. switch(a)
  419. {
  420. case 1:
  421. addrec();
  422. break;
  423. case 2:
  424. header();
  425. disprec();
  426. break;
  427. case 3:
  428. sadno();
  429. break;
  430. case 4:
  431. sname();
  432. break;
  433. case 5:
  434. sproj();
  435. break;
  436. case 6:
  437. rangemark();
  438. break;
  439. case 7:
  440. topper_lower();
  441. break;
  442. case 8:
  443. fail();
  444. break;
  445. case 9:
  446. removerec();
  447. break;
  448. case 10:
  449. modifyrec();
  450. break;
  451. case 0:
  452. cout<<"\n\t\t\t\tThank You.";
  453. getch();
  454. exit(0);
  455.  
  456. }
  457. cout<<"\n\n\t\t\tPress any key to continue ";
  458. getch();
  459. }while(a!=0);
  460.  
  461.  
  462. }
  463. char *getpass()
  464. {
  465. char pass[200],ch;
  466. int i=0;
  467. ch=getch();
  468. while(ch!=13)
  469. {
  470. cout<<"*";
  471. pass[i++]=ch;
  472. ch=getch();
  473. }
  474. pass[i]=NULL;
  475. return pass;
  476. }
  477. class login
  478. {
  479. int id;
  480. char name[100],pass[100];
  481. public:
  482. int registration(int);
  483. void show();
  484. void change();
  485. int retid()
  486. {
  487. return id;
  488. }
  489. char *retpass()
  490. {
  491. return pass;
  492. }
  493. };
  494. int lastid()
  495. {
  496. int x=0;
  497. login l1;
  498. fstream f1("login.dat",ios::in|ios::binary);
  499. if(f1!=NULL)
  500. {
  501. while(f1.read((char *)&l1,sizeof(l1)))
  502. {
  503. x=l1.retid();
  504. }
  505. }
  506. return x+1;
  507. }
  508. int login::registration(int x)
  509. {
  510. clrscr();
  511. int f=0;
  512. id=x;
  513. char p1[100],p2[100];
  514. cout<<"\n\n\n\n\n\t\t\tEnter Username:";
  515. cin>>name;
  516. cout<<"\n\n\n\t\t\tEnter Password:";
  517. strcpy(p1,getpass());
  518. cout<<"\n\n\n\n\t\t\tConfirm Password:";
  519. strcpy(p2,getpass());
  520. if(strcmp(p1,p2)==0)
  521. {
  522. f=1;
  523. strcpy(pass,p1);
  524. clrscr();
  525. cout<<"\n\n\n\n\n\n\n\t\t\tLogin ID:"<<id<<endl<<"\t\t\tUsername:"<<name<<endl;
  526. }
  527. else
  528. {
  529. clrscr();
  530. cout<<"\n\n\n\tInvalid Password ";
  531. }
  532. return f;
  533. }
  534. void login::show()
  535. {
  536. clrscr();
  537. cout<<"\n\n\t\t\tID:"<<id;
  538. cout<<"\n\t\t\tUserName:"<<name;
  539. cout<<"\n\t\t\tPassword:"<<pass<<endl;
  540. }
  541. void login::change()
  542. {
  543. clrscr();
  544. cout<<"\n\n\t\t\tUsername:"<<name<<"\n\t\t\tEnter New Name:";
  545. cin>>name;
  546. cout<<"\n\t\t\tPassword:"<<pass<<"\n\t\t\tEnter New Password:";
  547. strcpy(pass,getpass());
  548. }
  549. void addlogin()
  550. {
  551. clrscr();
  552. fstream f1;
  553. f1.open("login.dat",ios::app|ios::binary);
  554. login l1;
  555. if(l1.registration(lastid())==1)
  556. {
  557. f1.write((char *)&l1,sizeof(l1));
  558. }
  559. f1.close();
  560. }
  561. void displaylogin()
  562. {
  563. clrscr();
  564. fstream f1;
  565. int id,x=0;
  566. char pass[100];
  567. f1.open("login.dat",ios::in|ios::binary);
  568. login l1;
  569. cout<<"\n\n\n\n\t\t\tEnter ID:";
  570. cin>>id;
  571. cout<<"\n\n\n\t\t\tEnter Password:";
  572. strcpy(pass,getpass());
  573. while(f1.read((char *)&l1,sizeof(l1)))
  574. {
  575. if(l1.retid()==id && strcmp(l1.retpass(),pass)==0)
  576. {
  577. l1.show();
  578. cout<<"\n\n\n\n\n\n\t\t\tPress any key for Main Menu ";
  579. getch();
  580. mainmenu();
  581. x=1;
  582. }
  583. }
  584. if(x==0)
  585. {
  586. clrscr();
  587. cout<<"\n\n\n\n\t\t\tInvalid Id ";
  588. }
  589. f1.close();
  590. }
  591. void modifylogin()
  592. {
  593. clrscr();
  594. fstream f1;
  595. int id,x=0;
  596. char pass[100];
  597. f1.open("login.dat",ios::in|ios::out|ios::binary);
  598. login l1;
  599. cout<<"\n\n\n\n\t\t\tEnter ID:";
  600. cin>>id;
  601. cout<<"\n\n\n\t\t\tEnter Password:";
  602. strcpy(pass,getpass());
  603. while(f1.read((char *)&l1,sizeof(l1)))
  604. {
  605. if(l1.retid()==id && strcmp(l1.retpass(),pass)==0)
  606. {
  607. l1.change();
  608. f1.seekp(f1.tellp()-sizeof(l1));
  609. f1.write((char *)&l1,sizeof(l1));
  610. x=1;
  611. }
  612. }
  613. if(x==0)
  614. cout<<"\n\t\t\tInvalid Id ";
  615. f1.close();
  616. }
  617. void deletelogin()
  618. {
  619. clrscr();
  620. fstream f1,f2;
  621. login l1;
  622. char pass[100];
  623. f1.open("login.dat",ios::in|ios::binary);
  624. f2.open("temp.dat",ios::out|ios::binary);
  625. if(f1==NULL)
  626. cout<<"Error in Loading"<<endl;
  627. else
  628. {
  629. int a,x=0;
  630. cout<<"\n\t\t\tEnter Login ID for Deletion:";
  631. cin>>a;
  632. cout<<"\n\t\t\tEnter Password:";
  633. cin>>pass;
  634. while(f1.read((char*)&l1,sizeof(l1)))
  635. {
  636. if(l1.retid()!=a && strcmp(l1.retpass(),pass)!=0)
  637. {
  638. f2.write((char *)&l1,sizeof(l1));
  639.  
  640. }
  641. else
  642. {
  643. clrscr();
  644. char ch;
  645. x=1;
  646.  
  647. l1.show();
  648. cout<<"\n\n\t\t\tConfirm Delete (Y/N): ";
  649. cin>>ch;
  650. if(ch!='y'&&ch!='Y')
  651. {
  652. f2.write((char *)&l1,sizeof(l1));
  653. cout<<"\n\n\t\t\tRecord Not Deleted";
  654. }
  655. else
  656. cout<<"\n\n\t\t\tRecord Deleted";
  657. }
  658. }
  659. if(x==0)
  660. cout<<"\n\n\t\t\tID does not exist."<<endl;
  661. f1.close();
  662. f2.close();
  663. remove("login.dat");
  664. rename("temp.dat","login.dat");
  665. }
  666. f1.close();
  667. }
  668.  
  669. void main()
  670. {
  671.  
  672. int a;
  673. clrscr();
  674. do
  675. {
  676. clrscr();
  677. cout<<endl<<endl<<endl<<endl<<endl<<endl<<"\t\t";
  678. for(int i=1;i<50;i++)
  679. cout<<"*";
  680. cout<<endl;
  681. cout<<"\t\t*\t\t1-New User\t\t\t*"<<endl;
  682. cout<<"\t\t*\t\t2-Log In\t\t\t*"<<endl;
  683. cout<<"\t\t*\t\t3-Modify User\t\t\t*"<<endl;
  684. cout<<"\t\t*\t\t4-Delete User\t\t\t*"<<endl;
  685. cout<<"\t\t*\t\t0-Exit\t\t\t\t*"<<endl;
  686. cout<<"\t\t";
  687. for(i=1;i<50;i++)
  688. cout<<"*";
  689. cout<<endl;
  690.  
  691. cout<<"\t\t\t\tEnter your option:\n\t\t\t\t";
  692. cin>>a;
  693. switch(a)
  694. {
  695. case 1:
  696. addlogin();
  697. break;
  698. case 2:
  699. displaylogin();
  700. break;
  701. case 3:
  702. modifylogin();
  703. break;
  704. case 4:
  705. deletelogin();
  706. break;
  707. case 0:
  708. cout<<"\n\t\t\t\tThank You.";
  709. getch();
  710. exit(0);
  711.  
  712. }
  713. cout<<"\n\n\n\n\t\t\tPress any key to continue ";
  714. getch();
  715. }while(a!=0);
  716. getch();
  717. }
Add Comment
Please, Sign In to add comment