Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <windows.h>
  4. using namespace std;
  5.  
  6.  
  7. struct fridge{
  8. char country[20];
  9. char model[20];
  10. char quantity[20];
  11. };
  12.  
  13. void print (const fridge &a)
  14. {
  15. cout<<a.country<<", "<<a.model<<", "<<a.quantity<<endl;
  16. }
  17.  
  18.  
  19. int search (fridge a[], char x[], int size, int beg)
  20. {
  21.  
  22.  
  23. for (int i=beg; i<size; i++)
  24. {
  25. if (strncmp(a[i].model, x, 4)==0) return i;
  26.  
  27. }
  28. return 5;
  29. }
  30.  
  31. main()
  32. {
  33. SetConsoleCP(1251);
  34. SetConsoleOutputCP(1251);
  35. int size = 4;
  36. fridge a[size] = {{"russian","2018samsung", "40"}, {"german","2018Bosh", "25"}, {"japan","2017sharp", "10"}, {"french","2016LG","3"}};
  37.  
  38. for (int i = 0; i<size;i++) print(a[i]);
  39. char x[5];
  40. cout<< endl << endl << "Input fridge's year - ";
  41. gets(x);
  42. cout << endl << endl << endl;
  43. int y=-1;
  44. int k=0;
  45. do{
  46. y=search(a, x,size,y+1);
  47. if (y!=5)
  48. {
  49. print (a[y]);
  50. k++;
  51. }
  52. }
  53. while (y!=5);
  54. if (k==0) cout<<"Fridge this year is absent";
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement