Advertisement
Ivan_Moscow

5.1.14.(2)

May 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. struct Adress {
  5.     int index;      //Индекс
  6.     char *city;     //Город
  7.     char *street;   //Улица
  8.     int house;      //Дом
  9. };
  10.  
  11. void searchByIndex (Adress target[], int len, int index) {
  12.     for (int i=0; i<len; i++) {
  13.         if (target[i].index == index) {
  14.             std::cout<<"\nCity:"<<target[i].city;
  15.             std::cout<<"\nStreet:"<<target[i].street;
  16.             std::cout<<"\nHouse:"<<target[i].house<<"\n";
  17.         }
  18.     }
  19.     return;
  20. }
  21.  
  22. int _tmain(int argc, _TCHAR* argv[]) {
  23.     char *cNames[] = {"Volgograd", "Voronezh", "Rostov", "Krasnodar", "Saratov",};
  24.     Adress myAdrBook[20];
  25.     for (int i=0; i<20; i++) {
  26.         myAdrBook[i].city = cNames[rand()%5];
  27.         myAdrBook[i].street = "...";
  28.         myAdrBook[i].house = rand()%100;
  29.         myAdrBook[i].index = i%5;
  30.     }
  31.     //Попробуем найти все адреса с индексом 3
  32.     searchByIndex(myAdrBook, 20, 3);
  33.     system("pause");
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement