Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <string.h>
- using namespace std;
- struct WordCard{
- string slovo,perevod;
- };
- class dictionary{
- private:
- string name;
- WordCard *mas;
- int size,count;
- public:
- dictionary(){
- cout<<"ZAPOLNENIE SLOVARYA!"<<endl;
- cout<<"Vvedite nazvanie slovarya : ";
- cin>>name;
- do{
- cout<<"Vvedite maximal`noe kolichestvo slov v slovare : ";cin>>size;
- mas = new WordCard[size+1];
- cout<<"Vvedite skolko slov vu xotite vvesti seuchas : ";cin>>count;--count;
- if(count>size)
- cout<<"eror,kolichestvo ne mojet but` bolshe razmera slovarya!"<<endl;
- else{
- for(int i = 0;i<count+1;i++){
- string tmp;
- bool fnd = true;
- if(i==0){
- cout<<"Vvedite slovo : ";
- cin>>tmp;
- }
- if(i>=1){
- do{
- cout<<"Vvedite slovo : ";
- cin>>tmp;
- if(find(tmp,1)==true){
- cout<<"Slovo uje est` v slovare!"<<endl;
- fnd = false;
- }
- else if(find(tmp,1)==false)
- fnd=true;
- }while(fnd==false);
- }
- mas[i].slovo = tmp;
- cout<<"Vvedite perevod : ";
- cin>>mas[i].perevod;
- }
- }
- cout<<endl<<"NAZAVANIE SLOVARYA : "<<name<<endl;
- for(int i = 0;i<count+1;i++){
- cout<<mas[i].slovo<<" " <<mas[i].perevod<<endl;
- }
- }while(count>size);
- }
- dictionary(int n){size = n; count = -1;mas = new WordCard[n+1];name = "SLOVAR` - REZULTAT";}
- int getSize(){return this->size;}
- int getCount(){return this->count+1;}
- void change (){
- cout<<"Nazvanie : "<<this->name;
- cout<<"Izmenit nazvanie na : ";cin>>this->name;
- cout<<"Nazvanie slovarya izmeneno na : "<<this->name;
- }
- void add(){
- if(count+1<size){
- ++count;
- cout<<"Vvedite slovo : ";
- cin>>mas[count].slovo;
- cout<<"Vvedite perevod slova : ";
- cin>>mas[count].perevod;
- }
- else
- cerr<<"Nelzya dobavit elemnt!"<<endl;
- }
- WordCard &operator[] (string fnd){
- for(int i = 0;i<count+1;i++){
- if(mas[i].slovo == fnd)
- return mas[i];
- }
- }
- void show(){
- cout<<"NAZVANIE SLOVARYA : "<<this->name<<endl;
- for(int i = 0;i<count+1;i++){
- cout<<"Slovo : "<<mas[i].slovo<<endl;
- cout<<"Perevod : "<<mas[i].perevod<<endl;
- }
- }
- void remove () {
- char ch;
- int tmp = count+1;
- int i = 0;
- do{
- cout<<"Slovo : "<<mas[i].slovo<<endl<<"Perevod : "<<mas[i].perevod<<endl;
- cout<<"Udalit eto slovo?\n1 - da\n2 - net"<<endl;
- ch = _getch();
- switch(ch){
- case'1':
- for(int j = i;j<tmp;j++){
- mas[j] = mas[j+1];
- }
- mas[size-1].perevod = "";
- mas[size-1].slovo= "";
- --count;
- if(i!=0)
- i--;
- break;
- case '2':
- i++;
- break;
- }
- }while(i!=count+1);
- }
- void changeName(){
- cout<<"Vu xotite izmenit` nazvanie slovarya "<<this->name;
- cout<<"Vvedite novoe nazvanie : ";cin>>name;
- }
- WordCard find(string fnd){
- bool t;
- for(int i = 0;i<count+1;i++){
- if(mas[i].slovo==fnd)
- {
- t = true;
- return mas[i];
- }
- }
- if(t==false)
- cout<<"takogo slova netu v slovare!"<<endl;
- }
- bool find(string fnd,int a){
- for(int i = 0;i<count+1;i++){
- if(mas[i].slovo==fnd)
- {
- return true;
- }
- }
- return false;
- }
- void add(string slovo,string perevod){
- if(count+1<size){
- count++;
- mas[count].slovo = slovo;
- mas[count].perevod = perevod;
- }
- else
- cout<<"Perepolnenie!"<<endl;
- }
- dictionary deleteDuplicate(){
- for(int i = 0;i<count+1;i++){
- for(int j = i+1;j<count+1;j++){
- if(mas[i].slovo == mas[j].slovo)
- {
- for(int z = j;z<count;z++){
- mas[z] = mas[z+1];
- }
- count-=1;
- }
- }
- }
- return *this;
- }
- dictionary obedninenie(dictionary &a){
- dictionary tmp(255);
- for(int i = 0;i<count+1;i++){
- tmp.add(this->mas[i].slovo,this->mas[i].perevod);
- }
- for(int i = 0;i<a.count+1;i++){
- tmp.add(a.mas[i].slovo,a.mas[i].perevod);
- }
- tmp.deleteDuplicate();
- return tmp;
- };
- dictionary peresechenie(dictionary &a){
- dictionary q(255);
- for(int i = 0;i<count+1;i++){
- if(a.find(mas[i].slovo,1) == true)
- {
- q.add(mas[i].slovo,mas[i].perevod);
- }
- }
- return q;
- }
- dictionary vuchitanie(dictionary &a){
- dictionary tmp(255);
- for(int i = 0;i<count;i++){
- if(!a.find(mas[i].slovo,1))
- {
- tmp.add(mas[i].slovo,mas[i].perevod);
- }
- }
- return tmp;
- }
- string getName(){return name;};
- bool sravnenieName(dictionary& a){
- if(a.getName() == this->getName())
- return true;
- return false;
- }
- };
- /*
- задача 10 стр 43
- */
- void main (){
- dictionary c(255),d(255),a,b;
- char ch,slovar;
- do{
- cout<<endl<<endl<<"1 - vuvesti informacuy pro slovar`"
- "\n2 - izmenit` nazvanie slovarya"
- "\n3 - dobavit slovo"
- "\n4 - udalit` slovo"
- "\n5 - ob`edinenie"
- "\n6 - peresichenie"
- "\n7 - vuchitanie"
- "\n8 - exit";
- ch = _getch();
- switch(ch){
- case'1':
- cout<<endl;
- cout<<"1 - dlya rabotu so slovarem : "<<a.getName()<<endl;
- cout<<"2 - dlya rabotu so slovarem : "<<b.getName()<<endl;
- slovar = _getch();
- if(slovar=='1'){
- cout<<"Informacuya pro slovar` : "<<a.getName()<<endl;
- a.show();
- }
- else if(slovar=='2'){
- cout<<"Informacuya pro slovar` : "<<b.getName()<<endl;
- b.show();
- }
- break;
- case'2':
- cout<<endl;
- cout<<"1 - dlya rabotu so slovarem : "<<a.getName()<<endl;
- cout<<"2 - dlya rabotu so slovarem : "<<b.getName()<<endl;
- slovar = _getch();
- if(slovar=='1'){
- a.change();
- }
- else if(slovar=='2'){
- b.change();
- }
- break;
- case'3':
- cout<<endl;
- cout<<"1 - dlya rabotu so slovarem : "<<a.getName()<<endl;
- cout<<"2 - dlya rabotu so slovarem : "<<b.getName()<<endl;
- slovar = _getch();
- if(slovar=='1'){
- cout<<"Dobavlenie slova v slovar` : "<<a.getName()<<endl;
- a.add();
- }
- else if(slovar=='2'){
- cout<<"Dobavlenie slova v slovar` : "<<b.getName()<<endl;
- b.add();
- }
- break;
- case'4':
- cout<<endl;
- cout<<"1 - dlya rabotu so slovarem : "<<a.getName()<<endl;
- cout<<"2 - dlya rabotu so slovarem : "<<b.getName()<<endl;
- slovar = _getch();
- if(slovar=='1'){
- cout<<"Udalenie slova v slovar` : "<<a.getName()<<endl;
- a.remove();
- }
- else if(slovar=='2'){
- cout<<"Udalenie slova v slovar` : "<<b.getName()<<endl;
- b.remove();
- }
- break;
- case'5':
- cout<<endl;
- {
- dictionary tmp(255);
- cout<<"1 - dlya rabotu so slovarem : "<<a.getName()<<endl;
- cout<<"2 - dlya rabotu so slovarem : "<<b.getName()<<endl;
- slovar = _getch();
- if(slovar=='1'){
- cout<<"Ob`edinit slovarya "<<a.getName()<<"so slovarem"<<b.getName()<<endl;
- tmp = a.obedninenie(b);
- tmp.show();
- }
- else if(slovar=='2'){
- cout<<"Ob`edinit slovarya "<<b.getName()<<"so slovarem "<<a.getName()<<endl;
- tmp = b.obedninenie(a);
- tmp.show();
- }
- break;
- }
- case'6':{
- cout<<endl;
- dictionary tmp(255);
- cout<<"1 - dlya naxojdeniya peresicheniya slovarya "<<a.getName()<<" so slovarem "<<b.getName()<<endl;
- cout<<"2 - dlya naxojdeniya peresecheniya slovarya "<<b.getName()<<" so slovarem "<<a.getName()<<endl;
- slovar = _getch();
- if(slovar=='1'){
- a.show();
- b.show();
- tmp = a.peresechenie(b);
- tmp.show();
- }
- else if(slovar=='2'){
- tmp = b.peresechenie(a);
- tmp.show();
- }
- break;
- }
- case'7':{
- cout<<endl;
- dictionary tmp(255);
- cout<<"1 - dlya vuchitaniya iz slovarya "<<a.getName()<<" slovarya "<<b.getName()<<endl;
- cout<<"2 - dlya vuchitaniya iz slovarya "<<b.getName()<<" slovarya "<<a.getName()<<endl;
- slovar = _getch();
- if(slovar=='1'){
- tmp = a.vuchitanie(b);
- tmp.show();
- }
- else if(slovar=='2'){
- tmp = b.vuchitanie(a);
- tmp.show();
- }
- break;
- }
- case'8':exit;
- }
- }while(ch!='8');
- system("pause>>void");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement