Example #1
0
 public static void PrintAllPlacesToConsole(PlaceOfInterestContainer place)
 {
     for (int i = 0; i < place.Count; i++)
     {
         Console.WriteLine(place.GetPlace(i).ToString());
     }
 }
Example #2
0
 public static void PlacesToFile(PlaceOfInterestContainer places, string fName)
 {
     using (StreamWriter writer = new StreamWriter(fName))
     {
         for (int i = 0; i < places.Count; i++)
         {
             writer.WriteLine(places.GetPlace(i).ToCsv());
         }
     }
 }
Example #3
0
        public static PlaceOfInterestContainer JoinCitiesPlaces(City[] cities)
        {
            PlaceOfInterestContainer allPlaces = new PlaceOfInterestContainer(MaxPlaces);

            foreach (City city in cities)
            {
                JoinPlaces(city.Monuments, city.Museums, allPlaces);
            }

            return(allPlaces);
        }
Example #4
0
        //Printing to console end

        public static void JoinPlaces(PlaceOfInterestContainer places1, PlaceOfInterestContainer places2, PlaceOfInterestContainer newPlace)
        {
            for (int i = 0; i < places1.Count; i++)
            {
                newPlace.AddPlace(places1.GetPlace(i));
            }
            for (int i = 0; i < places2.Count; i++)
            {
                newPlace.AddPlace(places2.GetPlace(i));
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            City[] cities = new City[MaxCities];

            cities[0] = new City("Kaunas");
            cities[1] = new City("Vilnius");
            cities[2] = new City("Panevezys");

            string[] filePaths = Directory.GetFiles(Directory.GetCurrentDirectory(), "L4Data_*.csv");
            foreach (string path in filePaths)
            {
                ReadCityData(cities, path);
            }

            DataTableToFile(cities, "table.txt");

            PrintGuideCountsToConsole(cities);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Oldest place:");
            Console.ForegroundColor = ConsoleColor.Gray;

            PrintPlaceToConsole((FindOldestPlace(cities)));
            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Sorted by year and by name:");
            Console.ForegroundColor = ConsoleColor.Gray;

            PlaceOfInterestContainer sortedPlaces = SortCityPlaces(cities);

            PrintAllPlacesToConsole(sortedPlaces);
            PlaceNamesToFile(sortedPlaces, "VisosVietos.csv");

            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Places after 1990:");
            Console.ForegroundColor = ConsoleColor.Gray;

            PlaceOfInterestContainer afterYear = PlacesAfterCertainYear(cities, 1990);

            PrintAllPlacesToConsole(afterYear);
            PlacesToFile(afterYear, "Po1990.csv");

            Console.ReadLine();
        }
Example #6
0
        public static PlaceOfInterestContainer PlacesAfterCertainYear(City[] cities, int minYear)
        {
            PlaceOfInterestContainer all = new PlaceOfInterestContainer(MaxPlaces);

            all = JoinCitiesPlaces(cities);

            PlaceOfInterestContainer filtered = new PlaceOfInterestContainer(all.Count);

            for (int i = 0; i < all.Count; i++)
            {
                if (all.GetPlace(i).Year > minYear)
                {
                    filtered.AddPlace(all.GetPlace(i));
                }
            }

            return(filtered);
        }
Example #7
0
        public static PlaceOfInterestContainer SortCityPlaces(City[] cities)
        {
            PlaceOfInterestContainer allPlaces = JoinCitiesPlaces(cities);

            int minPos = 0;

            for (int i = 0; i < allPlaces.Count; i++)
            {
                minPos = i;

                for (int j = i + 1; j < allPlaces.Count; j++)
                {
                    if (allPlaces.GetPlace(j).Year < allPlaces.GetPlace(minPos).Year)
                    {
                        minPos = j;
                    }
                }

                if (minPos != i)
                {
                    PlaceOfInterest temp = allPlaces.GetPlace(i);
                    allPlaces.SetPlace(allPlaces.GetPlace(minPos), i);
                    allPlaces.SetPlace(temp, minPos);
                }
                else
                {
                    for (int j = i + 1; j < allPlaces.Count; j++)
                    {
                        //CompareTo returns -1 if first string is "smaller"
                        if (allPlaces.GetPlace(i).Name.CompareTo(allPlaces.GetPlace(minPos).Name) < 0)
                        {
                            minPos = j;
                        }
                    }
                    if (minPos != i)
                    {
                        PlaceOfInterest temp = allPlaces.GetPlace(i);
                        allPlaces.SetPlace(allPlaces.GetPlace(minPos), i);
                        allPlaces.SetPlace(temp, minPos);
                    }
                }
            }
            return(allPlaces);
        }
Example #8
0
        public static PlaceOfInterest FindOldestPlace(City[] cities)
        {
            PlaceOfInterestContainer allPlaces = new PlaceOfInterestContainer(MaxPlaces);

            foreach (City city in cities)
            {
                JoinPlaces(city.Monuments, city.Museums, allPlaces);
            }

            int minIndex = 0;
            int minValue = 3000;

            for (int i = 0; i < allPlaces.Count; i++)
            {
                if (allPlaces.GetPlace(i).Year < minValue)
                {
                    minValue = allPlaces.GetPlace(i).Year;
                    minIndex = i;
                }
            }
            return(allPlaces.GetPlace(minIndex));
        }