Guest User

Untitled

a guest
Mar 23rd, 2012
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.46 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #pragma hdrstop
  4. #pragma argsused
  5.  
  6. #include <stdio.h>
  7. #include <iostream.h>
  8. #include <conio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <fstream.h>
  12.  
  13. //---------------------------------------------------------------------------
  14. class graphic{
  15. public:
  16. friend void draw_rect(int x, int y, int x1, int y1, int type, int color);
  17. friend void draw_table(int x,int y,int x1,int y1);
  18. friend void show_add_stud();
  19. };
  20.  
  21. //---------------------------------------------------------------------------
  22. class base_menu{
  23. protected:
  24. int selected;
  25. int rec;
  26. char mm [5][20];
  27. int kx,ky;
  28. public:
  29. base_menu(){selected=0;}
  30. void show(int x);
  31. void choose();
  32. void virtual keypress() {}
  33. };
  34.  
  35. //---------------------------------------------------------------------------
  36. void base_menu::show(int x)
  37. {selected=x;
  38. int i;
  39. for (i=0; i<rec; i++)
  40. {if (i==x-1) {textbackground(4);}
  41. gotoxy(kx,ky+i);
  42. cprintf(mm[i]);
  43. textbackground(0);}
  44. choose();}
  45.  
  46. //---------------------------------------------------------------------------
  47. void base_menu::choose(){
  48. char c;
  49. c=getch();
  50. if (c==80) {selected++; if (selected>rec) selected=1; show(selected); keypress();}
  51. if (c==72) {selected--; if (selected<1) selected=rec; show(selected); keypress();}
  52. if (c==13) keypress();
  53. if ((c!=72)&&(c!=80) && (c!=13)) choose();}
  54.  
  55.  
  56. //---------------------------------------------------------------------------
  57. class menu: virtual public base_menu{
  58. public:
  59. int x;
  60. void show(x){
  61. rec=4;
  62. strcpy(mm[0], "Add Student");
  63. strcpy(mm[1], "Show Students");
  64. strcpy(mm[2], "Sort Students");
  65. strcpy(mm[3], "Exit");
  66. draw_rect(30,10,49,17,2,7);
  67. kx=34; ky=12;
  68. base_menu::show(x);}
  69. void keypress();
  70. }m1;
  71.  
  72.  
  73. //---------------------------------------------------------------------------
  74. class search_menu: virtual public base_menu{
  75. public:
  76. int x;
  77. void show(x){rec=4;
  78. strcpy(mm[0], "By Name");
  79. strcpy(mm[1], "By Surname");
  80. strcpy(mm[2], "By Id");
  81. strcpy(mm[3], "Cancel");
  82. draw_rect(30,15,45,22,2,7);
  83. kx=34; ky=17;
  84. gotoxy(34,15); cout<<" Search ";
  85. base_menu::show(x);}
  86. void keypress();
  87. }sm1;
  88.  
  89.  
  90. //---------------------------------------------------------------------------
  91. class edit{
  92. public:
  93. char text[15];
  94. int ex,ey,ex1,ey1;
  95. int kolvo;
  96. int param;
  97. edit(){strcpy(text,"");}
  98. void get_string(int kolvo, int param );
  99. void virtual draw_edit(int x,int y,int x1,int y1) {edit(); ex=x; ey=y; ex1=x1; ey1=y1; draw_rect(ex,ey,ex1,ey1,1,7);}
  100. void focus(int color){draw_rect(ex,ey,ex1,ey1,1,color);gotoxy(1,1);}
  101. void virtual input_data(){draw_rect(ex,ey,ex1,ey1,1,6);
  102. strcpy(text,""); gotoxy(ex+1,ey+1); for (int i=0; i<ex1-ex; i++) cout<<" "; gotoxy(ex+1,ey+1); get_string(kolvo,param);
  103. int t;
  104. t=strcmp(text, "");if (t==0) input_data();}
  105. void clear_field(){gotoxy(ex+1,ey+1); for (int i=0; i<ex1-ex; i++) cout<<" ";}
  106. void clear_field(bool){strcpy(text,""); clear_field();};
  107. void draw_edit_text(){gotoxy(ex+1,ey+1); cout<<text;}
  108. }predm[10], edit_info[9],search_box;
  109.  
  110.  
  111. //---------------------------------------------------------------------------
  112. void edit::get_string(int kolvo, int k)
  113. {int count=0;
  114. char s;
  115. char g=32; char b=8;
  116. char str[2];
  117. str[1]='\0';
  118.  
  119. do
  120. {s=getch();
  121. if (s==27) continue;
  122.  
  123. if ((kolvo==2)|| (kolvo==4)) if ((s<48) || (s>57)) continue;
  124.  
  125. cout<<s;
  126.  
  127. if (s==13) {break;}
  128. if ((s==b)) {
  129. if ((count<=0)) { gotoxy(ex+1,ey+1); count=0; continue;}
  130. cout<<g; cout<<b;
  131. text[count-1]='\0'; count=count-1;
  132. continue;}
  133.  
  134. count=count+1;
  135. str[0]=s;
  136. strcat(text, str);
  137. }
  138. while (count<kolvo);
  139. s=13; cout<<s;
  140. focus(4);
  141. gotoxy(1,1);}
  142.  
  143.  
  144.  
  145. //---------------------------------------------------------------------------
  146. class button:public edit{
  147. public:
  148. button(){strcpy(text,"");}
  149. void draw_edit(int x,int y,int x1,int y1)
  150. {edit::draw_edit(x,y,x1,y1); gotoxy(ex+2,ey+1); cout<<text;}
  151. }bt_ok;
  152.  
  153.  
  154.  
  155. //---------------------------------------------------------------------------
  156. class int_edit: public edit{
  157. public:
  158. int mark;
  159. int_edit(){mark=0;}
  160. void input_int();
  161. void input_data() {draw_rect(ex,ey,ex1,ey1,1,6); mark=0;
  162. gotoxy(ex+1,ey+1); cout<<"  "; gotoxy(ex+1,ey+1); input_int(); focus(7);}
  163. void draw_edit_text() {gotoxy(ex+1,ey+1); if (mark!=0) cout<<mark;}
  164. void clear()
  165. {edit::clear_field(true); mark=0; draw_edit_text();}
  166. }ocenka[10];
  167.  
  168. //---------------------------------------------------------------------------
  169. void int_edit::input_int(){
  170. char c;
  171. c=getch();
  172. if ((c==50) || (c==51) || (c==52) || (c==53) ) {
  173. mark=c-48;
  174. cout<<mark;}
  175. else input_int();}
  176.  
  177.  
  178.  
  179. //---------------------------------------------------------------------------
  180. void draw_rect(int x, int y, int x1, int y1, int type, int color){
  181. char c; int i;
  182. textcolor(color);
  183. if (type==2) c=201; if (type==1) c=218; gotoxy(x,y); cprintf("%c",c);
  184. if (type==2) c=205; if (type==1) c=196; for(i=0; i<x1-x; i++) cprintf("%c",c);
  185. if (type==2) c=187; if (type==1) c=191; cprintf("%c",c);
  186. if (type==2) c=186; if (type==1) c=179; for(i=0; i<y1-1-y; i++) {gotoxy(x,y+1+i); cprintf("%c",c);}
  187. if (type==2) c=200; if (type==1) c=192; gotoxy(x,y1); cprintf("%c",c);
  188. if (type==2) c=205; if (type==1) c=196; for(i=0; i<x1-x; i++) cprintf("%c",c);
  189. if (type==2) c=188; if (type==1) c=217; cprintf("%c",c);
  190. if (type==2) c=186; if (type==1) c=179; for(i=0; i<y1-1-y; i++) {gotoxy(x1+1,y+1+i); cprintf("%c",c);}
  191. textcolor(7);}
  192.  
  193. //---------------------------------------------------------------------------
  194. void draw_table(int x,int y,int x1,int y1){
  195. draw_rect(x,y,x1,y1,2,7);
  196. char c;
  197. c=204; gotoxy(1,3); cout<<c;
  198. c=205; for (int i=1; i<x1; i++) {gotoxy(i+1,3); cout<<c;}
  199. c=185; cout<<c;
  200. c=209; gotoxy(9, 1); cout<<c;
  201.        gotoxy(25, 1); cout<<c;
  202.        gotoxy(45, 1); cout<<c;
  203.        gotoxy(67, 1); cout<<c;
  204. c=216; gotoxy(9, 3); cout<<c;
  205.        gotoxy(25, 3); cout<<c;
  206.        gotoxy(45, 3); cout<<c;
  207.        gotoxy(67, 3); cout<<c;
  208. c=179; for (int i=4; i<y1; i++) {gotoxy(9,i); cout<<c;}
  209.        for (int i=4; i<y1; i++) {gotoxy(25,i); cout<<c;}
  210.        for (int i=4; i<y1; i++) {gotoxy(45,i); cout<<c;}
  211.        for (int i=4; i<y1; i++) {gotoxy(67,i); cout<<c;}
  212.        gotoxy(9, 2); cout<<c;
  213.        gotoxy(25, 2); cout<<c;
  214.        gotoxy(45, 2); cout<<c;
  215.        gotoxy(67, 2); cout<<c;
  216.  
  217. c=207; gotoxy(9,y1); cout<<c;
  218.        gotoxy(25,y1); cout<<c;
  219.        gotoxy(45,y1); cout<<c;
  220.        gotoxy(67,y1); cout<<c;
  221.  
  222. gotoxy(4,2); cout<<"NUM";
  223. gotoxy(15,2); cout<<"NAME";
  224. gotoxy(32,2); cout<<"SURNAME";
  225. gotoxy(52,2); cout<<"OTCHESTVO";
  226. gotoxy(72,2); cout<<"ID";}
  227.  
  228. //---------------------------------------------------------------------------
  229. void show_add_stud(){ char c;
  230. char sp[7][10]={"NAME","SURNAME","OTCHESTVO","DD/MM/YY","FACULTET","GRUPPA","NUMBER"};
  231. draw_rect(1,1,78,44,2,7);
  232. c=209; gotoxy(28,1); cout<<c;
  233.        gotoxy(48,1); cout<<c;
  234. c=179; gotoxy(28,2);cout<<c;
  235.        gotoxy(48,2);cout<<c;
  236. c=192; gotoxy(28,3); cout<<c;
  237. c=196; for(int i=0; i<19;i++){cout<<c;}
  238. c=217; cout<<c;
  239. textcolor(2);
  240. gotoxy(33,2); cout<<"ADD STUDENT";
  241. gotoxy(13,2); cprintf("%s","INFO");
  242. gotoxy(58,2); cprintf("%s","SESSION 1");
  243.  
  244. int kkk=5;
  245. for (int i = 0; i < 7; i++) {
  246. gotoxy(4,kkk); cout<<sp[i];
  247. kkk=kkk+3;}
  248.  
  249.  
  250. int top=0; int left=0;
  251. for (int i=0; i<3; i++)
  252. {edit_info[i].kolvo=14;
  253. edit_info[i].draw_edit(15,4+top,30,6+top);
  254. top=top+3;}
  255.  
  256. for (int i=3; i<6; i++)
  257. {int k=0; if(i==5) k=2;
  258. edit_info[i].kolvo=2;
  259. if (i==5) {edit_info[i].kolvo=4;}
  260. edit_info[i].draw_edit(15+left,13,18+left+k,15);
  261. left=left+5;}
  262. top=0;
  263.  
  264. for (int i=6; i<9; i++)
  265. {edit_info[i].kolvo=14;
  266. edit_info[i].draw_edit(15,16+top,30,18+top);
  267. top=top+3;}
  268.  
  269. top=0; left=0;
  270. for (int i=0; i<10; i++)
  271. {predm[i].kolvo=14;
  272. gotoxy(50, 5+top); cout<<i+1;
  273. predm[i].draw_edit(52,4+top,67,6+top);
  274. top=top+3;}
  275.  
  276. top=0; left=0;
  277. for (int i=0; i<10; i++)
  278. {ocenka[i].mark=0;
  279. ocenka[i].draw_edit(69,4+top,71,6+top);
  280. top=top+3;}
  281.  
  282. strcpy(bt_ok.text,"SAVE");
  283. bt_ok.draw_edit(4,27,10,29);}
  284.  
  285.  
  286. //---------------------------------------------------------------------------
  287. class sessia{
  288. public:
  289. char predmet[15];
  290. int ocenka;
  291. };
  292.  
  293.  
  294. //---------------------------------------------------------------------------
  295. class student{private:
  296. char name[15];
  297. char surname[15];
  298. char otchestvo[15];
  299. int day, month, year;
  300. char facultet[15],gruppa[15], number[15];
  301. sessia ses[10][9];
  302. public:
  303. student() {clear_fields();}
  304.  
  305. //---------------------------------------------------------------------------
  306. void clear_edits()
  307. {for (int i=0; i < 9; i++) strcpy(edit_info[i].text,"");
  308. for (int i=0; i < 10; i++) {
  309. strcpy(predm[i].text, ""); ocenka[i].mark=0;}}
  310.  
  311. //---------------------------------------------------------------------------
  312. void clear_fields()
  313. {strcpy(name,""); strcpy(surname,""); strcpy(otchestvo,"");
  314. day=0; month=0; year=0;
  315. strcpy(facultet,""); strcpy(gruppa,""); strcpy(number,"");
  316. for (int j = 0; j < 9; j++)
  317. for (int i = 0; i < 10; i++) {
  318. strcpy(ses[i][j].predmet,""); ses[i][j].ocenka=0;}}
  319.  
  320. //---------------------------------------------------------------------------
  321. void update_session(int ses)
  322. {read_session(ses);
  323. for (int i = 0; i < 10; i++) {
  324. predm[i].clear_field();
  325. ocenka[i].clear_field();
  326. predm[i].draw_edit_text();
  327. ocenka[i].draw_edit_text();}}
  328.  
  329.  
  330. //---------------------------------------------------------------------------
  331. void input_stud(num) {student();
  332. int foc=1; int m=0; int ses=1;
  333. int flag=1;
  334. char key;
  335. update_session(ses);
  336. edit_info[foc-1].focus(4);
  337. do
  338. {key=getch();
  339. if (key==9) { flag++; if (flag>3) flag=1;
  340. switch (flag)   {
  341.     case 1: {foc=1; edit_info[foc-1].focus(4); bt_ok.focus(7); break;}
  342.     case 2: {edit_info[foc-1].focus(7); m=1; predm[0].focus(4); break;}
  343.     case 3: {for (int i = 0; i < 10; i++) predm[i].focus(7);
  344.     bt_ok.focus(4);
  345.     break;}     }
  346.             }
  347.  
  348. //Êëàâèøà âíèç
  349. if (key==80){
  350. if (flag==1) {foc++;
  351. if (foc>1) edit_info[foc-2].focus(7);
  352. if (foc>9) foc=1;
  353. edit_info[foc-1].focus(4); gotoxy(1,1);}
  354.  
  355. if (flag==2) {m++;
  356. if (m>1) predm[m-2].focus(7);
  357. if (m>10) m=1; predm[m-1].focus(4); gotoxy(1,1);}
  358. }
  359.  
  360. //Êëàâèøà ââåðõ
  361. if (key==72){
  362. if (flag==1){foc--;
  363. if (foc>=0) edit_info[foc].focus(7);
  364. if (foc==0) foc=9;
  365. edit_info[foc-1].focus(4); gotoxy(1,1);}
  366.  
  367. if (flag==2) {m--;
  368. if (m>=0) predm[m].focus(7);
  369. if (m<=0) m=10; predm[m-1].focus(4); gotoxy(1,1);}
  370. }
  371.  
  372. //Êëàâèøà âïðàâî
  373. if (key==77) if (flag==2) {
  374. write_session(ses); ses++;
  375. if (ses>9) {ses=1;}
  376. gotoxy(66,2); cprintf("%d",ses);
  377. update_session(ses);}
  378.  
  379. //Êëàâèøà âëåâî
  380. if (key==75) if (flag==2) {
  381. write_session(ses); ses--;
  382. if (ses<1) {ses=9;}
  383. gotoxy(66,2); cprintf("%d",ses);
  384. update_session(ses);}
  385.  
  386. //Óäàëèòü ïðåäìåò
  387. if (key==8) if (flag==2){
  388. predm[m-1].clear_field(true);
  389. ocenka[m-1].clear();
  390. }
  391.  
  392. if (key==13){
  393. if (flag==1) edit_info[foc-1].input_data();
  394. if (flag==2) {predm[m-1].input_data(); ocenka[m-1].input_data();}
  395. if (flag==3){
  396. write_session(ses);
  397. strcpy(name, edit_info[0].text);
  398. strcpy(surname, edit_info[1].text);
  399. strcpy(otchestvo, edit_info[2].text);
  400. strcpy(facultet, edit_info[6].text);
  401. strcpy(gruppa, edit_info[7].text);
  402. strcpy(number, edit_info[8].text);
  403. day=atoi(edit_info[3].text);
  404. month=atoi(edit_info[4].text);
  405. year=atoi(edit_info[5].text);
  406. write_stud(num);
  407. clear_edits();
  408. clrscr();
  409. m1.show(1);}}}
  410. while (key!=27);
  411. clrscr();
  412. m1.show(1);}
  413.  
  414. //---------------------------------------------------------------------------
  415. void output_stud(int x, int num) {
  416. gotoxy(4,x); cprintf("%d",num);
  417. gotoxy(11,x); cprintf(name);
  418. gotoxy(27,x); cprintf(surname);
  419. gotoxy(47,x); cprintf(otchestvo);
  420. gotoxy(69,x); cprintf(number);
  421. textbackground(0);}
  422.  
  423. //---------------------------------------------------------------------------
  424. void output_full_info(int num)
  425. {read_stud(num);
  426. show_add_stud();
  427. strcpy(edit_info[0].text, name);
  428. strcpy(edit_info[1].text, surname);
  429. strcpy(edit_info[2].text, otchestvo);
  430. strcpy(edit_info[6].text, facultet);
  431. strcpy(edit_info[7].text, gruppa);
  432. strcpy(edit_info[8].text, number);
  433. itoa(day, edit_info[3].text, 10);
  434. itoa(month, edit_info[4].text, 10);
  435. itoa(year, edit_info[5].text, 10);
  436. gotoxy(30,2); for (int i = 0; i < 18; i++) cout<<" ";
  437. gotoxy(33,2); cout<<"STUDENT # "<<num+1;
  438. for (int i=0; i<9; i++) edit_info[i].draw_edit_text();
  439. input_stud(num);
  440. clear_edits();}
  441.  
  442. //---------------------------------------------------------------------------
  443. void write_stud(int);
  444. void check_file();
  445. void set_pos(int);
  446. void read_stud(int);
  447. void delete_stud(int);
  448. void write_session(int);
  449. void read_session(int);
  450. void search(char *, int);
  451. void sort();
  452. static int count();
  453. static int count2();
  454.  
  455. //---------------------------------------------------------------------------
  456. void press(){ char g; int k=0; int kkk=1; int rec=10;
  457. vvod:
  458. g=getch();  div_t div_result; div_result = div( count(), 10 );
  459.  
  460.  if (count()>=10 & kkk<10) rec=10;
  461.  if (count()<10 & kkk<10) rec=count();
  462.  
  463. if (g==80) {k++; if (k>kkk+rec-2) k=kkk-1;
  464. vivod(rec,kkk, k); goto vvod;}
  465. if (g==72) {k--; if (k<kkk-1) k=kkk+rec-2;
  466. vivod(rec,kkk, k); goto vvod;}
  467.  
  468. if (g==77) {clrscr(); rec=10;
  469. if (kkk<count()-9) {kkk=kkk+10; k=kkk-1;}
  470. if (kkk+9>count()) {
  471. rec=div_result.rem; kkk=(div_result.quot*10)+1;}
  472. show_table(); vivod(rec,kkk, k); goto vvod;}
  473.  
  474. if ((g==75) & (kkk>-1)) {clrscr(); rec=10;
  475. if (kkk>=10) {kkk=kkk-10; k=kkk-1; }
  476. if (kkk+9>count()) {
  477. rec=div_result.rem; kkk=(div_result.quot*10)+1;}
  478. show_table();
  479. vivod(rec,kkk, k); goto vvod;}
  480.  
  481. if (g==115) {sm1.show(1);}
  482.  
  483. if (g==13) {clrscr(); output_full_info(k);}
  484. if (g==8) {delete_stud(k); clrscr(); check_file();}
  485. if ((g!=72)&&(g!=80) &&(g!=27) &&(g!=77)) goto vvod;
  486. if (g==27) clrscr(); m1.show(1);}
  487.  
  488.  
  489. //---------------------------------------------------------------------------
  490. void vivod(int count, int start, int vibor) {
  491. for (int i=start-1; i<count+start-1; i++) {
  492. student::read_stud(i);
  493. if (i==vibor) textbackground(4);
  494. student::output_stud(i+5-start,i+1); textbackground(0);}}
  495.  
  496.  
  497. //---------------------------------------------------------------------------
  498. void show_table(){draw_table(1,1,79,14);
  499. gotoxy(2,16); cout<<"Stydentov v baze: "<<count()<<"\n\n";
  500. char c;
  501. c=24; cout<<"\n "<<c; c=25; cout<<c; cout<<"        - Move students\n";
  502. c=27; cout<<" "<<c; c=26; cout<<c; cout<<"        - Move tables";
  503. cout<<"\n Enter     - Show Or Change";
  504. cout<<"\n Backspace - Delete Student";
  505. cout<<"\n S key     - Search";
  506. cout<<"\n A key     - Add Student";
  507. draw_rect(1,15,27,25,1,5);}
  508. }stud;
  509.  
  510.  
  511. //---------------------------------------------------------------------------
  512. void student::check_file(){
  513. ifstream file;
  514. file.open("student.txt");
  515. if (!file) {cout<<"No students"; getch(); clrscr(); file.close(); m1.show(1);}
  516. show_table();
  517. if (count()>=10) vivod(10,1, 0);
  518. if (count()<10) vivod(count(),1, 0);
  519. press();}
  520.  
  521.  
  522. //---------------------------------------------------------------------------
  523. void student::write_stud(int num)
  524. {ofstream file;
  525. file.open("student.txt", ios::in |ios::binary);
  526. file.seekp(num*sizeof(student));
  527. file.write((char*)this, sizeof(*this));
  528. file.close();}
  529.  
  530. //---------------------------------------------------------------------------
  531. void student::read_stud(int kolvo)
  532. {ifstream file;
  533. file.open("student.txt", ios::binary );
  534. file.seekg(kolvo*sizeof(student));
  535. file.read((char*)this, sizeof(*this));}
  536.  
  537. //---------------------------------------------------------------------------
  538. int student::count(){
  539. ifstream file;
  540. file.open("student.txt", ios::binary);
  541. file.seekg(0, ios::end);
  542. return (int)file.tellg()/sizeof(student);}
  543.  
  544. //---------------------------------------------------------------------------
  545. int student::count2(){
  546. ifstream file;
  547. file.open("temp.txt", ios::binary);
  548. file.seekg(0, ios::end);
  549. return (int)file.tellg()/sizeof(student);}
  550.  
  551. //---------------------------------------------------------------------------
  552. void student::delete_stud(int del){int i;
  553. ifstream file, file1;
  554. ofstream temp, temp1;
  555. file.open("student.txt", ios::binary );
  556. temp.open("temp.txt", ios::trunc | ios::ate| ios::in |ios::binary);
  557. for (i = 0; i < del; i++) {
  558. file.seekg(i*sizeof(student));
  559. file.read((char*)this, sizeof(*this));
  560. temp.write((char*)this, sizeof(*this));}
  561. for (i = del+1; i < count(); i++) {
  562. file.seekg(i*sizeof(student));
  563. file.read((char*)this, sizeof(*this));
  564. temp.write((char*)this, sizeof(*this));}
  565. file.close();
  566. temp.close();
  567. file1.open("temp.txt", ios::binary );
  568. temp1.open("student.txt", ios::trunc | ios::ate| ios::in |ios::binary);
  569. for (i = 0; i < count2(); i++) {
  570. file1.seekg(i*sizeof(student));
  571. file1.read((char*)this, sizeof(*this));
  572. temp1.write((char*)this, sizeof(*this));}
  573. file1.close();
  574. temp1.close();}
  575.  
  576. //---------------------------------------------------------------------------
  577. void student::write_session(int s)
  578. {for (int i = 0; i < 10; i++) {
  579. strcpy(ses[i][s-1].predmet, predm[i].text);
  580. ses[i][s-1].ocenka=ocenka[i].mark;}}
  581.  
  582. //---------------------------------------------------------------------------
  583. void student::read_session(int s)
  584. {for (int i = 0; i < 10; i++) {
  585. strcpy(predm[i].text, ses[i][s-1].predmet);
  586. ocenka[i].mark=ses[i][s-1].ocenka;}}
  587.  
  588. //---------------------------------------------------------------------------
  589. void student::search(char field[15], int type){
  590. int t;
  591. int c=0;
  592. for (int i = 0; i < count(); i++) {
  593. t=1; read_stud(i);
  594. switch (type) {
  595. case 0: {t=strcmp(name, field);
  596. if (t==0) {c++; output_stud(30+c,i+1);}}
  597. case 1: {t=strcmp(surname, field);
  598. if (t==0) {c++; output_stud(30+c,i+1);}}
  599. case 2: {t=strcmp(number, field);
  600. if (t==0) {c++; output_stud(30+c,i+1);}}
  601. }}
  602. if (c!=0) draw_rect(1,30,79,31+c,1,7);
  603. gotoxy(2,32+c);
  604. cout<<"\n\n Searching finished. Press ESC key to continue, Enter to Read Student";
  605. char vvod;
  606. do{vvod=getch();}
  607. while ((vvod!=13) && (vvod!=27));
  608. if (vvod==13){int ss;
  609. cout<<"\n Enter Student number: "; cin>>ss;
  610. clrscr(); output_full_info(ss-1);}
  611. if (vvod==27) clrscr(); stud.check_file();
  612. }
  613.  
  614. //---------------------------------------------------------------------------
  615. void student::sort(){
  616. bool flag;
  617. int kolvo=0;
  618. cout<<"              Spisok studentov, y kotorih hotya bi odna troyka\n";
  619. for (int i = 0; i < count(); i++) {
  620. read_stud(i);
  621. flag=false;
  622. for (int j = 0; j < 9; j++) {
  623. for (int k = 0; k < 10; k++) {
  624. if (ses[k][j].ocenka==0) {continue;}
  625. if (ses[k][j].ocenka==3) {flag=true;}}}
  626. if (flag==true) {kolvo++; output_stud(kolvo+5,i+1);}
  627. }
  628. draw_rect(1,5,78,6+kolvo,1,7);
  629. cout<<"\n\n\n\n   Press Enter Key...";
  630. getchar();
  631. clrscr();
  632. }
  633.  
  634.  
  635. // Ôóíêöèÿ íàæàòèÿ êëàâèø ãëàâíîãî ìåíþ.
  636. //---------------------------------------------------------------------------
  637. void menu::keypress(){
  638.         switch (selected)
  639.         {
  640.         case 1: {clrscr();
  641.                 stud.clear_fields(); stud.clear_edits();
  642.                 show_add_stud(); stud.input_stud(stud.count());
  643.                 clrscr(); show(1);}
  644.         case 2: {clrscr(); stud.check_file();}
  645.         case 3: {fflush(stdin); clrscr(); stud.sort(); show(1);}
  646.         case 4: {exit(1);}
  647.         default: keypress();
  648.         }
  649. }
  650.  
  651. //---------------------------------------------------------------------------
  652. void search_menu::keypress(){
  653.     switch (selected) {
  654.     case 1: {search_box.draw_edit(30,23,45,25); search_box.kolvo=14; search_box.input_data();
  655.     stud.search(search_box.text,0); stud.check_file();}
  656.     case 2: {search_box.draw_edit(30,23,45,25); search_box.kolvo=14; search_box.input_data();
  657.     stud.search(search_box.text,1); stud.check_file();}
  658.     case 3: {search_box.draw_edit(30,23,45,25); search_box.kolvo=14; search_box.input_data();
  659.     stud.search(search_box.text,2); stud.check_file();}
  660.     case 4: {clrscr(); stud.check_file();}}
  661. }
  662.  
  663. //---------------------------------------------------------------------------
  664. void main() {m1.show(1);}
  665. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment