Advertisement
Garey

st_class

Nov 29th, 2017
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.90 KB | None | 0 0
  1. #include <fstream>
  2. #include <stdlib.h>
  3. #include<conio.h>
  4. #include <windows.h>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8. //Äåêëàðàöèÿ íà áàçîâ êëàñ St -âêëþ÷âà äàííè çà ñòóäåíòè
  9. class St {
  10. public:
  11.     char FakNom[10];
  12.     int Grupa;
  13.     double Uspeh;
  14.     void getData();
  15.     void display();
  16. };
  17.  
  18. //Äåôèíèöèÿ íà ÷ëåí-ôóíêöèÿòà getData
  19. void St::getData() {
  20.     cout << "Âúâåäåòå ôàê.íîìåð íà ñòóäåíòà: "; cin >> FakNom;
  21.     cout << "Âúâåäåòå ãðóïà: "; cin >> Grupa;
  22.     cout << "Âúâåäåòå ñðåäíèÿò ìó óñïåõ: "; cin >> Uspeh;
  23. }
  24. //Äåôèíèöèÿ íà ÷ëåí-ôóíêöèÿòà display
  25. void St::display() {
  26.     cout << "Ôàê.íîìåð íà ñòóäåíòà å : " << FakNom << endl;
  27.     cout << "Ãðóïàòà ìó å : " << Grupa << endl;
  28.     cout << "Óñïåõúò ìó å : " << Uspeh << endl;
  29. }
  30.  
  31. //Äåôèíèöèÿ íà áàçîâ êëàñ Pr-äàííè çà ïðåïîäàâàòåë
  32. class Pr{
  33. public:
  34.     char Katedra[31];
  35.     int Staj;
  36.     void getData();
  37.     void display();
  38. };
  39.  
  40. //Äåôèíèöèÿ íà ÷ëåí-ôóíêöèÿòà getData
  41. void Pr::getData() {
  42.     cout << "Âúâåäåòå êàòåäðàòà íà ïðåïîäàâàòåëÿ: "; cin >> Katedra;
  43.     cout << "Âúâåäåòå òðóäîâèÿ ñòàæ: "; cin >> Staj;
  44. }
  45.  
  46. //Äåôèíèöèÿ íà ÷ëåí-ôóíêöèÿòà display
  47. void Pr::display() {
  48.     cout << "Êàòåäðà: " << Katedra << endl;
  49.     cout << "Òðóäîâ ñòàæ: " << Staj << endl;
  50. }
  51.  
  52. //Ïðîèçâîäåí êëàñ Smesen ñ äâà áàçîâè êëàñà: St è Pr
  53. class Smesen :public St, public Pr {
  54. public:
  55.     char Ime[16], Fam[16], Fak[21];
  56.     char VidLc; //Âèä ëèöå : ñ- ñòóäåíò , ï -ïðåïîäàâàòåë
  57.     void getData();
  58.     void display(char);
  59. };
  60.  
  61. //Äàôèíèöèÿ íà ÷ëåí-ôóíêöèÿòà getData
  62. void Smesen::getData() {
  63.     cout << "Âúâåäåòå ñîáñòâåíî èìå: "; cin >> Ime;
  64.     cout << "Âúâåäåòå ôàìèëíî èìå: "; cin >> Fam;
  65.     cout << "Âúâåäåòå ôàêóëòåò: "; cin >> Fak;
  66.     do {
  67.         cout << "Ñòóäåíò èëè ïðåïîäàâàòåë (s èëè p)? : "; cin >> VidLc;
  68.     } while (VidLc != 's' && VidLc != 'p');
  69.     if (VidLc == 's') St::getData(); //Îáðúùåíèå êúì íàñëåäåíà ô-èÿ
  70.     if (VidLc == 'p') Pr::getData(); //Îáðóùåíèå êúì íàñëåäíà ô-èÿ
  71. }
  72.  
  73. //Äåôèíèöèÿ íà ÷ëåí-ôóíêöèÿ display
  74. void Smesen::display(char VidSp = ' ') {      //Âèä ñïèñúê :s-ñòóäåíòè,p-ïðåïîäàâàòåëè
  75.     if (VidSp == ' ' || VidSp == VidLc) {
  76.         cout << "\nÈìå: " << Ime << endl;
  77.         cout << "Ôàì. èìå: " << Fam << endl;
  78.         cout << "Ôàêóëòåò: " << Fak << endl;
  79.         if (VidLc == 's') St::display();       //Îáðúùåíèå êúì íàñëåäåíà ô-èÿ
  80.         if (VidLc == 'p') Pr::display();       //Îáðúùåíèå êúì íàñëåäåíà ô-èÿ
  81.     }
  82. }
  83.  
  84. Smesen Lice; ofstream outf, outf1, outf2; ifstream inf; //Ãëîáàëíè
  85.  
  86. //Ôóíêöèÿ çà ñúçäàâàíå íà ïðàçåí ôàéë
  87. void SzdPrz() {
  88.     outf.open("DvFlStPr.cpp", ios::out | ios::binary); outf.close();
  89.     cout << "\n\tÔàéëúò å ñúçäàäåí.\n\n";
  90. }
  91.  
  92. //Ôóíêöèÿ çà äîáàâÿíå íà êîìïîíåíòè êúì ôàéëà
  93. void Dobavqne() {
  94.     outf.open("DvFlStPr.cpp", ios::app | ios::binary);
  95.     Lice.getData(); outf.write((char*)(&Lice), sizeof(Lice));
  96.     outf.close();
  97. }
  98.  
  99. //Ôóíêöèÿ çà èçâåæäàíå ñïèñúê íà ñòóäåíòèòå,ïðåïîäàâàòåëèòå èëè íà âñè÷êè ðåãèñòðèðàíè ëèöà
  100. void Spisak(char ImeDvFl[], char vidSp = ' ') {
  101.     inf.open(ImeDvFl, ios::in | ios::binary);
  102.     while (inf.read((char*)&Lice, sizeof(Lice)))Lice.display(vidSp);
  103.     inf.close();
  104. }
  105.  
  106. //Ôóíêöèÿ çà ñúçäàâàíå íà äâîè÷åí ôàéë ñ äàííèòå íà ñòóäåíòèòå è äâîè÷åí ôàéë ñ äàííèòå íà ïðåïîäàâàòåëèòå
  107.  
  108. void SzdDvaDvFl(char ImeDvFl[]) {
  109.     inf.open(ImeDvFl, ios::in | ios::binary);
  110.     outf1.open("DvFlSt.cpp", ios::out | ios::binary);
  111.     outf2.open("DvFlPr.cpp", ios::out | ios::binary);
  112.     while (inf.read((char*)&Lice, sizeof(Lice)))
  113.         if (Lice.VidLc == 's') outf1.write((char*)&Lice, sizeof(Lice));
  114.         else outf2.write((char*)&Lice, sizeof(Lice));
  115.         inf.close(); outf1.close(); outf2.close();
  116. }
  117.  
  118. //Äåôèíèöèÿ íà ôóíêöèÿòà main
  119. int main() {
  120.     SetConsoleOutputCP(1251);
  121.     system("mode 650");
  122.     char KodOp;
  123.     do {
  124.         cout << "\nÌÅÍÞ :" << endl;
  125.         cout << "1 - ñúçäàâàíå íà ôàéë" << endl;
  126.         cout << "2 - çà äîâàâÿíå íà êîìïîíåíòè(ñòóäåíòè è ïðåïîäàâàòåëè)" << endl;
  127.         cout << "3 - çà ñïèñúê íà ñòóäåíòèòå" << endl;
  128.         cout << "4 - çà ñïèñúê íà ïðåïîäàâàòåëèòå" << endl;
  129.         cout << "5 - çà ñïèñúê íà âñè÷êè ëèöà" << endl;
  130.         cout << "6 - çà äâà îòäåëíè äâîè÷íè ôàéëîâå" << endl;
  131.         cout << "0 - èçõîä" << endl;
  132.  
  133.         cout << "IZBOR: "; cin >> KodOp;
  134.         switch (KodOp) {
  135.         case '1':SzdPrz(); break;
  136.         case '2':Dobavqne(); break;
  137.         case '3':cout << "\n\n\t\t Ñïèñúê íà ñòóäåíòèòå\n";
  138.             Spisak("DvFlStPr.cpp", 's'); break;
  139.         case '4':cout << "\n\n\t\t Ñïèñúê íà ïðåïîäàâàòåëèòå\n";
  140.             Spisak("DvFlStPr.cpp", 'p'); break;
  141.         case '5':cout << "\n\n\t\t Ñïèñúê íà âñè÷êè\n";
  142.             Spisak("DvFlStPr.cpp", ' '); break;
  143.         case '6':SzdDvaDvFl("DvFlStPr.cpp");
  144.             cout << "\n Ñúäàðæàíèå íà ôàéëà \"Ñòóäåíòè\":"; Spisak("DvFlSt.cpp");
  145.             cout << "\n Ñúäàðæàíèå íà ôàéëà \"Ïðåïîäàâàòåëè\":"; Spisak("DvFlPr.cpp");    break;
  146.         case '0':break;
  147.         default:cout << "\n\nÃðåøåí èçáîð !!!";
  148.         }
  149.     } while (KodOp != '0');
  150.     system("pause");
  151.     return 0;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement