daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<string>
  3. #include<fstream>
  4. using namespace std;
  5.  
  6. typedef struct {
  7.     int nomer;
  8.     char ime[50];
  9.     char familiq[50];
  10.     int rojdennadata;
  11.     int godini;
  12.     double teglo;
  13.     double visochina;
  14.     char durjava[50];
  15. } Uchastnichki;
  16.  
  17. #define girlsCount 30
  18.  
  19. int UchastnichkiIn(Uchastnichki girls[], int count);//tova sa mi funkcite
  20. void UchastnichkiOut(Uchastnichki girls[], int count);//izvejda uc
  21. void UchastnichkiBinaryFileSave(Uchastnichki girls[], int count);//zapis v2
  22. void UchastnichkiBinaryFileRead(Uchastnichki girls[]);//chetene v2
  23. void UchastnichkiTextFileSave(Uchastnichki girls[], int count);//zapis txt
  24. void UchastnichkiTextFileRead(Uchastnichki girls[]);        //chetene txt
  25. void UchastnichkiOut2(Uchastnichki girls[], int count); //dani na uc po nemer i familiq
  26. void UchastnichkiOut3(Uchastnichki girls[], int count);
  27.  
  28. int main()
  29. {
  30.     Uchastnichki newgirls[girlsCount];//Car e tiput,toest strukturata,a newCars e ime. Vuv newCars se zapisvat danninite na kolite
  31.     int l;
  32.     int op;
  33.     do {
  34.         cout << " \t\t\t\tMENU\n" << endl;           //imam menu koeto izliza pri startirane na programata. Menuto e v do-while cikul
  35.         cout << "1. Enter girls" << endl;
  36.         cout << "2. Print girls" << endl;
  37.         cout << "3. Save girls in binary file" << endl;
  38.         cout << "4. Read girls from binary file" << endl;
  39.         cout << "5. Save girls in text file" << endl;
  40.         cout << "6. Read girls from text file" << endl;
  41.         cout << "7. Vuvedete nomer i familiq na uchastnichka" << endl;
  42.         cout << "8. Izvedete nai-mlada uchastnichka i broq na uchasnichkite na vuzrast do 20 godini" << endl;
  43.         cout << "0. Exit" << endl;
  44.         cout << "Select option: ";
  45.         cin >> op;
  46.  
  47.         switch (op)
  48.         {
  49.         case 1:
  50.         {
  51.                   l = UchastnichkiIn(newgirls, girlsCount);
  52.                   system("pause");
  53.         }
  54.             break;
  55.         case 2:
  56.         {
  57.                   UchastnichkiOut(newgirls, l);
  58.                   system("pause");
  59.         }           break;
  60.         case 3:
  61.         {
  62.                   UchastnichkiBinaryFileSave(newgirls, girlsCount);
  63.                   system("pause");
  64.         }
  65.             break;
  66.         case 4:
  67.         {
  68.                   UchastnichkiBinaryFileRead(newgirls);
  69.                   system("pause");
  70.         }
  71.             break;
  72.         case 5:
  73.         {
  74.                   UchastnichkiTextFileSave(newgirls, girlsCount);
  75.                   system("pause");
  76.         }
  77.             break;
  78.         case 6:
  79.         {
  80.                   UchastnichkiTextFileRead(newgirls);
  81.                   system("pause");
  82.         }
  83.             break;
  84.         case 7:
  85.         {
  86.                   UchastnichkiOut2(newgirls, girlsCount);
  87.                   system("pause");
  88.         }
  89.             break;
  90.         case 8:
  91.         {
  92.                   UchastnichkiOut3(newgirls, girlsCount);
  93.                   system("pause");
  94.         }           break;
  95.         case 0:
  96.         {
  97.                   cout << "Exit with <y> : ";
  98.                   char ch;
  99.                   cin >> ch;
  100.                   if (ch != 'y' && ch != 'Y')
  101.                   {
  102.                       op = -1;
  103.                   }
  104.         }
  105.  
  106.  
  107.             break;
  108.         default:
  109.             cout << "Invalid operation" << endl;
  110.             system("pause");
  111.             break;
  112.         }
  113.  
  114.         system("cls");//funkciqta "cls" e za izchistvane na ekrana
  115.     } while (op != 0);//cikula produljava, dokato se vuvede chislo razlichno ot 0
  116.  
  117. }
  118.  
  119. int UchastnichkiIn(Uchastnichki girls[], int count)//v tazi funkciq vuvejdam vsichki xarakteristiki za kolite s maksimalen broi 3. Vuvejdam marka,model,godina i price
  120. {
  121.     int l;
  122.     cout << "Vuvedete broi uchasnichki:";
  123.     cin >> l;
  124.     cout << "1. Enter girls:" << endl;
  125.     for (int i = 0; i < l; i++)
  126.     {
  127.         cin.ignore();
  128.         cout << "Enter nomer: "; cin >> girls[i].nomer;
  129.         cout << "Enter ime: ";  cin>>girls[i].ime;
  130.         cout << "Enter familiq: "; cin>>girls[i].familiq;
  131.         cout << "Enter rojdennadata: "; cin >> girls[i].rojdennadata;
  132.         cout << "Enter godini: "; cin >> girls[i].godini;
  133.         cout << "Enter teglo: "; cin >> girls[i].teglo;
  134.         cout << "Enter visochina: "; cin >> girls[i].visochina;
  135.         cout << "Enter durjava: ";  cin>>girls[i].durjava;
  136.     }
  137.     return l;
  138. }
  139.  
  140. void UchastnichkiOut(Uchastnichki girls[], int l)//CarOut e za,da ni izvede informaciqta koqto sme vuveli v funkciqta CarIn
  141. {
  142.  
  143.     cout << "2. Print girls" << endl;
  144.     for (int i = 0; i < l; i++)
  145.     {
  146.         cout << "Uchastnichki " << i << endl;
  147.         cout << "nomer: " << girls[i].nomer << endl;
  148.         cout << "ime: " << girls[i].ime << endl;
  149.         cout << "familiq: " << girls[i].familiq << endl;
  150.         cout << "rojdennadata: " << girls[i].rojdennadata << endl;
  151.         cout << "godini: " << girls[i].godini << endl;
  152.         cout << "teglo: " << girls[i].teglo << endl;
  153.         cout << "visochina: " << girls[i].visochina << endl;
  154.         cout << "durjava: " << girls[i].durjava << endl;
  155.  
  156.     }
  157. }
  158. void UchastnichkiBinaryFileSave(Uchastnichki girls[], int count)
  159. {
  160.     cout << "3. Save girls in binary file" << endl;
  161.     fstream file;//fstream e  za zapis ili chetene,v tazi funkciq go iZpolzvam za zapis
  162.     file.open("girls.bin", ios::binary | ios::out);//zapisvame faila v binary(dvuichen kod) v fail "Cars.bin" tazi papka shte se namira v papkata kudeto se namira programata
  163.     file.write((char*)girls, count * (sizeof(Uchastnichki)));//chrez file.write se zapisva faila v binary kod. Faila se zapisva s char kato se umnojava po broq na goleminata na nashata strukturata (Car)
  164.     file.close();//zatvarq faila
  165. }
  166.  
  167. void UchastnichkiBinaryFileRead(Uchastnichki girls[])
  168. {
  169.     cout << "4. Read girls from binary file" << endl;
  170.     fstream file;//fstream e  za zapis ili chetene,v tazi funkciq go izpolzvam za chetene
  171.     file.open("girls.bin", ios::binary | ios::in);//otvarq faila
  172.     file.seekg(0L, ios::end);//chrez file.seekg , se izprasta kursora v kraq na prozoreca
  173.     long pos = (long)file.tellg();
  174.     file.close();//zatvarq faila
  175.     int n = pos / (sizeof(Uchastnichki));
  176.  
  177.     file.open("girls.bin", ios::binary | ios::in);//za da se prochete faila se vliza v Cars.bin
  178.     file.read((char*)girls, n * (sizeof(Uchastnichki)));//prochita se faila
  179.     file.close();//zatvarq faila
  180. }
  181.  
  182. void UchastnichkiTextFileSave(Uchastnichki girls[], int count)//zapisva cqlata informaciq za 3te knigi v tekstov fail
  183. {
  184.     cout << "5. Save girls in text file" << endl;
  185.     fstream file;//fstream e  za zapis ili chetene,v tazi funkciq go izpolzvam za zapis
  186.     file.open("girls.txt", ios::out);//zapisva se faila s razshirenie ".txt"
  187.     for (int i = 0; i < count; i++)//for cikul,koito produljava da se vurti dokato se vudedut dannite za 3te koli
  188.     {
  189.         file << girls[i].nomer << endl;
  190.         file << endl << endl;
  191.         file << girls[i].ime << endl;
  192.         file << endl << endl;
  193.         file << girls[i].familiq << endl;
  194.         file << endl << endl;
  195.         file << girls[i].rojdennadata << endl;
  196.         file << endl << endl;
  197.         file << girls[i].godini << endl;
  198.         file << endl << endl;
  199.         file << girls[i].teglo << endl;
  200.         file << endl << endl;
  201.         file << girls[i].visochina << endl;
  202.         file << endl << endl;
  203.         file << girls[i].durjava << endl;
  204.     }
  205.     file.close();//zatvarq faila
  206. }
  207.  
  208. void UchastnichkiTextFileRead(Uchastnichki girls[])//tazi funkciq e za prochitane na tekstoviq fail
  209. {
  210.     cout << "6. Read girls from text file" << endl;
  211.     fstream file;//fstream e  za zapis ili chetene,v tazi funkciq go izpolzvam za chetene
  212.     file.open("girls.txt", ios::in);//otvarq faila
  213.  
  214.     for (int i = 0; i < girlsCount; i++)
  215.     {
  216.         //file.ignore();
  217.         file >> girls[i].nomer;
  218.         file.getline(girls[i].ime, 50);
  219.         file.getline(girls[i].familiq, 50);
  220.         file >> girls[i].rojdennadata;
  221.         file >> girls[i].godini;
  222.         file >> girls[i].teglo;
  223.         file >> girls[i].visochina;
  224.         file.getline(girls[i].durjava, 50);
  225.     }
  226.  
  227.     file.close();//zatvarq go
  228. }
  229. void UchastnichkiOut2(Uchastnichki girls[], int count)
  230. {
  231.     int proverka(0), nomer;  //br(0),
  232.     string familiq;
  233.     char ch;
  234.     cout << "7. Vuvedete nomer i familiq na uchastnichka" << endl;
  235.     do
  236.     {
  237.         cout << "Vuvedete nomer" << endl;
  238.         cin >> nomer;
  239.         cout << "Vuvedete familiq" << endl;
  240.         cin >> familiq;
  241.         for (int i = 0; i<count; i++)
  242.         {
  243.             if ((nomer == girls[i].nomer) && (familiq == girls[i].familiq))
  244.             {
  245.                 cout << girls[i].nomer << endl;
  246.                 cout << girls[i].ime << endl;
  247.                 cout << girls[i].familiq << endl;
  248.                 cout << girls[i].rojdennadata << endl;
  249.                 cout << girls[i].godini << endl;
  250.                 cout << girls[i].teglo << endl;
  251.                 cout << girls[i].visochina << endl;
  252.                 cout << girls[i].durjava << endl;
  253.                 /*br++;*/
  254.                 break;
  255.             }
  256.             else
  257.             {
  258.                 cout << "Ne suvpada nomera ili familiqta molq vuvedete otnovo" << endl;
  259.                 break;
  260.             }
  261.         }
  262.         /*if (br == 0)
  263.         cout << "nqma takuv nomer" << endl;
  264.         br = 0;*/
  265.  
  266.         cout << "Ako iskate da produljite natisnete 'y': " << endl;
  267.         cin >> ch;
  268.         if (ch == 'y' || ch == 'Y')
  269.         {
  270.             proverka = 0;
  271.         }
  272.         else
  273.         {
  274.             proverka = 1;
  275.         }
  276.  
  277.     } while (proverka = 1);
  278. }
  279.  
  280. void UchastnichkiOut3(Uchastnichki girls[], int count)
  281. {
  282.     int m;
  283.     cout << "Vuvedete broi uchasnichki:";
  284.     cin >> m;
  285.     for (int i = 0; i < m; i++)
  286.     {
  287.         if (girls[i].godini <= 20)
  288.         {
  289.             cout << "Uchastnichki " << i << endl;
  290.             cout << "nomer: " << girls[i].nomer << endl;
  291.             cout << "ime: " << girls[i].ime << endl;
  292.             cout << "familiq: " << girls[i].familiq << endl;
  293.             cout << "rojdennadata: " << girls[i].rojdennadata << endl;
  294.             cout << "godini: " << girls[i].godini << endl;
  295.             cout << "teglo: " << girls[i].teglo << endl;
  296.             cout << "visochina: " << girls[i].visochina << endl;
  297.             cout << "durjava: " << girls[i].durjava << endl;
  298.         }
  299.     }
  300.  
  301. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top