Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- public struct city
- {
- public string name;
- public int inhabitats;
- }
- class Program
- {
- static void Main(string[] args)
- {
- city[] array = new city[500];
- int citynumber = 0;
- while (1==1)
- {
- Console.WriteLine("1 .- Add a new city");
- Console.WriteLine("2 .- View all cities");
- Console.WriteLine("3 .- Modify a record");
- Console.WriteLine("4 .- Insert a new record");
- Console.WriteLine("5 .- Delete a record");
- Console.WriteLine("6 .- Search in the records");
- Console.WriteLine("7 .- Correct the capitalization of the names");
- byte choice = Convert.ToByte(Console.ReadLine());
- switch (choice)
- {
- case 1:
- Console.WriteLine("Write name");
- array[citynumber].name = Console.ReadLine();
- Console.WriteLine("Write population");
- array[citynumber].inhabitats = Convert.ToInt32(Console.ReadLine());
- citynumber++;
- break;
- case 2:
- for (int i = 0; i < citynumber; i++)
- {
- Console.WriteLine("Name of city: {0}", array[i].name);
- Console.WriteLine("Population: {0}", array[i].inhabitats);
- }
- break;
- case 3:
- Console.WriteLine("Choose city");
- int chosenc = Convert.ToInt32(Console.ReadLine());
- string decision;
- Console.WriteLine("Change population? Y/N");
- decision = Console.ReadLine();
- if (decision == "Y")
- {
- Console.WriteLine("Write population");
- array[chosenc].inhabitats = Convert.ToInt32(Console.ReadLine());
- }
- Console.WriteLine("Change name? Y/N");
- decision = Console.ReadLine();
- if (decision == "Y")
- {
- Console.WriteLine("Write name");
- array[chosenc].name = Console.ReadLine();
- }
- break;
- case 4:
- Console.WriteLine("Choose city number");
- int chosennumber = Convert.ToInt32(Console.ReadLine());
- for (int i = chosennumber; i < citynumber; i++)
- {
- array[i + 1] = array[i];
- }
- Console.WriteLine("Write name");
- array[chosennumber].name = Console.ReadLine();
- Console.WriteLine("Write population");
- array[chosennumber].inhabitats = Convert.ToInt32(Console.ReadLine());
- break;
- case 5:
- Console.WriteLine("Choose city number");
- int delnumb = Convert.ToInt32(Console.ReadLine());
- for (int i = delnumb; i < citynumber; i++)
- {
- array[i] = array[i + 1];
- }
- break;
- case 6:
- Console.WriteLine("Which city do you want to find? Write the name");
- string findname = Console.ReadLine();
- for (int i = 0; i <= citynumber; i++)
- {
- if (array[i].name == findname)
- {
- Console.WriteLine("Number {0}, name {1}, population {2}", i, array[i].name, array[i].inhabitats);
- }
- }
- break;
- case 7:
- for (int i = 0; i <= citynumber; i++)
- {
- char.ToUpper(array[i].name[0]);
- }
- break;
- case 0:
- break;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment