Advertisement
mmayoub

תרגילי חזרה, שאלה 1

Nov 28th, 2021
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace TestExample28112021
  6. {
  7.     // part 1
  8.     class Contact
  9.     {
  10.         private string name;
  11.         private int phone;
  12.         private string city;
  13.  
  14.         // part 2
  15.         public Contact(string name, int phone, string city)
  16.         {
  17.  
  18.         }
  19.  
  20.         // part 3
  21.         public bool fromCity(string city)
  22.         {
  23.             if (this.city == city)
  24.             {
  25.                 return true;
  26.             }
  27.             else
  28.             {
  29.                 return false;
  30.             }
  31.         }
  32.     }
  33.     // end of class Contact
  34.  
  35.     // part 4
  36.     public static void part4(Contact[] arr)
  37.     {
  38.         string cityName;
  39.  
  40.         Console.Write("Enter city name: ");
  41.         cityName = Console.ReadLine();
  42.  
  43.         for (int i = 0; i < arr.Length; i++)
  44.         {
  45.             //if (arr[i].getCity() == cityName) {
  46.             if (arr[i].fromCity(cityName) == true)
  47.             {
  48.                 Console.WriteLine(arr[i].getName());
  49.             }
  50.         }
  51.  
  52.     }
  53.  
  54.     // part 5
  55.     public staic int find(Contact[] arr, string name)
  56.     {
  57.         for (int i = 0; i < arr.Length; i++)
  58.         {
  59.             if (arr[i].getName() == name)
  60.             {
  61.                 return arr[i].getPhone();
  62.             }
  63.         }
  64.  
  65.     }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement