Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <stdlib.h>
- #include<conio.h>
- #include <windows.h>
- #include <iostream>
- using namespace std;
- //Äåêëàðàöèÿ íà áàçîâ êëàñ St -âêëþ÷âà äàííè çà ñòóäåíòè
- class St {
- public:
- char FakNom[10];
- int Grupa;
- double Uspeh;
- void getData();
- void display();
- };
- //Äåôèíèöèÿ íà ÷ëåí-ôóíêöèÿòà getData
- void St::getData() {
- cout << "Âúâåäåòå ôàê.íîìåð íà ñòóäåíòà: "; cin >> FakNom;
- cout << "Âúâåäåòå ãðóïà: "; cin >> Grupa;
- cout << "Âúâåäåòå ñðåäíèÿò ìó óñïåõ: "; cin >> Uspeh;
- }
- //Äåôèíèöèÿ íà ÷ëåí-ôóíêöèÿòà display
- void St::display() {
- cout << "Ôàê.íîìåð íà ñòóäåíòà å : " << FakNom << endl;
- cout << "Ãðóïàòà ìó å : " << Grupa << endl;
- cout << "Óñïåõúò ìó å : " << Uspeh << endl;
- }
- //Äåôèíèöèÿ íà áàçîâ êëàñ Pr-äàííè çà ïðåïîäàâàòåë
- class Pr{
- public:
- char Katedra[31];
- int Staj;
- void getData();
- void display();
- };
- //Äåôèíèöèÿ íà ÷ëåí-ôóíêöèÿòà getData
- void Pr::getData() {
- cout << "Âúâåäåòå êàòåäðàòà íà ïðåïîäàâàòåëÿ: "; cin >> Katedra;
- cout << "Âúâåäåòå òðóäîâèÿ ñòàæ: "; cin >> Staj;
- }
- //Äåôèíèöèÿ íà ÷ëåí-ôóíêöèÿòà display
- void Pr::display() {
- cout << "Êàòåäðà: " << Katedra << endl;
- cout << "Òðóäîâ ñòàæ: " << Staj << endl;
- }
- //Ïðîèçâîäåí êëàñ Smesen ñ äâà áàçîâè êëàñà: St è Pr
- class Smesen :public St, public Pr {
- public:
- char Ime[16], Fam[16], Fak[21];
- char VidLc; //Âèä ëèöå : ñ- ñòóäåíò , ï -ïðåïîäàâàòåë
- void getData();
- void display(char);
- };
- //Äàôèíèöèÿ íà ÷ëåí-ôóíêöèÿòà getData
- void Smesen::getData() {
- cout << "Âúâåäåòå ñîáñòâåíî èìå: "; cin >> Ime;
- cout << "Âúâåäåòå ôàìèëíî èìå: "; cin >> Fam;
- cout << "Âúâåäåòå ôàêóëòåò: "; cin >> Fak;
- do {
- cout << "Ñòóäåíò èëè ïðåïîäàâàòåë (s èëè p)? : "; cin >> VidLc;
- } while (VidLc != 's' && VidLc != 'p');
- if (VidLc == 's') St::getData(); //Îáðúùåíèå êúì íàñëåäåíà ô-èÿ
- if (VidLc == 'p') Pr::getData(); //Îáðóùåíèå êúì íàñëåäíà ô-èÿ
- }
- //Äåôèíèöèÿ íà ÷ëåí-ôóíêöèÿ display
- void Smesen::display(char VidSp = ' ') { //Âèä ñïèñúê :s-ñòóäåíòè,p-ïðåïîäàâàòåëè
- if (VidSp == ' ' || VidSp == VidLc) {
- cout << "\nÈìå: " << Ime << endl;
- cout << "Ôàì. èìå: " << Fam << endl;
- cout << "Ôàêóëòåò: " << Fak << endl;
- if (VidLc == 's') St::display(); //Îáðúùåíèå êúì íàñëåäåíà ô-èÿ
- if (VidLc == 'p') Pr::display(); //Îáðúùåíèå êúì íàñëåäåíà ô-èÿ
- }
- }
- Smesen Lice; ofstream outf, outf1, outf2; ifstream inf; //Ãëîáàëíè
- //Ôóíêöèÿ çà ñúçäàâàíå íà ïðàçåí ôàéë
- void SzdPrz() {
- outf.open("DvFlStPr.cpp", ios::out | ios::binary); outf.close();
- cout << "\n\tÔàéëúò å ñúçäàäåí.\n\n";
- }
- //Ôóíêöèÿ çà äîáàâÿíå íà êîìïîíåíòè êúì ôàéëà
- void Dobavqne() {
- outf.open("DvFlStPr.cpp", ios::app | ios::binary);
- Lice.getData(); outf.write((char*)(&Lice), sizeof(Lice));
- outf.close();
- }
- //Ôóíêöèÿ çà èçâåæäàíå ñïèñúê íà ñòóäåíòèòå,ïðåïîäàâàòåëèòå èëè íà âñè÷êè ðåãèñòðèðàíè ëèöà
- void Spisak(char ImeDvFl[], char vidSp = ' ') {
- inf.open(ImeDvFl, ios::in | ios::binary);
- while (inf.read((char*)&Lice, sizeof(Lice)))Lice.display(vidSp);
- inf.close();
- }
- //Ôóíêöèÿ çà ñúçäàâàíå íà äâîè÷åí ôàéë ñ äàííèòå íà ñòóäåíòèòå è äâîè÷åí ôàéë ñ äàííèòå íà ïðåïîäàâàòåëèòå
- void SzdDvaDvFl(char ImeDvFl[]) {
- inf.open(ImeDvFl, ios::in | ios::binary);
- outf1.open("DvFlSt.cpp", ios::out | ios::binary);
- outf2.open("DvFlPr.cpp", ios::out | ios::binary);
- while (inf.read((char*)&Lice, sizeof(Lice)))
- if (Lice.VidLc == 's') outf1.write((char*)&Lice, sizeof(Lice));
- else outf2.write((char*)&Lice, sizeof(Lice));
- inf.close(); outf1.close(); outf2.close();
- }
- //Äåôèíèöèÿ íà ôóíêöèÿòà main
- int main() {
- SetConsoleOutputCP(1251);
- system("mode 650");
- char KodOp;
- do {
- cout << "\nÌÅÍÞ :" << endl;
- cout << "1 - ñúçäàâàíå íà ôàéë" << endl;
- cout << "2 - çà äîâàâÿíå íà êîìïîíåíòè(ñòóäåíòè è ïðåïîäàâàòåëè)" << endl;
- cout << "3 - çà ñïèñúê íà ñòóäåíòèòå" << endl;
- cout << "4 - çà ñïèñúê íà ïðåïîäàâàòåëèòå" << endl;
- cout << "5 - çà ñïèñúê íà âñè÷êè ëèöà" << endl;
- cout << "6 - çà äâà îòäåëíè äâîè÷íè ôàéëîâå" << endl;
- cout << "0 - èçõîä" << endl;
- cout << "IZBOR: "; cin >> KodOp;
- switch (KodOp) {
- case '1':SzdPrz(); break;
- case '2':Dobavqne(); break;
- case '3':cout << "\n\n\t\t Ñïèñúê íà ñòóäåíòèòå\n";
- Spisak("DvFlStPr.cpp", 's'); break;
- case '4':cout << "\n\n\t\t Ñïèñúê íà ïðåïîäàâàòåëèòå\n";
- Spisak("DvFlStPr.cpp", 'p'); break;
- case '5':cout << "\n\n\t\t Ñïèñúê íà âñè÷êè\n";
- Spisak("DvFlStPr.cpp", ' '); break;
- case '6':SzdDvaDvFl("DvFlStPr.cpp");
- cout << "\n Ñúäàðæàíèå íà ôàéëà \"Ñòóäåíòè\":"; Spisak("DvFlSt.cpp");
- cout << "\n Ñúäàðæàíèå íà ôàéëà \"Ïðåïîäàâàòåëè\":"; Spisak("DvFlPr.cpp"); break;
- case '0':break;
- default:cout << "\n\nÃðåøåí èçáîð !!!";
- }
- } while (KodOp != '0');
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement