MrSpooner

Day 1

Apr 3rd, 2018
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 4.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     public struct city
  10.     {
  11.         public string name;
  12.         public int inhabitats;
  13.     }
  14.     class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             city[] array = new city[500];
  19.             int citynumber = 0;
  20.             while (1==1)
  21.             {
  22.                 Console.WriteLine("1 .- Add a new city");
  23.                 Console.WriteLine("2 .- View all cities");
  24.                 Console.WriteLine("3 .- Modify a record");
  25.                 Console.WriteLine("4 .- Insert a new record");
  26.                 Console.WriteLine("5 .- Delete a record");
  27.                 Console.WriteLine("6 .- Search in the records");
  28.                 Console.WriteLine("7 .- Correct the capitalization of the names");
  29.  
  30.                 byte choice = Convert.ToByte(Console.ReadLine());
  31.                 switch (choice)
  32.                 {
  33.                     case 1:
  34.                         Console.WriteLine("Write name");
  35.                         array[citynumber].name = Console.ReadLine();
  36.                         Console.WriteLine("Write population");
  37.                         array[citynumber].inhabitats = Convert.ToInt32(Console.ReadLine());
  38.                         citynumber++;
  39.                         break;
  40.                     case 2:
  41.                         for (int i = 0; i < citynumber; i++)
  42.                         {
  43.                             Console.WriteLine("Name of city: {0}", array[i].name);
  44.                             Console.WriteLine("Population: {0}", array[i].inhabitats);
  45.                         }
  46.                         break;
  47.                     case 3:
  48.                         Console.WriteLine("Choose city");
  49.                         int chosenc = Convert.ToInt32(Console.ReadLine());
  50.                         string decision;
  51.  
  52.                         Console.WriteLine("Change population? Y/N");
  53.                         decision = Console.ReadLine();
  54.                         if (decision == "Y")
  55.                         {
  56.                             Console.WriteLine("Write population");
  57.                             array[chosenc].inhabitats = Convert.ToInt32(Console.ReadLine());
  58.                         }
  59.  
  60.  
  61.                         Console.WriteLine("Change name? Y/N");
  62.                         decision = Console.ReadLine();
  63.                         if (decision == "Y")
  64.                         {
  65.                             Console.WriteLine("Write name");
  66.                             array[chosenc].name = Console.ReadLine();
  67.                         }
  68.                         break;
  69.                     case 4:
  70.                         Console.WriteLine("Choose city number");
  71.                         int chosennumber = Convert.ToInt32(Console.ReadLine());
  72.                         for (int i = chosennumber; i < citynumber; i++)
  73.                         {
  74.                             array[i + 1] = array[i];
  75.                         }
  76.  
  77.                         Console.WriteLine("Write name");
  78.                         array[chosennumber].name = Console.ReadLine();
  79.                         Console.WriteLine("Write population");
  80.                         array[chosennumber].inhabitats = Convert.ToInt32(Console.ReadLine());
  81.  
  82.                         break;
  83.                     case 5:
  84.                         Console.WriteLine("Choose city number");
  85.                         int delnumb = Convert.ToInt32(Console.ReadLine());
  86.                         for (int i = delnumb; i < citynumber; i++)
  87.                         {
  88.                             array[i] = array[i + 1];
  89.                         }
  90.                         break;
  91.                     case 6:
  92.                         Console.WriteLine("Which city do you want to find? Write the name");
  93.                         string findname = Console.ReadLine();
  94.                         for (int i = 0; i <= citynumber; i++)
  95.                         {
  96.                             if (array[i].name == findname)
  97.                             {
  98.                                 Console.WriteLine("Number {0}, name {1}, population {2}", i, array[i].name, array[i].inhabitats);
  99.                             }
  100.                         }
  101.                         break;
  102.                     case 7:
  103.                         for (int i = 0; i <= citynumber; i++)
  104.                         {
  105.                             char.ToUpper(array[i].name[0]);
  106.                         }
  107.                         break;
  108.                     case 0:
  109.                         break;
  110.                 }
  111.            
  112.             }
  113.         }
  114.     }
  115. }
Add Comment
Please, Sign In to add comment