Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #pragma hdrstop
- #pragma argsused
- #include <stdio.h>
- #include <iostream.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fstream.h>
- //---------------------------------------------------------------------------
- class graphic{
- public:
- friend void draw_rect(int x, int y, int x1, int y1, int type, int color);
- friend void draw_table(int x,int y,int x1,int y1);
- friend void show_add_stud();
- };
- //---------------------------------------------------------------------------
- class base_menu{
- protected:
- int selected;
- int rec;
- char mm [5][20];
- int kx,ky;
- public:
- base_menu(){selected=0;}
- void show(int x);
- void choose();
- void virtual keypress() {}
- };
- //---------------------------------------------------------------------------
- void base_menu::show(int x)
- {selected=x;
- int i;
- for (i=0; i<rec; i++)
- {if (i==x-1) {textbackground(4);}
- gotoxy(kx,ky+i);
- cprintf(mm[i]);
- textbackground(0);}
- choose();}
- //---------------------------------------------------------------------------
- void base_menu::choose(){
- char c;
- c=getch();
- if (c==80) {selected++; if (selected>rec) selected=1; show(selected); keypress();}
- if (c==72) {selected--; if (selected<1) selected=rec; show(selected); keypress();}
- if (c==13) keypress();
- if ((c!=72)&&(c!=80) && (c!=13)) choose();}
- //---------------------------------------------------------------------------
- class menu: virtual public base_menu{
- public:
- int x;
- void show(x){
- rec=4;
- strcpy(mm[0], "Add Student");
- strcpy(mm[1], "Show Students");
- strcpy(mm[2], "Sort Students");
- strcpy(mm[3], "Exit");
- draw_rect(30,10,49,17,2,7);
- kx=34; ky=12;
- base_menu::show(x);}
- void keypress();
- }m1;
- //---------------------------------------------------------------------------
- class search_menu: virtual public base_menu{
- public:
- int x;
- void show(x){rec=4;
- strcpy(mm[0], "By Name");
- strcpy(mm[1], "By Surname");
- strcpy(mm[2], "By Id");
- strcpy(mm[3], "Cancel");
- draw_rect(30,15,45,22,2,7);
- kx=34; ky=17;
- gotoxy(34,15); cout<<" Search ";
- base_menu::show(x);}
- void keypress();
- }sm1;
- //---------------------------------------------------------------------------
- class edit{
- public:
- char text[15];
- int ex,ey,ex1,ey1;
- int kolvo;
- int param;
- edit(){strcpy(text,"");}
- void get_string(int kolvo, int param );
- 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);}
- void focus(int color){draw_rect(ex,ey,ex1,ey1,1,color);gotoxy(1,1);}
- void virtual input_data(){draw_rect(ex,ey,ex1,ey1,1,6);
- 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);
- int t;
- t=strcmp(text, "");if (t==0) input_data();}
- void clear_field(){gotoxy(ex+1,ey+1); for (int i=0; i<ex1-ex; i++) cout<<" ";}
- void clear_field(bool){strcpy(text,""); clear_field();};
- void draw_edit_text(){gotoxy(ex+1,ey+1); cout<<text;}
- }predm[10], edit_info[9],search_box;
- //---------------------------------------------------------------------------
- void edit::get_string(int kolvo, int k)
- {int count=0;
- char s;
- char g=32; char b=8;
- char str[2];
- str[1]='\0';
- do
- {s=getch();
- if (s==27) continue;
- if ((kolvo==2)|| (kolvo==4)) if ((s<48) || (s>57)) continue;
- cout<<s;
- if (s==13) {break;}
- if ((s==b)) {
- if ((count<=0)) { gotoxy(ex+1,ey+1); count=0; continue;}
- cout<<g; cout<<b;
- text[count-1]='\0'; count=count-1;
- continue;}
- count=count+1;
- str[0]=s;
- strcat(text, str);
- }
- while (count<kolvo);
- s=13; cout<<s;
- focus(4);
- gotoxy(1,1);}
- //---------------------------------------------------------------------------
- class button:public edit{
- public:
- button(){strcpy(text,"");}
- void draw_edit(int x,int y,int x1,int y1)
- {edit::draw_edit(x,y,x1,y1); gotoxy(ex+2,ey+1); cout<<text;}
- }bt_ok;
- //---------------------------------------------------------------------------
- class int_edit: public edit{
- public:
- int mark;
- int_edit(){mark=0;}
- void input_int();
- void input_data() {draw_rect(ex,ey,ex1,ey1,1,6); mark=0;
- gotoxy(ex+1,ey+1); cout<<" "; gotoxy(ex+1,ey+1); input_int(); focus(7);}
- void draw_edit_text() {gotoxy(ex+1,ey+1); if (mark!=0) cout<<mark;}
- void clear()
- {edit::clear_field(true); mark=0; draw_edit_text();}
- }ocenka[10];
- //---------------------------------------------------------------------------
- void int_edit::input_int(){
- char c;
- c=getch();
- if ((c==50) || (c==51) || (c==52) || (c==53) ) {
- mark=c-48;
- cout<<mark;}
- else input_int();}
- //---------------------------------------------------------------------------
- void draw_rect(int x, int y, int x1, int y1, int type, int color){
- char c; int i;
- textcolor(color);
- if (type==2) c=201; if (type==1) c=218; gotoxy(x,y); cprintf("%c",c);
- if (type==2) c=205; if (type==1) c=196; for(i=0; i<x1-x; i++) cprintf("%c",c);
- if (type==2) c=187; if (type==1) c=191; cprintf("%c",c);
- 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);}
- if (type==2) c=200; if (type==1) c=192; gotoxy(x,y1); cprintf("%c",c);
- if (type==2) c=205; if (type==1) c=196; for(i=0; i<x1-x; i++) cprintf("%c",c);
- if (type==2) c=188; if (type==1) c=217; cprintf("%c",c);
- 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);}
- textcolor(7);}
- //---------------------------------------------------------------------------
- void draw_table(int x,int y,int x1,int y1){
- draw_rect(x,y,x1,y1,2,7);
- char c;
- c=204; gotoxy(1,3); cout<<c;
- c=205; for (int i=1; i<x1; i++) {gotoxy(i+1,3); cout<<c;}
- c=185; cout<<c;
- c=209; gotoxy(9, 1); cout<<c;
- gotoxy(25, 1); cout<<c;
- gotoxy(45, 1); cout<<c;
- gotoxy(67, 1); cout<<c;
- c=216; gotoxy(9, 3); cout<<c;
- gotoxy(25, 3); cout<<c;
- gotoxy(45, 3); cout<<c;
- gotoxy(67, 3); cout<<c;
- c=179; for (int i=4; i<y1; i++) {gotoxy(9,i); cout<<c;}
- for (int i=4; i<y1; i++) {gotoxy(25,i); cout<<c;}
- for (int i=4; i<y1; i++) {gotoxy(45,i); cout<<c;}
- for (int i=4; i<y1; i++) {gotoxy(67,i); cout<<c;}
- gotoxy(9, 2); cout<<c;
- gotoxy(25, 2); cout<<c;
- gotoxy(45, 2); cout<<c;
- gotoxy(67, 2); cout<<c;
- c=207; gotoxy(9,y1); cout<<c;
- gotoxy(25,y1); cout<<c;
- gotoxy(45,y1); cout<<c;
- gotoxy(67,y1); cout<<c;
- gotoxy(4,2); cout<<"NUM";
- gotoxy(15,2); cout<<"NAME";
- gotoxy(32,2); cout<<"SURNAME";
- gotoxy(52,2); cout<<"OTCHESTVO";
- gotoxy(72,2); cout<<"ID";}
- //---------------------------------------------------------------------------
- void show_add_stud(){ char c;
- char sp[7][10]={"NAME","SURNAME","OTCHESTVO","DD/MM/YY","FACULTET","GRUPPA","NUMBER"};
- draw_rect(1,1,78,44,2,7);
- c=209; gotoxy(28,1); cout<<c;
- gotoxy(48,1); cout<<c;
- c=179; gotoxy(28,2);cout<<c;
- gotoxy(48,2);cout<<c;
- c=192; gotoxy(28,3); cout<<c;
- c=196; for(int i=0; i<19;i++){cout<<c;}
- c=217; cout<<c;
- textcolor(2);
- gotoxy(33,2); cout<<"ADD STUDENT";
- gotoxy(13,2); cprintf("%s","INFO");
- gotoxy(58,2); cprintf("%s","SESSION 1");
- int kkk=5;
- for (int i = 0; i < 7; i++) {
- gotoxy(4,kkk); cout<<sp[i];
- kkk=kkk+3;}
- int top=0; int left=0;
- for (int i=0; i<3; i++)
- {edit_info[i].kolvo=14;
- edit_info[i].draw_edit(15,4+top,30,6+top);
- top=top+3;}
- for (int i=3; i<6; i++)
- {int k=0; if(i==5) k=2;
- edit_info[i].kolvo=2;
- if (i==5) {edit_info[i].kolvo=4;}
- edit_info[i].draw_edit(15+left,13,18+left+k,15);
- left=left+5;}
- top=0;
- for (int i=6; i<9; i++)
- {edit_info[i].kolvo=14;
- edit_info[i].draw_edit(15,16+top,30,18+top);
- top=top+3;}
- top=0; left=0;
- for (int i=0; i<10; i++)
- {predm[i].kolvo=14;
- gotoxy(50, 5+top); cout<<i+1;
- predm[i].draw_edit(52,4+top,67,6+top);
- top=top+3;}
- top=0; left=0;
- for (int i=0; i<10; i++)
- {ocenka[i].mark=0;
- ocenka[i].draw_edit(69,4+top,71,6+top);
- top=top+3;}
- strcpy(bt_ok.text,"SAVE");
- bt_ok.draw_edit(4,27,10,29);}
- //---------------------------------------------------------------------------
- class sessia{
- public:
- char predmet[15];
- int ocenka;
- };
- //---------------------------------------------------------------------------
- class student{private:
- char name[15];
- char surname[15];
- char otchestvo[15];
- int day, month, year;
- char facultet[15],gruppa[15], number[15];
- sessia ses[10][9];
- public:
- student() {clear_fields();}
- //---------------------------------------------------------------------------
- void clear_edits()
- {for (int i=0; i < 9; i++) strcpy(edit_info[i].text,"");
- for (int i=0; i < 10; i++) {
- strcpy(predm[i].text, ""); ocenka[i].mark=0;}}
- //---------------------------------------------------------------------------
- void clear_fields()
- {strcpy(name,""); strcpy(surname,""); strcpy(otchestvo,"");
- day=0; month=0; year=0;
- strcpy(facultet,""); strcpy(gruppa,""); strcpy(number,"");
- for (int j = 0; j < 9; j++)
- for (int i = 0; i < 10; i++) {
- strcpy(ses[i][j].predmet,""); ses[i][j].ocenka=0;}}
- //---------------------------------------------------------------------------
- void update_session(int ses)
- {read_session(ses);
- for (int i = 0; i < 10; i++) {
- predm[i].clear_field();
- ocenka[i].clear_field();
- predm[i].draw_edit_text();
- ocenka[i].draw_edit_text();}}
- //---------------------------------------------------------------------------
- void input_stud(num) {student();
- int foc=1; int m=0; int ses=1;
- int flag=1;
- char key;
- update_session(ses);
- edit_info[foc-1].focus(4);
- do
- {key=getch();
- if (key==9) { flag++; if (flag>3) flag=1;
- switch (flag) {
- case 1: {foc=1; edit_info[foc-1].focus(4); bt_ok.focus(7); break;}
- case 2: {edit_info[foc-1].focus(7); m=1; predm[0].focus(4); break;}
- case 3: {for (int i = 0; i < 10; i++) predm[i].focus(7);
- bt_ok.focus(4);
- break;} }
- }
- //Êëàâèøà âíèç
- if (key==80){
- if (flag==1) {foc++;
- if (foc>1) edit_info[foc-2].focus(7);
- if (foc>9) foc=1;
- edit_info[foc-1].focus(4); gotoxy(1,1);}
- if (flag==2) {m++;
- if (m>1) predm[m-2].focus(7);
- if (m>10) m=1; predm[m-1].focus(4); gotoxy(1,1);}
- }
- //Êëàâèøà ââåðõ
- if (key==72){
- if (flag==1){foc--;
- if (foc>=0) edit_info[foc].focus(7);
- if (foc==0) foc=9;
- edit_info[foc-1].focus(4); gotoxy(1,1);}
- if (flag==2) {m--;
- if (m>=0) predm[m].focus(7);
- if (m<=0) m=10; predm[m-1].focus(4); gotoxy(1,1);}
- }
- //Êëàâèøà âïðàâî
- if (key==77) if (flag==2) {
- write_session(ses); ses++;
- if (ses>9) {ses=1;}
- gotoxy(66,2); cprintf("%d",ses);
- update_session(ses);}
- //Êëàâèøà âëåâî
- if (key==75) if (flag==2) {
- write_session(ses); ses--;
- if (ses<1) {ses=9;}
- gotoxy(66,2); cprintf("%d",ses);
- update_session(ses);}
- //Óäàëèòü ïðåäìåò
- if (key==8) if (flag==2){
- predm[m-1].clear_field(true);
- ocenka[m-1].clear();
- }
- if (key==13){
- if (flag==1) edit_info[foc-1].input_data();
- if (flag==2) {predm[m-1].input_data(); ocenka[m-1].input_data();}
- if (flag==3){
- write_session(ses);
- strcpy(name, edit_info[0].text);
- strcpy(surname, edit_info[1].text);
- strcpy(otchestvo, edit_info[2].text);
- strcpy(facultet, edit_info[6].text);
- strcpy(gruppa, edit_info[7].text);
- strcpy(number, edit_info[8].text);
- day=atoi(edit_info[3].text);
- month=atoi(edit_info[4].text);
- year=atoi(edit_info[5].text);
- write_stud(num);
- clear_edits();
- clrscr();
- m1.show(1);}}}
- while (key!=27);
- clrscr();
- m1.show(1);}
- //---------------------------------------------------------------------------
- void output_stud(int x, int num) {
- gotoxy(4,x); cprintf("%d",num);
- gotoxy(11,x); cprintf(name);
- gotoxy(27,x); cprintf(surname);
- gotoxy(47,x); cprintf(otchestvo);
- gotoxy(69,x); cprintf(number);
- textbackground(0);}
- //---------------------------------------------------------------------------
- void output_full_info(int num)
- {read_stud(num);
- show_add_stud();
- strcpy(edit_info[0].text, name);
- strcpy(edit_info[1].text, surname);
- strcpy(edit_info[2].text, otchestvo);
- strcpy(edit_info[6].text, facultet);
- strcpy(edit_info[7].text, gruppa);
- strcpy(edit_info[8].text, number);
- itoa(day, edit_info[3].text, 10);
- itoa(month, edit_info[4].text, 10);
- itoa(year, edit_info[5].text, 10);
- gotoxy(30,2); for (int i = 0; i < 18; i++) cout<<" ";
- gotoxy(33,2); cout<<"STUDENT # "<<num+1;
- for (int i=0; i<9; i++) edit_info[i].draw_edit_text();
- input_stud(num);
- clear_edits();}
- //---------------------------------------------------------------------------
- void write_stud(int);
- void check_file();
- void set_pos(int);
- void read_stud(int);
- void delete_stud(int);
- void write_session(int);
- void read_session(int);
- void search(char *, int);
- void sort();
- static int count();
- static int count2();
- //---------------------------------------------------------------------------
- void press(){ char g; int k=0; int kkk=1; int rec=10;
- vvod:
- g=getch(); div_t div_result; div_result = div( count(), 10 );
- if (count()>=10 & kkk<10) rec=10;
- if (count()<10 & kkk<10) rec=count();
- if (g==80) {k++; if (k>kkk+rec-2) k=kkk-1;
- vivod(rec,kkk, k); goto vvod;}
- if (g==72) {k--; if (k<kkk-1) k=kkk+rec-2;
- vivod(rec,kkk, k); goto vvod;}
- if (g==77) {clrscr(); rec=10;
- if (kkk<count()-9) {kkk=kkk+10; k=kkk-1;}
- if (kkk+9>count()) {
- rec=div_result.rem; kkk=(div_result.quot*10)+1;}
- show_table(); vivod(rec,kkk, k); goto vvod;}
- if ((g==75) & (kkk>-1)) {clrscr(); rec=10;
- if (kkk>=10) {kkk=kkk-10; k=kkk-1; }
- if (kkk+9>count()) {
- rec=div_result.rem; kkk=(div_result.quot*10)+1;}
- show_table();
- vivod(rec,kkk, k); goto vvod;}
- if (g==115) {sm1.show(1);}
- if (g==13) {clrscr(); output_full_info(k);}
- if (g==8) {delete_stud(k); clrscr(); check_file();}
- if ((g!=72)&&(g!=80) &&(g!=27) &&(g!=77)) goto vvod;
- if (g==27) clrscr(); m1.show(1);}
- //---------------------------------------------------------------------------
- void vivod(int count, int start, int vibor) {
- for (int i=start-1; i<count+start-1; i++) {
- student::read_stud(i);
- if (i==vibor) textbackground(4);
- student::output_stud(i+5-start,i+1); textbackground(0);}}
- //---------------------------------------------------------------------------
- void show_table(){draw_table(1,1,79,14);
- gotoxy(2,16); cout<<"Stydentov v baze: "<<count()<<"\n\n";
- char c;
- c=24; cout<<"\n "<<c; c=25; cout<<c; cout<<" - Move students\n";
- c=27; cout<<" "<<c; c=26; cout<<c; cout<<" - Move tables";
- cout<<"\n Enter - Show Or Change";
- cout<<"\n Backspace - Delete Student";
- cout<<"\n S key - Search";
- cout<<"\n A key - Add Student";
- draw_rect(1,15,27,25,1,5);}
- }stud;
- //---------------------------------------------------------------------------
- void student::check_file(){
- ifstream file;
- file.open("student.txt");
- if (!file) {cout<<"No students"; getch(); clrscr(); file.close(); m1.show(1);}
- show_table();
- if (count()>=10) vivod(10,1, 0);
- if (count()<10) vivod(count(),1, 0);
- press();}
- //---------------------------------------------------------------------------
- void student::write_stud(int num)
- {ofstream file;
- file.open("student.txt", ios::in |ios::binary);
- file.seekp(num*sizeof(student));
- file.write((char*)this, sizeof(*this));
- file.close();}
- //---------------------------------------------------------------------------
- void student::read_stud(int kolvo)
- {ifstream file;
- file.open("student.txt", ios::binary );
- file.seekg(kolvo*sizeof(student));
- file.read((char*)this, sizeof(*this));}
- //---------------------------------------------------------------------------
- int student::count(){
- ifstream file;
- file.open("student.txt", ios::binary);
- file.seekg(0, ios::end);
- return (int)file.tellg()/sizeof(student);}
- //---------------------------------------------------------------------------
- int student::count2(){
- ifstream file;
- file.open("temp.txt", ios::binary);
- file.seekg(0, ios::end);
- return (int)file.tellg()/sizeof(student);}
- //---------------------------------------------------------------------------
- void student::delete_stud(int del){int i;
- ifstream file, file1;
- ofstream temp, temp1;
- file.open("student.txt", ios::binary );
- temp.open("temp.txt", ios::trunc | ios::ate| ios::in |ios::binary);
- for (i = 0; i < del; i++) {
- file.seekg(i*sizeof(student));
- file.read((char*)this, sizeof(*this));
- temp.write((char*)this, sizeof(*this));}
- for (i = del+1; i < count(); i++) {
- file.seekg(i*sizeof(student));
- file.read((char*)this, sizeof(*this));
- temp.write((char*)this, sizeof(*this));}
- file.close();
- temp.close();
- file1.open("temp.txt", ios::binary );
- temp1.open("student.txt", ios::trunc | ios::ate| ios::in |ios::binary);
- for (i = 0; i < count2(); i++) {
- file1.seekg(i*sizeof(student));
- file1.read((char*)this, sizeof(*this));
- temp1.write((char*)this, sizeof(*this));}
- file1.close();
- temp1.close();}
- //---------------------------------------------------------------------------
- void student::write_session(int s)
- {for (int i = 0; i < 10; i++) {
- strcpy(ses[i][s-1].predmet, predm[i].text);
- ses[i][s-1].ocenka=ocenka[i].mark;}}
- //---------------------------------------------------------------------------
- void student::read_session(int s)
- {for (int i = 0; i < 10; i++) {
- strcpy(predm[i].text, ses[i][s-1].predmet);
- ocenka[i].mark=ses[i][s-1].ocenka;}}
- //---------------------------------------------------------------------------
- void student::search(char field[15], int type){
- int t;
- int c=0;
- for (int i = 0; i < count(); i++) {
- t=1; read_stud(i);
- switch (type) {
- case 0: {t=strcmp(name, field);
- if (t==0) {c++; output_stud(30+c,i+1);}}
- case 1: {t=strcmp(surname, field);
- if (t==0) {c++; output_stud(30+c,i+1);}}
- case 2: {t=strcmp(number, field);
- if (t==0) {c++; output_stud(30+c,i+1);}}
- }}
- if (c!=0) draw_rect(1,30,79,31+c,1,7);
- gotoxy(2,32+c);
- cout<<"\n\n Searching finished. Press ESC key to continue, Enter to Read Student";
- char vvod;
- do{vvod=getch();}
- while ((vvod!=13) && (vvod!=27));
- if (vvod==13){int ss;
- cout<<"\n Enter Student number: "; cin>>ss;
- clrscr(); output_full_info(ss-1);}
- if (vvod==27) clrscr(); stud.check_file();
- }
- //---------------------------------------------------------------------------
- void student::sort(){
- bool flag;
- int kolvo=0;
- cout<<" Spisok studentov, y kotorih hotya bi odna troyka\n";
- for (int i = 0; i < count(); i++) {
- read_stud(i);
- flag=false;
- for (int j = 0; j < 9; j++) {
- for (int k = 0; k < 10; k++) {
- if (ses[k][j].ocenka==0) {continue;}
- if (ses[k][j].ocenka==3) {flag=true;}}}
- if (flag==true) {kolvo++; output_stud(kolvo+5,i+1);}
- }
- draw_rect(1,5,78,6+kolvo,1,7);
- cout<<"\n\n\n\n Press Enter Key...";
- getchar();
- clrscr();
- }
- // Ôóíêöèÿ íàæàòèÿ êëàâèø ãëàâíîãî ìåíþ.
- //---------------------------------------------------------------------------
- void menu::keypress(){
- switch (selected)
- {
- case 1: {clrscr();
- stud.clear_fields(); stud.clear_edits();
- show_add_stud(); stud.input_stud(stud.count());
- clrscr(); show(1);}
- case 2: {clrscr(); stud.check_file();}
- case 3: {fflush(stdin); clrscr(); stud.sort(); show(1);}
- case 4: {exit(1);}
- default: keypress();
- }
- }
- //---------------------------------------------------------------------------
- void search_menu::keypress(){
- switch (selected) {
- case 1: {search_box.draw_edit(30,23,45,25); search_box.kolvo=14; search_box.input_data();
- stud.search(search_box.text,0); stud.check_file();}
- case 2: {search_box.draw_edit(30,23,45,25); search_box.kolvo=14; search_box.input_data();
- stud.search(search_box.text,1); stud.check_file();}
- case 3: {search_box.draw_edit(30,23,45,25); search_box.kolvo=14; search_box.input_data();
- stud.search(search_box.text,2); stud.check_file();}
- case 4: {clrscr(); stud.check_file();}}
- }
- //---------------------------------------------------------------------------
- void main() {m1.show(1);}
- //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment