Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <windows.h>
- using namespace std;
- struct fridge{
- char country[20];
- char model[20];
- char quantity[20];
- };
- void print (const fridge &a)
- {
- cout<<a.country<<", "<<a.model<<", "<<a.quantity<<endl;
- }
- int search (fridge a[], char x[], int size, int beg)
- {
- for (int i=beg; i<size; i++)
- {
- if (strncmp(a[i].model, x, 4)==0) return i;
- }
- return 5;
- }
- main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int size = 4;
- fridge a[size] = {{"russian","2018samsung", "40"}, {"german","2018Bosh", "25"}, {"japan","2017sharp", "10"}, {"french","2016LG","3"}};
- for (int i = 0; i<size;i++) print(a[i]);
- char x[5];
- cout<< endl << endl << "Input fridge's year - ";
- gets(x);
- cout << endl << endl << endl;
- int y=-1;
- int k=0;
- do{
- y=search(a, x,size,y+1);
- if (y!=5)
- {
- print (a[y]);
- k++;
- }
- }
- while (y!=5);
- if (k==0) cout<<"Fridge this year is absent";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement