fix: merge submodule 'Lab3'
This commit is contained in:
commit
8a57967a88
14
Lab3/.editorconfig
Normal file
14
Lab3/.editorconfig
Normal file
@ -0,0 +1,14 @@
|
||||
root=true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_style = tab
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.cs]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
388
Lab3/.gitignore
vendored
Normal file
388
Lab3/.gitignore
vendored
Normal file
@ -0,0 +1,388 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.tlog
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*.json
|
||||
coverage*.xml
|
||||
coverage*.info
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Nuget personal access tokens and Credentials
|
||||
# nuget.config
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
|
||||
# VS Code files for those working on multiple tools
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Windows Installer files from build outputs
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
76
Lab3/Lab3.Exercises.Register/Dog.cs
Normal file
76
Lab3/Lab3.Exercises.Register/Dog.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab3.Exercises.Register
|
||||
{
|
||||
class Dog
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Breed { get; set; }
|
||||
public DateTime BirthDate { get; set; }
|
||||
public Gender Gender { get; set; }
|
||||
public DateTime LastVaccinationDate { get; set; }
|
||||
|
||||
private const int VaccinationDuration = 1;
|
||||
|
||||
public int Age
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime today = DateTime.Today;
|
||||
int age = today.Year - this.BirthDate.Year;
|
||||
if (BirthDate.Date > today.AddYears(-age))
|
||||
{
|
||||
age--;
|
||||
}
|
||||
return age;
|
||||
}
|
||||
}
|
||||
|
||||
public bool RequiresVaccination
|
||||
{
|
||||
get
|
||||
{
|
||||
if (LastVaccinationDate.Equals(DateTime.MinValue))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return LastVaccinationDate.AddYears(VaccinationDuration).CompareTo(DateTime.Now) < 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Dog(int id, string name, string breed, DateTime birthDate, Gender gender)
|
||||
{
|
||||
ID = id;
|
||||
Name = name;
|
||||
Breed = breed;
|
||||
BirthDate = birthDate;
|
||||
Gender = gender;
|
||||
}
|
||||
|
||||
public override bool Equals(object other)
|
||||
{
|
||||
return ID == ((Dog)other).ID;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ID.GetHashCode();
|
||||
}
|
||||
|
||||
public int CompareTo(Dog other)
|
||||
{
|
||||
int genderComparison = Gender.CompareTo(other.Gender);
|
||||
if (genderComparison == 0)
|
||||
{
|
||||
return Breed.CompareTo(other.Breed);
|
||||
}
|
||||
else
|
||||
{
|
||||
return genderComparison;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
8
Lab3/Lab3.Exercises.Register/Dogs.csv
Normal file
8
Lab3/Lab3.Exercises.Register/Dogs.csv
Normal file
@ -0,0 +1,8 @@
|
||||
123;Reksas;Buldogas;2014-01-01;Male
|
||||
124;Margis;Dalmantinas;2014-02-28;Male
|
||||
125;Bitė;Senbernaras;2008-07-17;Female
|
||||
320;Rikis;Taksas;2012-01-07;Male
|
||||
123;Reksas;Buldogas;2014-01-01;Male
|
||||
415;Pifas;Taksas;2014-07-07;Male
|
||||
420;Markas;Dalmantinas;2013-02-28;Female
|
||||
123;Reksas;Buldogas;2014-01-01;Male
|
|
145
Lab3/Lab3.Exercises.Register/DogsContainer.cs
Normal file
145
Lab3/Lab3.Exercises.Register/DogsContainer.cs
Normal file
@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab3.Exercises.Register
|
||||
{
|
||||
class DogsContainer
|
||||
{
|
||||
private Dog[] dogs;
|
||||
private int Capacity;
|
||||
public int Count { get; private set; }
|
||||
|
||||
public DogsContainer(int capacity = 16)
|
||||
{
|
||||
Capacity = capacity;
|
||||
dogs = new Dog[capacity];
|
||||
}
|
||||
|
||||
public DogsContainer(DogsContainer container) : this(container.Capacity) //call another constructor
|
||||
{
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
Add(container.Get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(Dog dog)
|
||||
{
|
||||
if (Count == Capacity)
|
||||
{
|
||||
EnsureCapacity(Capacity * 2);
|
||||
}
|
||||
|
||||
dogs[Count] = dog;
|
||||
Count++;
|
||||
}
|
||||
public Dog Get(int index)
|
||||
{
|
||||
return dogs[index];
|
||||
}
|
||||
public bool Contains(Dog dog)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (dogs[i].Equals(dog))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Put(int index, Dog dog)
|
||||
{
|
||||
dogs[index] = dog;
|
||||
}
|
||||
|
||||
public void Insert(int index, Dog dog)
|
||||
{
|
||||
if (Count == Capacity)
|
||||
{
|
||||
EnsureCapacity(Capacity * 2);
|
||||
}
|
||||
for (int i = Count+1; i > index; i--)
|
||||
{
|
||||
dogs[i] = dogs[i-1];
|
||||
}
|
||||
dogs[index] = dog;
|
||||
Count++;
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
for (int i = index; i < Count; i++)
|
||||
{
|
||||
dogs[i] = dogs[i + 1];
|
||||
}
|
||||
Count--;
|
||||
}
|
||||
|
||||
public void Remove(Dog dog)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (dogs[i].ID == dog.ID)
|
||||
{
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureCapacity(int minimumCapacity)
|
||||
{
|
||||
if (minimumCapacity > Capacity)
|
||||
{
|
||||
Dog[] dogsClone = new Dog[minimumCapacity];
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
dogsClone[i] = dogs[i];
|
||||
}
|
||||
Capacity = minimumCapacity;
|
||||
dogs = dogsClone;
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort()
|
||||
{
|
||||
bool flag = true;
|
||||
while (flag)
|
||||
{
|
||||
flag = false;
|
||||
for (int i = 0; i < this.Count - 1; i++)
|
||||
{
|
||||
Dog a = this.dogs[i];
|
||||
Dog b = this.dogs[i + 1];
|
||||
if (a.CompareTo(b) > 0)
|
||||
{
|
||||
this.dogs[i] = b;
|
||||
this.dogs[i + 1] = a;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DogsContainer Intersect(DogsContainer other)
|
||||
{
|
||||
DogsContainer result = new DogsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Dog current = dogs[i];
|
||||
if (other.Contains(current))
|
||||
{
|
||||
result.Add(current);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
131
Lab3/Lab3.Exercises.Register/DogsRegister.cs
Normal file
131
Lab3/Lab3.Exercises.Register/DogsRegister.cs
Normal file
@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab3.Exercises.Register
|
||||
{
|
||||
class DogsRegister
|
||||
{
|
||||
private DogsContainer AllDogs;
|
||||
public DogsRegister()
|
||||
{
|
||||
AllDogs = new DogsContainer();
|
||||
}
|
||||
public DogsRegister(DogsContainer Dogs)
|
||||
{
|
||||
AllDogs = new DogsContainer();
|
||||
for (int i = 0; i < Dogs.Count; i++)
|
||||
{
|
||||
this.AllDogs.Add(Dogs.Get(i));
|
||||
}
|
||||
}
|
||||
public void Add(Dog dog)
|
||||
{
|
||||
AllDogs.Add(dog);
|
||||
}
|
||||
|
||||
public int DogsCount()
|
||||
{
|
||||
return AllDogs.Count;
|
||||
}
|
||||
|
||||
public Dog GetByIndex(int index)
|
||||
{
|
||||
return AllDogs.Get(index);
|
||||
}
|
||||
|
||||
public int CountByGender(Gender gender)
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < AllDogs.Count; i++)
|
||||
{
|
||||
Dog dog = AllDogs.Get(i);
|
||||
if (dog.Gender.Equals(gender))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public Dog FindOldestDog()
|
||||
{
|
||||
return this.FindOldestDog(this.AllDogs);
|
||||
}
|
||||
|
||||
public DogsContainer FilterByBreed(string breed)
|
||||
{
|
||||
DogsContainer Filtered = new DogsContainer();
|
||||
for (int i = 0; i < AllDogs.Count; i++)
|
||||
{
|
||||
Dog dog = AllDogs.Get(i);
|
||||
if (dog.Breed.Equals(breed)) // uses string method Equals()
|
||||
{
|
||||
Filtered.Add(dog);
|
||||
}
|
||||
}
|
||||
return Filtered;
|
||||
}
|
||||
|
||||
public Dog FindOldestDog(string breed)
|
||||
{
|
||||
DogsContainer Filtered = this.FilterByBreed(breed);
|
||||
return this.FindOldestDog(Filtered);
|
||||
}
|
||||
private Dog FindOldestDog(DogsContainer Dogs)
|
||||
{
|
||||
Dog oldest = Dogs.Get(0);
|
||||
for (int i = 1; i < Dogs.Count; i++) //starts on index value 1
|
||||
{
|
||||
Dog dog = Dogs.Get(i);
|
||||
if (DateTime.Compare(oldest.BirthDate, dog.BirthDate) > 0)
|
||||
{
|
||||
oldest = dog;
|
||||
}
|
||||
}
|
||||
return oldest;
|
||||
}
|
||||
private Dog FindDogByID(int ID)
|
||||
{
|
||||
for (int i = 0; i < AllDogs.Count; i++)
|
||||
{
|
||||
Dog dog = AllDogs.Get(i);
|
||||
if (dog.ID == ID)
|
||||
{
|
||||
return dog;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
public void UpdateVaccinationsInfo(List<Vaccination> Vaccinations)
|
||||
{
|
||||
foreach (Vaccination vaccination in Vaccinations)
|
||||
{
|
||||
Dog dog = FindDogByID(vaccination.DogID);
|
||||
if (dog != null && vaccination > dog.LastVaccinationDate)
|
||||
{
|
||||
dog.LastVaccinationDate = vaccination.Date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DogsContainer FilterByVaccinationExpired()
|
||||
{
|
||||
DogsContainer Filtered = new DogsContainer();
|
||||
for (int i = 0; i < AllDogs.Count; i++)
|
||||
{
|
||||
Dog dog = AllDogs.Get(i);
|
||||
if (dog.RequiresVaccination)
|
||||
{
|
||||
Filtered.Add(dog);
|
||||
}
|
||||
}
|
||||
return Filtered;
|
||||
}
|
||||
public bool Contains(Dog dog)
|
||||
{
|
||||
return AllDogs.Contains(dog);
|
||||
}
|
||||
}
|
||||
}
|
12
Lab3/Lab3.Exercises.Register/Gender.cs
Normal file
12
Lab3/Lab3.Exercises.Register/Gender.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab3.Exercises.Register
|
||||
{
|
||||
enum Gender
|
||||
{
|
||||
Male = 1,
|
||||
Female = 2,
|
||||
}
|
||||
}
|
140
Lab3/Lab3.Exercises.Register/InOutUtils.cs
Normal file
140
Lab3/Lab3.Exercises.Register/InOutUtils.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab3.Exercises.Register
|
||||
{
|
||||
class InOutUtils
|
||||
{
|
||||
public static List<Vaccination> ReadVaccinations(string fileName)
|
||||
{
|
||||
List<Vaccination> Vaccinations = new List<Vaccination>();
|
||||
string[] Lines = File.ReadAllLines(fileName);
|
||||
foreach (string line in Lines)
|
||||
{
|
||||
string[] values = line.Split(';');
|
||||
int id = int.Parse(values[0]);
|
||||
DateTime vaccinationDate = DateTime.Parse(values[1]);
|
||||
Vaccination v = new Vaccination(id, vaccinationDate);
|
||||
Vaccinations.Add(v);
|
||||
}
|
||||
return Vaccinations;
|
||||
}
|
||||
|
||||
public static DogsContainer ReadDogs(string fileName)
|
||||
{
|
||||
DogsContainer Dogs = new DogsContainer();
|
||||
string[] lines = File.ReadAllLines(fileName, Encoding.UTF8);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string[] values = line.Split(';');
|
||||
int id = int.Parse(values[0]);
|
||||
string name = values[1];
|
||||
string breed = values[2];
|
||||
DateTime birthDate = DateTime.Parse(values[3]);
|
||||
Gender gender;
|
||||
Enum.TryParse(values[4], out gender); //tries to convert value to enum
|
||||
Dog dog = new Dog(id, name, breed, birthDate, gender);
|
||||
if (!Dogs.Contains(dog))
|
||||
{
|
||||
Dogs.Add(dog);
|
||||
}
|
||||
}
|
||||
return Dogs;
|
||||
}
|
||||
public static void PrintDogs(DogsRegister register)
|
||||
{
|
||||
PrintDogsHeader();
|
||||
for (int i = 0; i < register.DogsCount(); i++)
|
||||
{
|
||||
Dog dog = register.GetByIndex(i);
|
||||
PrintDogsRow(register.GetByIndex(i));
|
||||
}
|
||||
PrintDogsFooter();
|
||||
}
|
||||
|
||||
public static void PrintDogs(List<Dog> dogs)
|
||||
{
|
||||
PrintDogsHeader();
|
||||
foreach (Dog dog in dogs)
|
||||
{
|
||||
PrintDogsRow(dog);
|
||||
}
|
||||
PrintDogsFooter();
|
||||
}
|
||||
|
||||
public static void PrintDogs(DogsContainer container)
|
||||
{
|
||||
PrintDogsHeader();
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
Dog dog = container.Get(i);
|
||||
PrintDogsRow(dog);
|
||||
}
|
||||
PrintDogsFooter();
|
||||
}
|
||||
|
||||
public static void PrintDogs(string label, DogsContainer container)
|
||||
{
|
||||
PrintDogsHeader(label);
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
Dog dog = container.Get(i);
|
||||
PrintDogsRow(dog);
|
||||
}
|
||||
PrintDogsFooter();
|
||||
}
|
||||
|
||||
private static void PrintDogsHeader()
|
||||
{
|
||||
Console.WriteLine(new string('-', 74));
|
||||
Console.WriteLine("| {0,8} | {1,-15} | {2,-15} | {3,-12} | {4,-8} |", "Reg.Nr.", "Vardas", "Veislė", "Gimimo data", "Lytis");
|
||||
Console.WriteLine(new string('-', 74));
|
||||
}
|
||||
|
||||
private static void PrintDogsHeader(string label)
|
||||
{
|
||||
Console.WriteLine(new string('-', 74));
|
||||
Console.WriteLine("| {0,-70} |", label);
|
||||
Console.WriteLine(new string('-', 74));
|
||||
Console.WriteLine("| {0,8} | {1,-15} | {2,-15} | {3,-12} | {4,-8} |", "Reg.Nr.", "Vardas", "Veislė", "Gimimo data", "Lytis");
|
||||
Console.WriteLine(new string('-', 74));
|
||||
}
|
||||
|
||||
private static void PrintDogsFooter()
|
||||
{
|
||||
Console.WriteLine(new string('-', 74));
|
||||
}
|
||||
|
||||
private static void PrintDogsRow(Dog dog)
|
||||
{
|
||||
Console.WriteLine("| {0,8} | {1,-15} | {2,-15} | {3,-12:yyyy-MM-dd} | {4,-8} |", dog.ID, dog.Name, dog.Breed, dog.BirthDate, dog.Gender);
|
||||
}
|
||||
|
||||
|
||||
public static void PrintDog(Dog dog)
|
||||
{
|
||||
Console.WriteLine("Vardas: {0}, Veislė: {1}, Amžius: {2}", dog.Name, dog.Breed, dog.Age);
|
||||
}
|
||||
|
||||
public static void PrintBreeds(List<string> breeds)
|
||||
{
|
||||
foreach (string breed in breeds)
|
||||
{
|
||||
Console.WriteLine(breed);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PrintDogsToCSVFile(string fileName, List<Dog> Dogs)
|
||||
{
|
||||
string[] lines = new string[Dogs.Count + 1];
|
||||
lines[0] = String.Format("{0};{1};{2};{3};{4}", "Reg.Nr.", "Vardas", "Veislė", "Gimimo data", "Lytis");
|
||||
for (int i = 0; i < Dogs.Count; i++)
|
||||
{
|
||||
lines[i + 1] = String.Format("{0};{1};{2};{3};{4}", Dogs[i].ID, Dogs[i].Name, Dogs[i].Breed, Dogs[i].BirthDate, Dogs[i].Gender);
|
||||
}
|
||||
File.WriteAllLines(fileName, lines, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
17
Lab3/Lab3.Exercises.Register/Lab3.Exercises.Register.csproj
Normal file
17
Lab3/Lab3.Exercises.Register/Lab3.Exercises.Register.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Dogs.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Vaccinations.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
100
Lab3/Lab3.Exercises.Register/Program.cs
Normal file
100
Lab3/Lab3.Exercises.Register/Program.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab3.Exercises.Register
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Dog dog1 = new Dog(1, "Foo", "FooBreed", DateTime.Now, Gender.Male);
|
||||
|
||||
Dog dog2 = new Dog(2, "Bar", "BarBreed", DateTime.Now, Gender.Male);
|
||||
|
||||
Dog dog3 = new Dog(3, "Baz", "BazBreed", DateTime.Now, Gender.Female);
|
||||
|
||||
DogsContainer container = new DogsContainer();
|
||||
container.Add(dog1);
|
||||
container.Add(dog2);
|
||||
container.Add(dog3);
|
||||
InOutUtils.PrintDogs(container);
|
||||
container.Remove(1);
|
||||
InOutUtils.PrintDogs(container);
|
||||
|
||||
/*
|
||||
DogsContainer container = InOutUtils.ReadDogs("Dogs.csv");
|
||||
container.Sort();
|
||||
InOutUtils.PrintDogs("Container", container);
|
||||
|
||||
DogsContainer otherContainer = new DogsContainer(container);
|
||||
InOutUtils.PrintDogs("Other container", otherContainer);
|
||||
*/
|
||||
|
||||
/*
|
||||
DogsContainer container = InOutUtils.ReadDogs("Dogs.csv");
|
||||
DogsRegister register = new DogsRegister(container);
|
||||
List<Vaccination> vaccinationsData = InOutUtils.ReadVaccinations(@"Vaccinations.csv");
|
||||
register.UpdateVaccinationsInfo(vaccinationsData);
|
||||
|
||||
Console.WriteLine("Registro informacija:");
|
||||
InOutUtils.PrintDogs(register);
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("Iš viso šunų: {0}", register.DogsCount());
|
||||
Console.WriteLine("Patinų: {0}", register.CountByGender(Gender.Male));
|
||||
Console.WriteLine("Patelių: {0}", register.CountByGender(Gender.Female));
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("Šunys kuriems reikia vakcinuotis:");
|
||||
DogsContainer dogsThatNeedVaccination = register.FilterByVaccinationExpired();
|
||||
InOutUtils.PrintDogs(dogsThatNeedVaccination);
|
||||
Console.WriteLine();
|
||||
|
||||
string vaccinationBreed = "Taksas";
|
||||
DogsContainer allDogsByBreed = register.FilterByBreed(vaccinationBreed);
|
||||
Console.WriteLine("Šunys kuriems reikia vakcinuotis ({0}):", vaccinationBreed);
|
||||
InOutUtils.PrintDogs(allDogsByBreed.Intersect(dogsThatNeedVaccination));
|
||||
*/
|
||||
|
||||
/*
|
||||
Dog oldestDog = TaskUtils.FindOldestDog(register);
|
||||
Console.WriteLine("Seniausias šuo:");
|
||||
InOutUtils.PrintDog(oldestDog);
|
||||
Console.WriteLine();
|
||||
|
||||
List<string> breeds = TaskUtils.FindBreeds(register);
|
||||
Console.WriteLine("Šunų veislės:");
|
||||
InOutUtils.PrintBreeds(breeds);
|
||||
Console.WriteLine();
|
||||
|
||||
List<string> popularBreeds = TaskUtils.FindMostPopularBreeds(register);
|
||||
Console.WriteLine("Populiariausios šunų veislės:");
|
||||
InOutUtils.PrintBreeds(popularBreeds);
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("Kokios veislės šunis atrinkti?");
|
||||
string selectedBreed = Console.ReadLine().Trim();
|
||||
if (selectedBreed.Equals(""))
|
||||
{
|
||||
Console.WriteLine("Šunio veislė neįvesta");
|
||||
return;
|
||||
}
|
||||
|
||||
List<Dog> filteredByBreed = TaskUtils.FilterByBreed(register, selectedBreed);
|
||||
if (filteredByBreed.Count == 0)
|
||||
{
|
||||
Console.WriteLine("Šunų su veisle '{0}' nerasta", selectedBreed);
|
||||
return;
|
||||
}
|
||||
|
||||
Dog oldestFilteredDog = TaskUtils.FindOldestDog(filteredByBreed);
|
||||
Console.WriteLine("Seniausias šuo pagal '{0}' veislę:", selectedBreed);
|
||||
InOutUtils.PrintDog(oldestFilteredDog);
|
||||
InOutUtils.PrintDogs(filteredByBreed);
|
||||
string fileName = selectedBreed + ".csv";
|
||||
InOutUtils.PrintDogsToCSVFile(fileName, filteredByBreed);
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
26
Lab3/Lab3.Exercises.Register/Vaccination.cs
Normal file
26
Lab3/Lab3.Exercises.Register/Vaccination.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab3.Exercises.Register
|
||||
{
|
||||
class Vaccination
|
||||
{
|
||||
public int DogID { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public Vaccination(int dogID, DateTime date)
|
||||
{
|
||||
DogID = dogID;
|
||||
Date = date;
|
||||
}
|
||||
public static bool operator <(Vaccination vaccination, DateTime date)
|
||||
{
|
||||
return vaccination.Date.CompareTo(date) < 0;
|
||||
}
|
||||
public static bool operator >(Vaccination vaccination, DateTime date)
|
||||
{
|
||||
return vaccination.Date.CompareTo(date) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
6
Lab3/Lab3.Exercises.Register/Vaccinations.csv
Normal file
6
Lab3/Lab3.Exercises.Register/Vaccinations.csv
Normal file
@ -0,0 +1,6 @@
|
||||
123;2020-07-24
|
||||
124;2021-05-17
|
||||
421;2021-07-01
|
||||
125;2021-01-01
|
||||
320;2021-07-01
|
||||
320;2010-07-01
|
|
213
Lab3/Lab3.TouristInformationCenter/InOutUtils.cs
Normal file
213
Lab3/Lab3.TouristInformationCenter/InOutUtils.cs
Normal file
@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace Lab3.TouristInformationCenter
|
||||
{
|
||||
/// <summary>
|
||||
/// Class that stores functions that are related to reading and writing data
|
||||
/// </summary>
|
||||
class InOutUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Append the museums from the second container to the first one
|
||||
/// </summary>
|
||||
/// <param name="container1">First container</param>
|
||||
/// <param name="container2">Second container</param>
|
||||
private static void AppendContainer(MuseumsContainer container1, MuseumsContainer container2)
|
||||
{
|
||||
for (int i = 0; i < container2.Count; i++)
|
||||
{
|
||||
container1.Add(container2.Get(i));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode a list of museums from a given list of lines.
|
||||
/// </summary>
|
||||
/// <param name="lines"></param>
|
||||
/// <returns>Container of museums</returns>
|
||||
public static MuseumsContainer DecodeMuseums(List<string> lines)
|
||||
{
|
||||
MuseumsContainer container = new MuseumsContainer(lines.Count-2);
|
||||
string city = lines[0];
|
||||
string manager = lines[1];
|
||||
for (int i = 2; i < lines.Count; i++)
|
||||
{
|
||||
string line = lines[i];
|
||||
string[] values = line.Split(';');
|
||||
string name = values[0];
|
||||
string type = values[1];
|
||||
List<Weekday> workdays = new List<Weekday>();
|
||||
for (int j = 1; j <= 7; j++)
|
||||
{
|
||||
if (int.Parse(values[j + 1]) == 1)
|
||||
{
|
||||
workdays.Add((Weekday)j);
|
||||
}
|
||||
}
|
||||
double price = double.Parse(values[9]);
|
||||
bool hasGuide = int.Parse(values[10]) == 1;
|
||||
|
||||
Museum museum = new Museum(name, city, manager, type, workdays, price, hasGuide);
|
||||
container.Add(museum);
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read and decode a list of museums from a file.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target file</param>
|
||||
/// <returns>Container of museums</returns>
|
||||
public static MuseumsContainer ReadMuseumsFromCSV(string filename)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
foreach (string line in File.ReadAllLines(filename, Encoding.UTF8))
|
||||
{
|
||||
lines.Add(line);
|
||||
}
|
||||
return DecodeMuseums(lines);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read all the entries from a zip file and decode the museums inside the csv entries.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target filename</param>
|
||||
/// <returns>Register of museums</returns>
|
||||
public static MuseumsContainer ReadMuseumsFromZIP(string filename)
|
||||
{
|
||||
MuseumsContainer mainContainer = new MuseumsContainer();
|
||||
|
||||
using (ZipArchive zipFile = ZipFile.Open(filename, ZipArchiveMode.Read))
|
||||
{
|
||||
foreach (ZipArchiveEntry entry in zipFile.Entries)
|
||||
{
|
||||
if (!entry.Name.EndsWith(".csv")) continue;
|
||||
List<string> lines = new List<string>();
|
||||
using (StreamReader reader = new StreamReader(entry.Open(), Encoding.UTF8))
|
||||
{
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
lines.Add(reader.ReadLine());
|
||||
}
|
||||
}
|
||||
|
||||
MuseumsContainer contaienr = DecodeMuseums(lines);
|
||||
AppendContainer(mainContainer, contaienr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return mainContainer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read and decode lists of museums from multiple files and put into a single register.
|
||||
/// </summary>
|
||||
/// <param name="filenames">Target files</param>
|
||||
/// <returns>Register containing museums from all files</returns>
|
||||
public static MuseumsContainer ReadMuseums(params string[] filenames)
|
||||
{
|
||||
MuseumsContainer mainContainer = new MuseumsContainer();
|
||||
foreach (string filename in filenames)
|
||||
{
|
||||
if (filename.EndsWith(".csv"))
|
||||
{
|
||||
AppendContainer(mainContainer, ReadMuseumsFromCSV(filename));
|
||||
}
|
||||
else if(filename.EndsWith(".zip"))
|
||||
{
|
||||
AppendContainer(mainContainer, ReadMuseumsFromZIP(filename));
|
||||
}
|
||||
}
|
||||
return mainContainer;
|
||||
}
|
||||
|
||||
private static string CreateMuseumLine(Museum museum)
|
||||
{
|
||||
string workDays = "";
|
||||
workDays += museum.Workdays.Contains(Weekday.Monday) ? "1" : "0";
|
||||
workDays += museum.Workdays.Contains(Weekday.Tuesday) ? ";1" : ";0";
|
||||
workDays += museum.Workdays.Contains(Weekday.Wednesday) ? ";1" : ";0";
|
||||
workDays += museum.Workdays.Contains(Weekday.Thursday) ? ";1" : ";0";
|
||||
workDays += museum.Workdays.Contains(Weekday.Friday) ? ";1" : ";0";
|
||||
workDays += museum.Workdays.Contains(Weekday.Saturday) ? ";1" : ";0";
|
||||
workDays += museum.Workdays.Contains(Weekday.Sunday) ? ";1" : ";0";
|
||||
|
||||
return String.Join(";", museum.City, museum.Name, workDays, museum.Price);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write and encode a list of museums to a file. The file will be in a csv format using ";" as seperators.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target file</param>
|
||||
/// <param name="container">Container of museums</param>
|
||||
public static void WriteMuseums(string filename, MuseumsContainer container)
|
||||
{
|
||||
string[] lines = new string[container.Count];
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
Museum museum = container.Get(i);
|
||||
lines[i] = CreateMuseumLine(museum);
|
||||
}
|
||||
File.WriteAllLines(filename, lines, Encoding.UTF8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write and encode a list of museums to a file from a register.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target location</param>
|
||||
/// <param name="register">Register containing museums</param>
|
||||
public static void WriteMuseums(string filename, MuseumsRegister register)
|
||||
{
|
||||
int n = register.Count();
|
||||
string[] lines = new string[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
Museum museum = register.GetByIndex(i);
|
||||
lines[i] = CreateMuseumLine(museum);
|
||||
}
|
||||
File.WriteAllLines(filename, lines, Encoding.UTF8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out a container of museums in a table to the console.
|
||||
/// </summary>
|
||||
/// <param name="container">Container of museums</param>
|
||||
public static void PrintMuseums(MuseumsContainer container)
|
||||
{
|
||||
if (container.Count == 0)
|
||||
{
|
||||
Console.WriteLine("Nėra");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine(new string('-', 123));
|
||||
Console.WriteLine("| {0,-20} | {1,-10} | {2,-20} | {3,-10} | {4,18} | {5,13} | {6,-4} |", "Vardas", "Miestas", "Atsakingas", "Tipas", "Darbo dienų kiekis", "Kaina", "Turi gidą?");
|
||||
Console.WriteLine(new string('-', 123));
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
Museum m = container.Get(i);
|
||||
Console.WriteLine("| {0,-20} | {1,-10} | {2,-20} | {3,-10} | {4,18} | {5,13:f2} | {6,-10} |", m.Name, m.City, m.Manager, m.Type, m.Workdays.Count, m.Price, m.HasGuide ? "Taip" : "Ne");
|
||||
}
|
||||
Console.WriteLine(new string('-', 123));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out a list of museums in a table to the console from a register.
|
||||
/// </summary>
|
||||
/// <param name="register">Register containing museums</param>
|
||||
public static void PrintMuseums(MuseumsRegister register)
|
||||
{
|
||||
MuseumsContainer museums = new MuseumsContainer();
|
||||
for (int i = 0; i < register.Count(); i++)
|
||||
{
|
||||
museums.Add(register.GetByIndex(i));
|
||||
}
|
||||
PrintMuseums(museums);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="MuseumsKaunas.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="MuseumsVilnius.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
28
Lab3/Lab3.TouristInformationCenter/Museum.cs
Normal file
28
Lab3/Lab3.TouristInformationCenter/Museum.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab3.TouristInformationCenter
|
||||
{
|
||||
/// <summary>
|
||||
/// Class used for storing data related a single museum.
|
||||
/// </summary>
|
||||
class Museum
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string City { get; set; }
|
||||
public string Manager { get; set; }
|
||||
public string Type { get; set; }
|
||||
public List<Weekday> Workdays { get; set; }
|
||||
public double Price { get; set; }
|
||||
public bool HasGuide { get; set; }
|
||||
public Museum(string name, string city, string manager, string type, List<Weekday> workdays, double price, bool hasGuide)
|
||||
{
|
||||
Name = name;
|
||||
Manager = manager;
|
||||
City = city;
|
||||
Type = type;
|
||||
Workdays = workdays;
|
||||
Price = price;
|
||||
HasGuide = hasGuide;
|
||||
}
|
||||
}
|
||||
}
|
246
Lab3/Lab3.TouristInformationCenter/MuseumsContainer.cs
Normal file
246
Lab3/Lab3.TouristInformationCenter/MuseumsContainer.cs
Normal file
@ -0,0 +1,246 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab3.TouristInformationCenter
|
||||
{
|
||||
class MuseumsContainer
|
||||
{
|
||||
private Museum[] museums;
|
||||
private int Capacity;
|
||||
public int Count { get; private set; }
|
||||
public MuseumsContainer(int capacity = 16)
|
||||
{
|
||||
Capacity = capacity;
|
||||
museums = new Museum[capacity];
|
||||
}
|
||||
|
||||
public MuseumsContainer(MuseumsContainer container) : this(container.Capacity)
|
||||
{
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
Add(container.Get(i));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a museum to the end of the container
|
||||
/// </summary>
|
||||
/// <param name="museum">Target museum</param>
|
||||
public void Add(Museum museum)
|
||||
{
|
||||
if (Count == Capacity)
|
||||
{
|
||||
EnsureCapacity(Capacity * 2);
|
||||
}
|
||||
|
||||
museums[Count] = museum;
|
||||
Count++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a musem by index from container
|
||||
/// </summary>
|
||||
/// <param name="index">Target index</param>
|
||||
/// <returns>Museum at given index</returns>
|
||||
public Museum Get(int index)
|
||||
{
|
||||
return museums[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if given museum exists in container
|
||||
/// </summary>
|
||||
/// <param name="museum">Target museum</param>
|
||||
/// <returns>True if contains</returns>
|
||||
public bool Contains(Museum museum)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (museums[i].Equals(museum))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Put a museum at a specific index
|
||||
/// </summary>
|
||||
/// <param name="index">Target index</param>
|
||||
/// <param name="museum">Target museum</param>
|
||||
public void Put(int index, Museum museum)
|
||||
{
|
||||
museums[index] = museum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "HasGuide"
|
||||
/// </summary>
|
||||
/// <param name="hasGuide">Target value</param>
|
||||
/// <returns>A filtered container of museums</returns>
|
||||
public MuseumsContainer FilterByGuide(bool hasGuide)
|
||||
{
|
||||
MuseumsContainer filtered = new MuseumsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (museum.HasGuide == hasGuide)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Type".
|
||||
/// </summary>
|
||||
/// <param name="type">Target type</param>
|
||||
/// <returns>A filtered container of museums</returns>
|
||||
public MuseumsContainer FilterByType(string type)
|
||||
{
|
||||
MuseumsContainer filtered = new MuseumsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (museum.Type == type)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Price".
|
||||
/// </summary>
|
||||
/// <param name="maxPrice">Maximum allowed price to be included</param>
|
||||
/// <returns>A container with museums that dont't have a larger price then "maxPrice"</returns>
|
||||
public MuseumsContainer FilterByPrice(double maxPrice)
|
||||
{
|
||||
MuseumsContainer filtered = new MuseumsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (museum.Price <= maxPrice)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Type"
|
||||
/// </summary>
|
||||
/// <param name="city">Target city</param>
|
||||
/// <returns>A container of museums</returns>
|
||||
public MuseumsContainer FilterByCity(string city)
|
||||
{
|
||||
MuseumsContainer filtered = new MuseumsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (museum.City == city)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a list of "active" museums from the contaner.
|
||||
/// A museum is considered active if it is working at least some amount a week.
|
||||
/// </summary>
|
||||
/// <param name="threshold">Threshold which determines what is active</param>
|
||||
/// <returns>A container of "active" museums</returns>
|
||||
public MuseumsContainer FilterByActivity(int threshold)
|
||||
{
|
||||
MuseumsContainer filtered = new MuseumsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (museum.Workdays.Count >= threshold)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Name"
|
||||
/// </summary>
|
||||
/// <param name="name">Target name</param>
|
||||
/// <returns>A filtered container</returns>
|
||||
public MuseumsContainer FilterByName(string name)
|
||||
{
|
||||
MuseumsContainer filtered = new MuseumsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (museum.Name == name)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all of the different types of cities.
|
||||
/// </summary>
|
||||
/// <returns>A list of city names</returns>
|
||||
public List<string> GetAllCities()
|
||||
{
|
||||
List<string> cities = new List<string>();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (!cities.Contains(museum.City))
|
||||
{
|
||||
cities.Add(museum.City);
|
||||
}
|
||||
}
|
||||
return cities;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sort container by "City" and "Name" in alphabetical order.
|
||||
/// </summary>
|
||||
public void Sort()
|
||||
{
|
||||
for (int i = 0; i < Count - 1; i++)
|
||||
{
|
||||
for (int j = i + 1; j < Count; j++)
|
||||
{
|
||||
Museum a = museums[i];
|
||||
Museum b = museums[j];
|
||||
int nameCompare = a.Name.CompareTo(b.Name);
|
||||
int cityCompare = a.City.CompareTo(b.City);
|
||||
if (cityCompare > 0 || (cityCompare == 0 && nameCompare > 0))
|
||||
{
|
||||
museums[i] = b;
|
||||
museums[j] = a;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureCapacity(int minimumCapacity)
|
||||
{
|
||||
if (minimumCapacity <= Capacity) return;
|
||||
|
||||
Museum[] museumsClone = new Museum[minimumCapacity];
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
museumsClone[i] = museums[i];
|
||||
}
|
||||
Capacity = minimumCapacity;
|
||||
museums = museumsClone;
|
||||
}
|
||||
}
|
||||
}
|
8
Lab3/Lab3.TouristInformationCenter/MuseumsKaunas.csv
Normal file
8
Lab3/Lab3.TouristInformationCenter/MuseumsKaunas.csv
Normal file
@ -0,0 +1,8 @@
|
||||
Kaunas
|
||||
Jonas Jonaitis
|
||||
KaunoMuziejus1;Dailė;1;0;0;0;1;0;1;3,40;0
|
||||
KaunoMuziejusB;Computer;1;1;0;1;1;1;1;14,39;1
|
||||
KaunoMuziejus3;History;0;1;0;0;1;0;0;3,26;0
|
||||
KaunoMuziejus4;Dailė;0;1;0;1;1;0;1;9,47;1
|
||||
KaunoMuziejus5;Space;1;1;0;0;0;0;1;1,99;1
|
||||
KaunoMuziejusB;Space;1;1;1;1;0;1;1;0,99;1
|
|
170
Lab3/Lab3.TouristInformationCenter/MuseumsRegister.cs
Normal file
170
Lab3/Lab3.TouristInformationCenter/MuseumsRegister.cs
Normal file
@ -0,0 +1,170 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab3.TouristInformationCenter
|
||||
{
|
||||
/// <summary>
|
||||
/// Class used to store multiple museums in one place
|
||||
/// </summary>
|
||||
class MuseumsRegister
|
||||
{
|
||||
private MuseumsContainer AllMuseums;
|
||||
|
||||
public MuseumsRegister()
|
||||
{
|
||||
AllMuseums = new MuseumsContainer();
|
||||
}
|
||||
|
||||
public MuseumsRegister(MuseumsContainer museums)
|
||||
{
|
||||
AllMuseums = new MuseumsContainer(museums);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add one museum to the register.
|
||||
/// </summary>
|
||||
/// <param name="museum">Target museum</param>
|
||||
public void Add(Museum museum)
|
||||
{
|
||||
AllMuseums.Add(museum);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The amount of stored museums in the register.
|
||||
/// </summary>
|
||||
/// <returns>Museum count</returns>
|
||||
public int Count()
|
||||
{
|
||||
return AllMuseums.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Access museum from register by index
|
||||
/// </summary>
|
||||
/// <param name="index">Target index</param>
|
||||
/// <returns>Museum</returns>
|
||||
public Museum GetByIndex(int index)
|
||||
{
|
||||
return AllMuseums.Get(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a list of active museums from the register.
|
||||
/// A museum is considered active if it is working at least some amount a week.
|
||||
/// </summary>
|
||||
/// <param name="threshold">Threshold which determines what is active</param>
|
||||
/// <returns>A list of active museums</returns>
|
||||
public MuseumsContainer FilterByActiveMuseums(int threshold)
|
||||
{
|
||||
return AllMuseums.FilterByActivity(threshold);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find museum that work the most days in a week
|
||||
/// </summary>
|
||||
/// <returns>Most active museum</returns>
|
||||
public Museum FindMostActiveMuseum()
|
||||
{
|
||||
if (AllMuseums.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Museum mostActive = AllMuseums.Get(0);
|
||||
for (int i = 0; i < AllMuseums.Count; i++)
|
||||
{
|
||||
Museum museum = AllMuseums.Get(i);
|
||||
if (museum.Workdays.Count > mostActive.Workdays.Count)
|
||||
{
|
||||
mostActive = museum;
|
||||
}
|
||||
}
|
||||
return mostActive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find all museums that work the most days in a week
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public MuseumsContainer FindMostActiveMuseums()
|
||||
{
|
||||
Museum mostActive = FindMostActiveMuseum();
|
||||
MuseumsContainer activeMuseums = new MuseumsContainer();
|
||||
for (int i = 0; i < AllMuseums.Count; i++)
|
||||
{
|
||||
Museum museum = AllMuseums.Get(i);
|
||||
if (museum.Workdays.Count == mostActive.Workdays.Count)
|
||||
{
|
||||
activeMuseums.Add(museum);
|
||||
}
|
||||
}
|
||||
return activeMuseums;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all of the different types of cities.
|
||||
/// </summary>
|
||||
/// <returns>A list of city names</returns>
|
||||
public List<string> GetAllCities()
|
||||
{
|
||||
return AllMuseums.GetAllCities();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter the museums by city name from register
|
||||
/// </summary>
|
||||
/// <param name="city">Target city</param>
|
||||
/// <returns>A container of museums</returns>
|
||||
public MuseumsContainer FilterByCity(string city)
|
||||
{
|
||||
return AllMuseums.FilterByCity(city);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Type".
|
||||
/// </summary>
|
||||
/// <param name="type">Target type</param>
|
||||
/// <returns>A filtered container of museums</returns>
|
||||
public MuseumsContainer FilterByType(string type)
|
||||
{
|
||||
return AllMuseums.FilterByType(type);
|
||||
}
|
||||
|
||||
private List<string> GetMuseumNames()
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
for (int i = 0; i < AllMuseums.Count; i++)
|
||||
{
|
||||
Museum museum = AllMuseums.Get(i);
|
||||
if (!result.Contains(museum.Name))
|
||||
{
|
||||
result.Add(museum.Name);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find all museums that have matching names
|
||||
/// </summary>
|
||||
/// <returns>A container with museums that have matching names</returns>
|
||||
public MuseumsContainer FindMuseumsWithDuplicateNames()
|
||||
{
|
||||
MuseumsContainer result = new MuseumsContainer();
|
||||
List<string> names = GetMuseumNames();
|
||||
foreach (string name in names)
|
||||
{
|
||||
MuseumsContainer museumsByName = AllMuseums.FilterByName(name);
|
||||
if (museumsByName.Count <= 1) continue;
|
||||
|
||||
for (int i = 0; i < museumsByName.Count; i++)
|
||||
{
|
||||
result.Add(museumsByName.Get(i));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
7
Lab3/Lab3.TouristInformationCenter/MuseumsVilnius.csv
Normal file
7
Lab3/Lab3.TouristInformationCenter/MuseumsVilnius.csv
Normal file
@ -0,0 +1,7 @@
|
||||
Vilnius
|
||||
Petras Petraitis
|
||||
VilnausMuziejus1;Dailė;1;0;0;1;1;0;0;5,49;0
|
||||
VilnausMuziejus2;Computer;1;1;0;1;1;1;1;0,00;1
|
||||
VilnausMuziejusA;Dailė;0;1;1;1;1;0;0;1,23;0
|
||||
VilnausMuziejusA;Food;1;1;1;1;1;1;0;6,90;0
|
||||
VilnausMuziejus5;History;0;1;0;1;1;0;1;10,49;0
|
|
46
Lab3/Lab3.TouristInformationCenter/Program.cs
Normal file
46
Lab3/Lab3.TouristInformationCenter/Program.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab3.TouristInformationCenter
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// Read all museums from initial data files
|
||||
MuseumsContainer container = InOutUtils.ReadMuseums("MuseumsKaunas.csv", "MuseumsVilnius.csv");
|
||||
MuseumsRegister register = new MuseumsRegister(container);
|
||||
Console.WriteLine("Visi muziejai:");
|
||||
InOutUtils.PrintMuseums(register);
|
||||
Console.WriteLine();
|
||||
|
||||
// Write out a list of cities and if they have at least one museum that is free and with a guide
|
||||
List<string> cities = register.GetAllCities();
|
||||
foreach (string city in cities)
|
||||
{
|
||||
MuseumsContainer freeMuseumsWithGuide = register
|
||||
.FilterByCity(city)
|
||||
.FilterByPrice(0)
|
||||
.FilterByGuide(true);
|
||||
bool passesCriteria = freeMuseumsWithGuide.Count > 0;
|
||||
Console.WriteLine("{0}: {1}", city, passesCriteria ? "Taip" : "Ne");
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
// Find all museums that are the most active
|
||||
MuseumsContainer mostActiveMuseums = register.FindMostActiveMuseums();
|
||||
Console.WriteLine("Aktyviausi muziejai:");
|
||||
InOutUtils.PrintMuseums(mostActiveMuseums);
|
||||
Console.WriteLine();
|
||||
|
||||
// Find museums that have duplicate names
|
||||
MuseumsContainer museumsWithDuplicateNames = register.FindMuseumsWithDuplicateNames();
|
||||
InOutUtils.WriteMuseums("Sutampta.csv", museumsWithDuplicateNames);
|
||||
|
||||
// Find all art museums and sort them
|
||||
MuseumsContainer artMuseums = register.FilterByType("Dailė");
|
||||
artMuseums.Sort();
|
||||
InOutUtils.WriteMuseums("Dailė.csv", artMuseums);
|
||||
}
|
||||
}
|
||||
}
|
17
Lab3/Lab3.TouristInformationCenter/Weekday.cs
Normal file
17
Lab3/Lab3.TouristInformationCenter/Weekday.cs
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
namespace Lab3.TouristInformationCenter
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for storing weekdays as numbers rather than strings
|
||||
/// </summary>
|
||||
enum Weekday
|
||||
{
|
||||
Monday = 1,
|
||||
Tuesday = 2,
|
||||
Wednesday = 3,
|
||||
Thursday = 4,
|
||||
Friday = 5,
|
||||
Saturday = 6,
|
||||
Sunday = 7
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
Kaunas
|
||||
Jonas Jonaitis
|
||||
KaunoMuziejus1;Dailė;1;0;0;0;1;0;1;3,40;0
|
||||
KaunoMuziejusB;Computer;1;1;0;1;1;1;1;14,39;1
|
||||
KaunoMuziejus3;History;0;1;0;0;1;0;0;3,26;0
|
||||
KaunoMuziejus4;Dailė;0;1;0;1;1;0;1;9,47;1
|
||||
KaunoMuziejus5;Space;1;1;0;0;0;0;1;1,99;1
|
||||
KaunoMuziejusB;Space;1;1;1;1;0;1;1;0,99;1
|
|
@ -0,0 +1,7 @@
|
||||
Vilnius
|
||||
Petras Petraitis
|
||||
VilnausMuziejus1;Dailė;1;0;0;1;1;0;0;5,49;0
|
||||
VilnausMuziejus2;Computer;1;1;0;1;1;1;1;0,00;1
|
||||
VilnausMuziejusA;Dailė;0;1;1;1;1;0;0;1,23;0
|
||||
VilnausMuziejusA;Food;1;1;1;1;1;1;0;6,90;0
|
||||
VilnausMuziejus5;History;0;1;0;1;1;0;1;10,49;0
|
|
@ -0,0 +1,5 @@
|
||||
Kaunas
|
||||
Jonas Joniausias
|
||||
KaunoMuziejusB;Computer;1;1;0;1;1;1;1;14,39;1
|
||||
KaunoMuziejus3;History;0;1;0;0;1;0;0;3,26;0
|
||||
KaunoMuziejusB;Space;1;1;1;1;0;1;1;0,99;0
|
|
@ -0,0 +1,5 @@
|
||||
Vilnius
|
||||
Petras Petrausias
|
||||
VilnausMuziejus2;Computer;1;1;0;1;1;1;1;0,00;0
|
||||
VilnausMuziejusA;Dailė;0;1;1;1;1;0;0;1,23;0
|
||||
VilnausMuziejusB;Food;1;1;1;1;1;1;0;6,90;0
|
|
224
Lab3/Lab3.TouristInformationCenterExtra/InOutUtils.cs
Normal file
224
Lab3/Lab3.TouristInformationCenterExtra/InOutUtils.cs
Normal file
@ -0,0 +1,224 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace Lab3.TouristInformationCenterExtra
|
||||
{
|
||||
/// <summary>
|
||||
/// Class that stores functions that are related to reading and writing data
|
||||
/// </summary>
|
||||
class InOutUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Append the museums from the second container to the first one
|
||||
/// </summary>
|
||||
/// <param name="container1">First container</param>
|
||||
/// <param name="container2">Second container</param>
|
||||
private static void AppendContainer(MuseumsContainer container1, MuseumsContainer container2)
|
||||
{
|
||||
for (int i = 0; i < container2.Count; i++)
|
||||
{
|
||||
container1.Add(container2.Get(i));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode a single museum from a string
|
||||
/// </summary>
|
||||
/// <param name="city">Target city</param>
|
||||
/// <param name="manager">Target manager</param>
|
||||
/// <param name="encoded">Encoded string</param>
|
||||
/// <returns>A decode museum</returns>
|
||||
public static Museum DecodeMusem(string city, string manager, string encoded)
|
||||
{
|
||||
string[] values = encoded.Split(';');
|
||||
string name = values[0];
|
||||
string type = values[1];
|
||||
List<Weekday> workdays = new List<Weekday>();
|
||||
for (int i = 1; i <= 7; i++)
|
||||
{
|
||||
if (int.Parse(values[i + 1]) == 1)
|
||||
{
|
||||
workdays.Add((Weekday)i);
|
||||
}
|
||||
}
|
||||
double price = double.Parse(values[9]);
|
||||
bool hasGuide = int.Parse(values[10]) == 1;
|
||||
|
||||
return new Museum(name, city, manager, type, workdays, price, hasGuide);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode a list of museums from a given list of lines.
|
||||
/// </summary>
|
||||
/// <param name="lines"></param>
|
||||
/// <returns>Container of museums</returns>
|
||||
public static MuseumsContainer DecodeMuseums(List<string> lines)
|
||||
{
|
||||
MuseumsContainer container = new MuseumsContainer(lines.Count-2);
|
||||
string city = lines[0];
|
||||
string manager = lines[1];
|
||||
for (int i = 2; i < lines.Count; i++)
|
||||
{
|
||||
Museum museum = DecodeMusem(city, manager, lines[i]);
|
||||
container.Add(museum);
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read and decode a list of museums from a file.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target file</param>
|
||||
/// <returns>Container of museums</returns>
|
||||
public static MuseumsContainer ReadMuseumsFromCSV(string filename)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
foreach (string line in File.ReadAllLines(filename, Encoding.UTF8))
|
||||
{
|
||||
lines.Add(line);
|
||||
}
|
||||
return DecodeMuseums(lines);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read all the entries from a zip file and decode the museums inside the csv entries.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target filename</param>
|
||||
/// <returns>Register of museums</returns>
|
||||
public static MuseumsContainer ReadMuseumsFromZIP(string filename)
|
||||
{
|
||||
MuseumsContainer mainContainer = new MuseumsContainer();
|
||||
|
||||
using (ZipArchive zipFile = ZipFile.Open(filename, ZipArchiveMode.Read))
|
||||
{
|
||||
foreach (ZipArchiveEntry entry in zipFile.Entries)
|
||||
{
|
||||
if (!entry.Name.EndsWith(".csv")) continue;
|
||||
List<string> lines = new List<string>();
|
||||
using (StreamReader reader = new StreamReader(entry.Open(), Encoding.UTF8))
|
||||
{
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
lines.Add(reader.ReadLine());
|
||||
}
|
||||
}
|
||||
|
||||
MuseumsContainer contaienr = DecodeMuseums(lines);
|
||||
AppendContainer(mainContainer, contaienr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return mainContainer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read and decode lists of museums from multiple files and put into a single register.
|
||||
/// </summary>
|
||||
/// <param name="filenames">Target files</param>
|
||||
/// <returns>Register containing museums from all files</returns>
|
||||
public static MuseumsContainer ReadMuseums(params string[] filenames)
|
||||
{
|
||||
MuseumsContainer mainContainer = new MuseumsContainer();
|
||||
foreach (string filename in filenames)
|
||||
{
|
||||
if (filename.EndsWith(".csv"))
|
||||
{
|
||||
AppendContainer(mainContainer, ReadMuseumsFromCSV(filename));
|
||||
}
|
||||
else if(filename.EndsWith(".zip"))
|
||||
{
|
||||
AppendContainer(mainContainer, ReadMuseumsFromZIP(filename));
|
||||
}
|
||||
}
|
||||
return mainContainer;
|
||||
}
|
||||
|
||||
private static string CreateMuseumLine(Museum museum)
|
||||
{
|
||||
string workDays = "";
|
||||
workDays += museum.Workdays.Contains(Weekday.Monday) ? "1" : "0";
|
||||
workDays += museum.Workdays.Contains(Weekday.Tuesday) ? ";1" : ";0";
|
||||
workDays += museum.Workdays.Contains(Weekday.Wednesday) ? ";1" : ";0";
|
||||
workDays += museum.Workdays.Contains(Weekday.Thursday) ? ";1" : ";0";
|
||||
workDays += museum.Workdays.Contains(Weekday.Friday) ? ";1" : ";0";
|
||||
workDays += museum.Workdays.Contains(Weekday.Saturday) ? ";1" : ";0";
|
||||
workDays += museum.Workdays.Contains(Weekday.Sunday) ? ";1" : ";0";
|
||||
|
||||
return String.Join(";", museum.City, museum.Name, workDays, museum.Price);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write and encode a list of museums to a file. The file will be in a csv format using ";" as seperators.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target file</param>
|
||||
/// <param name="container">Container of museums</param>
|
||||
public static void WriteMuseums(string filename, MuseumsContainer container)
|
||||
{
|
||||
string[] lines = new string[container.Count];
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
Museum museum = container.Get(i);
|
||||
lines[i] = CreateMuseumLine(museum);
|
||||
}
|
||||
File.WriteAllLines(filename, lines, Encoding.UTF8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write and encode a list of museums to a file from a register.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target location</param>
|
||||
/// <param name="register">Register containing museums</param>
|
||||
public static void WriteMuseums(string filename, MuseumsRegister register)
|
||||
{
|
||||
int n = register.Count();
|
||||
string[] lines = new string[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
Museum museum = register.GetByIndex(i);
|
||||
lines[i] = CreateMuseumLine(museum);
|
||||
}
|
||||
File.WriteAllLines(filename, lines, Encoding.UTF8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out a container of museums in a table to the console.
|
||||
/// </summary>
|
||||
/// <param name="container">Container of museums</param>
|
||||
public static void PrintMuseums(MuseumsContainer container)
|
||||
{
|
||||
if (container.Count == 0)
|
||||
{
|
||||
Console.WriteLine("Nėra");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine(new string('-', 115));
|
||||
Console.WriteLine("| {0,20} | {1,-10} | {2,20} | {3,-10} | {4,-18} | {5,-3} | {6,-4} |", "Vardas", "Miestas", "Atsakingas", "Tipas", "Darbo dienų kiekis", "Kaina", "Turi gidą?");
|
||||
Console.WriteLine(new string('-', 115));
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
Museum m = container.Get(i);
|
||||
Console.WriteLine("| {0,20} | {1,-10} | {2, 20} | {3,-10} | {4,-18} | {5,-5:f2} | {6,-10} |", m.Name, m.City, m.Manager, m.Type, m.Workdays.Count, m.Price, m.HasGuide ? "Taip" : "Ne");
|
||||
}
|
||||
Console.WriteLine(new string('-', 115));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out a list of museums in a table to the console from a register.
|
||||
/// </summary>
|
||||
/// <param name="register">Register containing museums</param>
|
||||
public static void PrintMuseums(MuseumsRegister register)
|
||||
{
|
||||
MuseumsContainer museums = new MuseumsContainer();
|
||||
for (int i = 0; i < register.Count(); i++)
|
||||
{
|
||||
museums.Add(register.GetByIndex(i));
|
||||
}
|
||||
PrintMuseums(museums);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="MuseumsKaunas.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="MuseumsVilnius.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
28
Lab3/Lab3.TouristInformationCenterExtra/Museum.cs
Normal file
28
Lab3/Lab3.TouristInformationCenterExtra/Museum.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab3.TouristInformationCenterExtra
|
||||
{
|
||||
/// <summary>
|
||||
/// Class used for storing data related a single museum.
|
||||
/// </summary>
|
||||
class Museum
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string City { get; set; }
|
||||
public string Manager { get; set; }
|
||||
public string Type { get; set; }
|
||||
public List<Weekday> Workdays { get; set; }
|
||||
public double Price { get; set; }
|
||||
public bool HasGuide { get; set; }
|
||||
public Museum(string name, string city, string manager, string type, List<Weekday> workdays, double price, bool hasGuide)
|
||||
{
|
||||
Name = name;
|
||||
Manager = manager;
|
||||
City = city;
|
||||
Type = type;
|
||||
Workdays = workdays;
|
||||
Price = price;
|
||||
HasGuide = hasGuide;
|
||||
}
|
||||
}
|
||||
}
|
283
Lab3/Lab3.TouristInformationCenterExtra/MuseumsContainer.cs
Normal file
283
Lab3/Lab3.TouristInformationCenterExtra/MuseumsContainer.cs
Normal file
@ -0,0 +1,283 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.IO.MemoryMappedFiles;
|
||||
|
||||
namespace Lab3.TouristInformationCenterExtra
|
||||
{
|
||||
class MuseumsContainer
|
||||
{
|
||||
|
||||
public int Count { get; private set; }
|
||||
private static Random random = new Random();
|
||||
private string Filename;
|
||||
private FileStream fs;
|
||||
|
||||
public MuseumsContainer()
|
||||
{
|
||||
Filename = ".container"+random.Next(1000).ToString();
|
||||
fs = File.Create(Filename);
|
||||
}
|
||||
|
||||
public MuseumsContainer(MuseumsContainer container) : this()
|
||||
{
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
Add(container.Get(i));
|
||||
}
|
||||
}
|
||||
|
||||
~MuseumsContainer()
|
||||
{
|
||||
fs.Close();
|
||||
//File.Delete(Filename);
|
||||
}
|
||||
|
||||
private void SeekToEnd()
|
||||
{
|
||||
fs.Seek(0, SeekOrigin.End);
|
||||
}
|
||||
|
||||
private static Museum DecodeMuseum(string encoded)
|
||||
{
|
||||
string[] values = encoded.Split(';');
|
||||
string name = values[0];
|
||||
string city = values[1];
|
||||
string manager = values[2];
|
||||
string type = values[3];
|
||||
List<Weekday> workdays = new List<Weekday>();
|
||||
for (int i = 1; i <= 7; i++)
|
||||
{
|
||||
if (int.Parse(values[i+3]) == 1)
|
||||
{
|
||||
workdays.Add((Weekday)i);
|
||||
}
|
||||
}
|
||||
double price = double.Parse(values[11]);
|
||||
bool hasGuide = int.Parse(values[12]) == 1;
|
||||
|
||||
return new Museum(name, city, manager, type, workdays, price, hasGuide);
|
||||
}
|
||||
|
||||
private static string EncodeMuseum(Museum museum)
|
||||
{
|
||||
int[] workDays = new int[museum.Workdays.Count];
|
||||
for (int i = 0; i < museum.Workdays.Count; i++)
|
||||
{
|
||||
Weekday day = museum.Workdays[i];
|
||||
workDays[i] = Convert.ToInt32(day);
|
||||
}
|
||||
|
||||
int hasGuide = Convert.ToInt32(museum.HasGuide);
|
||||
string workDaysJoined = String.Join(";", workDays);
|
||||
|
||||
return String.Join(";", museum.Name, museum.City, museum.Manager, museum.Type, workDaysJoined, museum.Price, hasGuide);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a museum to the end of the container
|
||||
/// </summary>
|
||||
/// <param name="museum">Target museum</param>
|
||||
public void Add(Museum museum)
|
||||
{
|
||||
SeekToEnd();
|
||||
string encoded = EncodeMuseum(museum);
|
||||
byte[] bytes = new UTF8Encoding(true).GetBytes(encoded);
|
||||
fs.Write(bytes);
|
||||
Count++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a musem by index from container
|
||||
/// </summary>
|
||||
/// <param name="index">Target index</param>
|
||||
/// <returns>Museum at given index</returns>
|
||||
public Museum Get(int index)
|
||||
{
|
||||
return museums[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if given museum exists in container
|
||||
/// </summary>
|
||||
/// <param name="museum">Target museum</param>
|
||||
/// <returns>True if contains</returns>
|
||||
public bool Contains(Museum museum)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (museums[i].Equals(museum))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Put a museum at a specific index
|
||||
/// </summary>
|
||||
/// <param name="index">Target index</param>
|
||||
/// <param name="museum">Target museum</param>
|
||||
public void Put(int index, Museum museum)
|
||||
{
|
||||
museums[index] = museum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "HasGuide"
|
||||
/// </summary>
|
||||
/// <param name="hasGuide">Target value</param>
|
||||
/// <returns>A filtered container of museums</returns>
|
||||
public MuseumsContainer FilterByGuide(bool hasGuide)
|
||||
{
|
||||
MuseumsContainer filtered = new MuseumsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (museum.HasGuide == hasGuide)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Type".
|
||||
/// </summary>
|
||||
/// <param name="type">Target type</param>
|
||||
/// <returns>A filtered container of museums</returns>
|
||||
public MuseumsContainer FilterByType(string type)
|
||||
{
|
||||
MuseumsContainer filtered = new MuseumsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (museum.Type == type)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Price".
|
||||
/// </summary>
|
||||
/// <param name="maxPrice">Maximum allowed price to be included</param>
|
||||
/// <returns>A container with museums that dont't have a larger price then "maxPrice"</returns>
|
||||
public MuseumsContainer FilterByPrice(double maxPrice)
|
||||
{
|
||||
MuseumsContainer filtered = new MuseumsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (museum.Price <= maxPrice)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Type"
|
||||
/// </summary>
|
||||
/// <param name="city">Target city</param>
|
||||
/// <returns>A container of museums</returns>
|
||||
public MuseumsContainer FilterByCity(string city)
|
||||
{
|
||||
MuseumsContainer filtered = new MuseumsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (museum.City == city)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a list of "active" museums from the contaner.
|
||||
/// A museum is considered active if it is working at least some amount a week.
|
||||
/// </summary>
|
||||
/// <param name="threshold">Threshold which determines what is active</param>
|
||||
/// <returns>A container of "active" museums</returns>
|
||||
public MuseumsContainer FilterByActivity(int threshold)
|
||||
{
|
||||
MuseumsContainer filtered = new MuseumsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (museum.Workdays.Count >= threshold)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Name"
|
||||
/// </summary>
|
||||
/// <param name="name">Target name</param>
|
||||
/// <returns>A filtered container</returns>
|
||||
public MuseumsContainer FilterByName(string name)
|
||||
{
|
||||
MuseumsContainer filtered = new MuseumsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (museum.Name == name)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all of the different types of cities.
|
||||
/// </summary>
|
||||
/// <returns>A list of city names</returns>
|
||||
public List<string> GetAllCities()
|
||||
{
|
||||
List<string> cities = new List<string>();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (!cities.Contains(museum.City))
|
||||
{
|
||||
cities.Add(museum.City);
|
||||
}
|
||||
}
|
||||
return cities;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sort container by "City" and "Name" in alphabetical order.
|
||||
/// </summary>
|
||||
public void Sort()
|
||||
{
|
||||
for (int i = 0; i < Count - 1; i++)
|
||||
{
|
||||
for (int j = i + 1; j < Count; j++)
|
||||
{
|
||||
Museum a = museums[i];
|
||||
Museum b = museums[j];
|
||||
int nameCompare = a.Name.CompareTo(b.Name);
|
||||
int cityCompare = a.City.CompareTo(b.City);
|
||||
if (cityCompare > 0 || (cityCompare == 0 && nameCompare > 0))
|
||||
{
|
||||
museums[i] = b;
|
||||
museums[j] = a;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
Kaunas
|
||||
Jonas Jonaitis
|
||||
KaunoMuziejus1;Dailė;1;0;0;0;1;0;1;3,40;0
|
||||
KaunoMuziejusB;Computer;1;1;0;1;1;1;1;14,39;1
|
||||
KaunoMuziejus3;History;0;1;0;0;1;0;0;3,26;0
|
||||
KaunoMuziejus4;Dailė;0;1;0;1;1;0;1;9,47;1
|
||||
KaunoMuziejus5;Space;1;1;0;0;0;0;1;1,99;1
|
||||
KaunoMuziejusB;Space;1;1;1;1;0;1;1;0,99;1
|
|
166
Lab3/Lab3.TouristInformationCenterExtra/MuseumsRegister.cs
Normal file
166
Lab3/Lab3.TouristInformationCenterExtra/MuseumsRegister.cs
Normal file
@ -0,0 +1,166 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab3.TouristInformationCenterExtra
|
||||
{
|
||||
/// <summary>
|
||||
/// Class used to store multiple museums in one place
|
||||
/// </summary>
|
||||
class MuseumsRegister
|
||||
{
|
||||
private MuseumsContainer AllMuseums;
|
||||
|
||||
public MuseumsRegister()
|
||||
{
|
||||
AllMuseums = new MuseumsContainer();
|
||||
}
|
||||
|
||||
public MuseumsRegister(MuseumsContainer museums)
|
||||
{
|
||||
AllMuseums = new MuseumsContainer(museums);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add one museum to the register.
|
||||
/// </summary>
|
||||
/// <param name="museum">Target museum</param>
|
||||
public void Add(Museum museum)
|
||||
{
|
||||
AllMuseums.Add(museum);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The amount of stored museums in the register.
|
||||
/// </summary>
|
||||
/// <returns>Museum count</returns>
|
||||
public int Count()
|
||||
{
|
||||
return AllMuseums.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Access museum from register by index
|
||||
/// </summary>
|
||||
/// <param name="index">Target index</param>
|
||||
/// <returns>Museum</returns>
|
||||
public Museum GetByIndex(int index)
|
||||
{
|
||||
return AllMuseums.Get(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a list of active museums from the register.
|
||||
/// A museum is considered active if it is working at least some amount a week.
|
||||
/// </summary>
|
||||
/// <param name="threshold">Threshold which determines what is active</param>
|
||||
/// <returns>A list of active museums</returns>
|
||||
public MuseumsContainer FilterByActiveMuseums(int threshold)
|
||||
{
|
||||
return AllMuseums.FilterByActivity(threshold);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find museum that work the most days in a week
|
||||
/// </summary>
|
||||
/// <returns>Most active museum</returns>
|
||||
public Museum FindMostActiveMuseum()
|
||||
{
|
||||
if (AllMuseums.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Museum mostActive = AllMuseums.Get(0);
|
||||
for (int i = 0; i < AllMuseums.Count; i++)
|
||||
{
|
||||
Museum museum = AllMuseums.Get(i);
|
||||
if (museum.Workdays.Count > mostActive.Workdays.Count)
|
||||
{
|
||||
mostActive = museum;
|
||||
}
|
||||
}
|
||||
return mostActive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find all museums that work the most days in a week
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public MuseumsContainer FindMostActiveMuseums()
|
||||
{
|
||||
Museum mostActive = FindMostActiveMuseum();
|
||||
MuseumsContainer activeMuseums = new MuseumsContainer();
|
||||
for (int i = 0; i < AllMuseums.Count; i++)
|
||||
{
|
||||
Museum museum = AllMuseums.Get(i);
|
||||
if (museum.Workdays.Count == mostActive.Workdays.Count)
|
||||
{
|
||||
activeMuseums.Add(museum);
|
||||
}
|
||||
}
|
||||
return activeMuseums;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all of the different types of cities.
|
||||
/// </summary>
|
||||
/// <returns>A list of city names</returns>
|
||||
public List<string> GetAllCities()
|
||||
{
|
||||
return AllMuseums.GetAllCities();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter the museums by city name from register
|
||||
/// </summary>
|
||||
/// <param name="city">Target city</param>
|
||||
/// <returns>A container of museums</returns>
|
||||
public MuseumsContainer FilterByCity(string city)
|
||||
{
|
||||
return AllMuseums.FilterByCity(city);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Type".
|
||||
/// </summary>
|
||||
/// <param name="type">Target type</param>
|
||||
/// <returns>A filtered container of museums</returns>
|
||||
public MuseumsContainer FilterByType(string type)
|
||||
{
|
||||
return AllMuseums.FilterByType(type);
|
||||
}
|
||||
|
||||
private List<string> GetMuseumNames()
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
for (int i = 0; i < AllMuseums.Count; i++)
|
||||
{
|
||||
Museum museum = AllMuseums.Get(i);
|
||||
if (!result.Contains(museum.Name))
|
||||
{
|
||||
result.Add(museum.Name);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public MuseumsContainer FindMuseumsWithDuplicateNames()
|
||||
{
|
||||
MuseumsContainer result = new MuseumsContainer();
|
||||
List<string> names = GetMuseumNames();
|
||||
foreach (string name in names)
|
||||
{
|
||||
MuseumsContainer museumsByName = AllMuseums.FilterByName(name);
|
||||
if (museumsByName.Count <= 1) continue;
|
||||
|
||||
for (int i = 0; i < museumsByName.Count; i++)
|
||||
{
|
||||
result.Add(museumsByName.Get(i));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
Vilnius
|
||||
Petras Petraitis
|
||||
VilnausMuziejus1;Dailė;1;0;0;1;1;0;0;5,49;0
|
||||
VilnausMuziejus2;Computer;1;1;0;1;1;1;1;0,00;1
|
||||
VilnausMuziejusA;Dailė;0;1;1;1;1;0;0;1,23;0
|
||||
VilnausMuziejusA;Food;1;1;1;1;1;1;0;6,90;0
|
||||
VilnausMuziejus5;History;0;1;0;1;1;0;1;10,49;0
|
|
54
Lab3/Lab3.TouristInformationCenterExtra/Program.cs
Normal file
54
Lab3/Lab3.TouristInformationCenterExtra/Program.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab3.TouristInformationCenterExtra
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
List<Weekday> workDays = new List<Weekday> { Weekday.Monday };
|
||||
Museum museum = new Museum("Foo", "Bar", "Baz", "IDK", workDays, 4.20, true);
|
||||
|
||||
MuseumsContainer container = new MuseumsContainer();
|
||||
container.Add(museum);
|
||||
|
||||
/*
|
||||
// Read all museums from initial data files
|
||||
MuseumsContainer container = InOutUtils.ReadMuseums("MuseumsKaunas.csv", "MuseumsVilnius.csv");
|
||||
MuseumsRegister register = new MuseumsRegister(container);
|
||||
Console.WriteLine("Visi muziejai:");
|
||||
InOutUtils.PrintMuseums(register);
|
||||
Console.WriteLine();
|
||||
|
||||
// Write out a list of cities and if they have at least one museum that is free and with a guide
|
||||
List<string> cities = register.GetAllCities();
|
||||
foreach (string city in cities)
|
||||
{
|
||||
MuseumsContainer freeMuseumsWithGuide = register
|
||||
.FilterByCity(city)
|
||||
.FilterByPrice(0)
|
||||
.FilterByGuide(true);
|
||||
bool passesCriteria = freeMuseumsWithGuide.Count > 0;
|
||||
Console.WriteLine("{0}: {1}", city, passesCriteria ? "Taip" : "Ne");
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
// Find all museums that are the most active
|
||||
MuseumsContainer mostActiveMuseums = register.FindMostActiveMuseums();
|
||||
Console.WriteLine("Aktyviausi muziejai:");
|
||||
InOutUtils.PrintMuseums(mostActiveMuseums);
|
||||
Console.WriteLine();
|
||||
|
||||
// Find museums that have duplicate names
|
||||
MuseumsContainer museumsWithDuplicateNames = register.FindMuseumsWithDuplicateNames();
|
||||
InOutUtils.WriteMuseums("Sutampta.csv", museumsWithDuplicateNames);
|
||||
|
||||
// Find all art museums and sort them
|
||||
MuseumsContainer artMuseums = register.FilterByType("Dailė");
|
||||
artMuseums.Sort();
|
||||
InOutUtils.WriteMuseums("Dailė.csv", artMuseums);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
17
Lab3/Lab3.TouristInformationCenterExtra/Weekday.cs
Normal file
17
Lab3/Lab3.TouristInformationCenterExtra/Weekday.cs
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
namespace Lab3.TouristInformationCenterExtra
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for storing weekdays as numbers rather than strings
|
||||
/// </summary>
|
||||
enum Weekday
|
||||
{
|
||||
Monday = 1,
|
||||
Tuesday = 2,
|
||||
Wednesday = 3,
|
||||
Thursday = 4,
|
||||
Friday = 5,
|
||||
Saturday = 6,
|
||||
Sunday = 7
|
||||
}
|
||||
}
|
43
Lab3/Lab3.sln
Normal file
43
Lab3/Lab3.sln
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.1525
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3.Exercises.Register", "Lab3.Exercises.Register\Lab3.Exercises.Register.csproj", "{2379B111-C112-4C7F-B4D9-9149B809E980}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Savarankiskas4", "Savarankiskas4\Savarankiskas4.csproj", "{FA2F782C-658B-4ED2-A93F-B2B334FBCBB8}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3.TouristInformationCenter", "Lab3.TouristInformationCenter\Lab3.TouristInformationCenter.csproj", "{C89E170A-8C75-483F-B992-78C8B6DB08DB}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab3.TouristInformationCenterExtra", "Lab3.TouristInformationCenterExtra\Lab3.TouristInformationCenterExtra.csproj", "{86E4FDD5-ADBC-434A-966F-2FD59428ECBF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2379B111-C112-4C7F-B4D9-9149B809E980}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2379B111-C112-4C7F-B4D9-9149B809E980}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2379B111-C112-4C7F-B4D9-9149B809E980}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2379B111-C112-4C7F-B4D9-9149B809E980}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FA2F782C-658B-4ED2-A93F-B2B334FBCBB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FA2F782C-658B-4ED2-A93F-B2B334FBCBB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FA2F782C-658B-4ED2-A93F-B2B334FBCBB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FA2F782C-658B-4ED2-A93F-B2B334FBCBB8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C89E170A-8C75-483F-B992-78C8B6DB08DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C89E170A-8C75-483F-B992-78C8B6DB08DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C89E170A-8C75-483F-B992-78C8B6DB08DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C89E170A-8C75-483F-B992-78C8B6DB08DB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{86E4FDD5-ADBC-434A-966F-2FD59428ECBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{86E4FDD5-ADBC-434A-966F-2FD59428ECBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{86E4FDD5-ADBC-434A-966F-2FD59428ECBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{86E4FDD5-ADBC-434A-966F-2FD59428ECBF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {27634FF3-4EBA-49EC-9207-F08AD686478C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
6
Lab3/README.md
Normal file
6
Lab3/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Lab3 example project
|
||||
|
||||
This project is from the "Object oriented programming" course in KTU.
|
||||
|
||||
It is not polished in any way, so don't expect anything from this.
|
||||
|
6
Lab3/Savarankiskas4/Chemijos.csv
Normal file
6
Lab3/Savarankiskas4/Chemijos.csv
Normal file
@ -0,0 +1,6 @@
|
||||
Chemijos fakultetas
|
||||
Watson;Brauner;CH-1/2;2;8;10
|
||||
Kelly;Brian;CH-1/2;3;9;7;6
|
||||
Garcia;Blair;CH-1/2;2;6;5
|
||||
Kennedy;Benjamin;CI-1/1;2;7;8
|
||||
Kouma;Peter;CI-1/1;3;5;5;6
|
|
7
Lab3/Savarankiskas4/Elektros.csv
Normal file
7
Lab3/Savarankiskas4/Elektros.csv
Normal file
@ -0,0 +1,7 @@
|
||||
Elektros fakultetas
|
||||
Lee;Amy;EL-1/1;2;10;10
|
||||
Cole;Annie ;EL-1/1;3;10;10;10
|
||||
Lowe;Rose;EL-1/1;4;10;10;10;10
|
||||
Moore;Mary;EL-1/2;3;10;10;10
|
||||
White;Alicia;EL-1/2;2;10;10
|
||||
Bruce;Lucy;EL-1/2;3;10;10;10
|
|
85
Lab3/Savarankiskas4/InOutUtils.cs
Normal file
85
Lab3/Savarankiskas4/InOutUtils.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Savarankiskas4
|
||||
{
|
||||
static class InOutUtils
|
||||
{
|
||||
public static StudentsContainer ReadStudents(string filename)
|
||||
{
|
||||
StudentsContainer container = new StudentsContainer();
|
||||
string[] lines = File.ReadAllLines(filename, Encoding.UTF8);
|
||||
string faculty = lines[0].TrimEnd();
|
||||
for (int i = 1; i < lines.Length; i++)
|
||||
{
|
||||
string[] values = lines[i].Split(';');
|
||||
string surname = values[0];
|
||||
string name = values[1];
|
||||
string group = values[2];
|
||||
int gradeCount = int.Parse(values[3]);
|
||||
List<int> grades = new List<int>();
|
||||
for (int j = 0; j < gradeCount; j++)
|
||||
{
|
||||
int grade = int.Parse(values[4 + j]);
|
||||
grades.Add(grade);
|
||||
}
|
||||
Student student = new Student(surname, name, faculty, group, grades);
|
||||
container.Add(student);
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
private static int FindTotalCount(StudentsContainer[] containers)
|
||||
{
|
||||
int count = 0;
|
||||
foreach (StudentsContainer container in containers)
|
||||
{
|
||||
count += container.Count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private static StudentsContainer MergeContainers(StudentsContainer[] containers)
|
||||
{
|
||||
int count = FindTotalCount(containers);
|
||||
StudentsContainer merged = new StudentsContainer(Math.Max(count, 1));
|
||||
foreach (StudentsContainer container in containers)
|
||||
{
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
merged.Add(container.Get(i));
|
||||
}
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
|
||||
public static StudentsContainer ReadStudents(params string[] filenames)
|
||||
{
|
||||
StudentsContainer[] containers = new StudentsContainer[filenames.Length];
|
||||
for (int i = 0; i < filenames.Length; i++)
|
||||
{
|
||||
string filename = filenames[i];
|
||||
containers[i] = ReadStudents(filename);
|
||||
}
|
||||
|
||||
return MergeContainers(containers);
|
||||
}
|
||||
|
||||
public static void PrintStudents(string label, StudentsContainer container)
|
||||
{
|
||||
Console.WriteLine(new string('-', 99));
|
||||
Console.WriteLine("| {0,-95} |", label);
|
||||
Console.WriteLine(new string('-', 99));
|
||||
Console.WriteLine("| {0,-15} | {1,-15} | {2,-25} | {3,-12} | {4,16} |", "Pavardė", "Vardas", "Fakultetas", "Grupė", "Pažymių vidurkis");
|
||||
Console.WriteLine(new string('-', 99));
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
Student student = container.Get(i);
|
||||
Console.WriteLine("| {0,-15} | {1,-15} | {2,-25} | {3,-12} | {4,16:f2} |", student.Surname, student.Name, student.Faculty, student.Group, student.GradesAverage);
|
||||
}
|
||||
Console.WriteLine(new string('-', 99));
|
||||
}
|
||||
}
|
||||
}
|
7
Lab3/Savarankiskas4/Informatikos.csv
Normal file
7
Lab3/Savarankiskas4/Informatikos.csv
Normal file
@ -0,0 +1,7 @@
|
||||
Informatikos fakultetas
|
||||
Puzonas;Rokas;IF-1/1;2;10;10
|
||||
Mercedes;Sarah;IF-1/1;3;7;8;9
|
||||
Mary;Elizabeth;IF-1/1;2;9;10
|
||||
Ben;Niamh;IF-1/2;3;9;8;7
|
||||
Reyes;Hannah;IF-1/2;4;10;9;10;10
|
||||
William;Beth;IF-1/2;2;10;10
|
|
24
Lab3/Savarankiskas4/Program.cs
Normal file
24
Lab3/Savarankiskas4/Program.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Savarankiskas4
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
StudentsContainer container = InOutUtils.ReadStudents("Chemijos.csv", "Elektros.csv", "Informatikos.csv");
|
||||
InOutUtils.PrintStudents("Studentai", container);
|
||||
Console.WriteLine();
|
||||
|
||||
StudentsRegister register = new StudentsRegister(container);
|
||||
List<Tuple<string, float>> averages = register.FindGradesAverages();
|
||||
Console.WriteLine("Grupių pažymių vidurkiai:");
|
||||
foreach (Tuple<string, float> tuple in averages)
|
||||
{
|
||||
Console.WriteLine("{0}: {1}", tuple.Item1, tuple.Item2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
Lab3/Savarankiskas4/Savarankiskas4.csproj
Normal file
20
Lab3/Savarankiskas4/Savarankiskas4.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Elektros.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Chemijos.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Informatikos.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
52
Lab3/Savarankiskas4/Student.cs
Normal file
52
Lab3/Savarankiskas4/Student.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Savarankiskas4
|
||||
{
|
||||
class Student
|
||||
{
|
||||
public string Surname { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Faculty { get; set; }
|
||||
public string Group { get; set; }
|
||||
public List<int> Grades { get; set; }
|
||||
public float GradesAverage
|
||||
{
|
||||
get
|
||||
{
|
||||
float sum = 0;
|
||||
foreach (int grade in Grades)
|
||||
{
|
||||
sum += grade;
|
||||
}
|
||||
return sum/Grades.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public Student(string surname, string name, string faculty, string group, List<int> grades)
|
||||
{
|
||||
Surname = surname;
|
||||
Name = name;
|
||||
Faculty = faculty;
|
||||
Group = group;
|
||||
Grades = grades;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var student = obj as Student;
|
||||
return student != null &&
|
||||
Surname == student.Surname &&
|
||||
Name == student.Name &&
|
||||
Faculty == student.Faculty &&
|
||||
Group == student.Group;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Surname, Name, Faculty, Group);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
97
Lab3/Savarankiskas4/StudentsContainer.cs
Normal file
97
Lab3/Savarankiskas4/StudentsContainer.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Savarankiskas4
|
||||
{
|
||||
class StudentsContainer
|
||||
{
|
||||
private int Capacity;
|
||||
public int Count { get; private set; } = 0;
|
||||
private Student[] students;
|
||||
public StudentsContainer(int capacity = 16)
|
||||
{
|
||||
Capacity = capacity;
|
||||
students = new Student[capacity];
|
||||
}
|
||||
|
||||
public void Add(Student student)
|
||||
{
|
||||
if (Count == Capacity)
|
||||
{
|
||||
EnsureCapacity(Capacity * 2);
|
||||
}
|
||||
|
||||
students[Count] = student;
|
||||
Count++;
|
||||
}
|
||||
|
||||
public void Put(int index, Student student)
|
||||
{
|
||||
students[index] = student;
|
||||
}
|
||||
|
||||
public Student Get(int index)
|
||||
{
|
||||
return students[index];
|
||||
}
|
||||
|
||||
public bool Contains(Student student)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (students[i].Equals(student))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Insert(int index, Student student)
|
||||
{
|
||||
for (int i = Count + 1; i > index; i--)
|
||||
{
|
||||
students[i] = students[i - 1];
|
||||
}
|
||||
students[index] = student;
|
||||
Count++;
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
for (int i = index; i < Count; i++)
|
||||
{
|
||||
students[i] = students[i + 1];
|
||||
}
|
||||
Count--;
|
||||
}
|
||||
|
||||
public void Remove(Student student)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (students[i].Equals(student))
|
||||
{
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureCapacity(int minimumCapacity)
|
||||
{
|
||||
if (minimumCapacity > Capacity)
|
||||
{
|
||||
Student[] dogsClone = new Student[minimumCapacity];
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
dogsClone[i] = students[i];
|
||||
}
|
||||
Capacity = minimumCapacity;
|
||||
students = dogsClone;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
93
Lab3/Savarankiskas4/StudentsRegister.cs
Normal file
93
Lab3/Savarankiskas4/StudentsRegister.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Savarankiskas4
|
||||
{
|
||||
class StudentsRegister
|
||||
{
|
||||
private StudentsContainer students;
|
||||
public StudentsRegister()
|
||||
{
|
||||
students = new StudentsContainer();
|
||||
}
|
||||
public StudentsRegister(StudentsContainer container)
|
||||
{
|
||||
students = new StudentsContainer();
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
students.Add(container.Get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(Student student)
|
||||
{
|
||||
students.Add(student);
|
||||
}
|
||||
|
||||
public Student Get(int index)
|
||||
{
|
||||
return students.Get(index);
|
||||
}
|
||||
|
||||
public int StudentsCount()
|
||||
{
|
||||
return students.Count;
|
||||
}
|
||||
|
||||
public List<string> FindAllGroups()
|
||||
{
|
||||
List<string> groups = new List<string>();
|
||||
for (int i = 0; i < students.Count; i++)
|
||||
{
|
||||
Student student = students.Get(i);
|
||||
if (!groups.Contains(student.Group))
|
||||
{
|
||||
groups.Add(student.Group);
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
public float FindGradesAverageByGroup(string group)
|
||||
{
|
||||
float sum = 0;
|
||||
int n = 0;
|
||||
for (int i = 0; i < students.Count; i++)
|
||||
{
|
||||
Student student = students.Get(i);
|
||||
if (student.Group == group)
|
||||
{
|
||||
sum += student.GradesAverage;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
return sum / n;
|
||||
}
|
||||
|
||||
public List<Tuple<string, float>> FindGradesAverages()
|
||||
{
|
||||
List<string> groups = FindAllGroups();
|
||||
List<Tuple<string, float>> averages = new List<Tuple<string, float>>();
|
||||
foreach (string group in groups)
|
||||
{
|
||||
float average = FindGradesAverageByGroup(group);
|
||||
averages.Add(new Tuple<string, float>(group, average));
|
||||
}
|
||||
|
||||
averages.Sort(delegate (Tuple<string, float> group1, Tuple<string, float> group2) {
|
||||
int gradesComparison = -group1.Item2.CompareTo(group2.Item2);
|
||||
if (gradesComparison == 0)
|
||||
{
|
||||
return group1.Item1.CompareTo(group2.Item1);
|
||||
} else
|
||||
{
|
||||
return gradesComparison;
|
||||
}
|
||||
});
|
||||
|
||||
return averages;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
5
Lab3/global.json
Normal file
5
Lab3/global.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "3.0.103"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user