added valasztasok

main
szabomarton 3 months ago
parent 38d9ffda29
commit fa3ca38f46

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{48EB5391-192B-4002-8B5E-7C22D38453FA}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ConsoleApp1</RootNamespace>
<AssemblyName>ConsoleApp1</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.33529.622
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1.csproj", "{48EB5391-192B-4002-8B5E-7C22D38453FA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{48EB5391-192B-4002-8B5E-7C22D38453FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48EB5391-192B-4002-8B5E-7C22D38453FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48EB5391-192B-4002-8B5E-7C22D38453FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48EB5391-192B-4002-8B5E-7C22D38453FA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {14D65D44-8165-4B4D-AE17-2638E5F4A634}
EndGlobalSection
EndGlobal

@ -0,0 +1,183 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApp1
{
public class Kepviselo
{
public int valasztokerulet, szavazatok;
public string nev, part;
public Kepviselo(int szam1, int szam2, string nev, string part)
{
this.valasztokerulet = szam1;
this.szavazatok = szam2;
this.nev = nev;
this.part = part;
}
}
public static class Data
{
public static List<Kepviselo> kepviselok = new List<Kepviselo>();
}
class Program
{
public static void ReadData()
{
FileStream fileStream = new FileStream("..\\szavazatok.txt", FileMode.Open, FileAccess.Read);
StreamReader streamReader = new StreamReader(fileStream);
string line = streamReader.ReadLine();
while (line != null)
{
string[] splitted = line.Split(' ');
string nev = $"{splitted[2]} {splitted[3]}";
Kepviselo kepviselo = new Kepviselo(Convert.ToInt32(splitted[0]), Convert.ToInt32(splitted[1]), nev, splitted[4]);
Data.kepviselok.Add(kepviselo);
line = streamReader.ReadLine();
}
streamReader.Close();
fileStream.Close();
}
public static int KepviseloNum()
{
return Data.kepviselok.Count;
}
public static void Feladat2()
{
Console.WriteLine($"A helyhatósági választáson {KepviseloNum()} képviselőjelölt indult.");
}
public static int SzavazatNum(string kepviselo)
{
foreach (var item in Data.kepviselok)
{
if (item.nev.ToLower() == kepviselo.ToLower())
{
return item.szavazatok;
}
}
return -1;
}
public static void Feladat3()
{
Console.WriteLine("Add meg egy képviselő nevét!");
string name = Console.ReadLine();
int num = SzavazatNum(name);
if (num >= 0)
{
Console.WriteLine($"{name} nevű képviselőre {num}db szavazatot adtak le.");
}
else
{
Console.WriteLine("Ilyen nevű képviselőjelölt nem szerepel a nyilvántartásban!");
}
}
public static int SzavazokNum()
{
int num = 0;
foreach (var item in Data.kepviselok)
{
num += item.szavazatok;
}
return num;
}
public static void Feladat4()
{
const int jogosultak = 12345;
int num = SzavazokNum();
double percentage = RoundedPercentage(num, jogosultak);
Console.WriteLine($"A választáson {num} állampolgár, a jogosultak {percentage}%-a vett részt.");
}
public static double RoundedPercentage(int num, int all)
{
double sol = Convert.ToDouble(num) / Convert.ToDouble(all) * 100;
return Math.Round(sol, 2);
}
public static void Feladat5()
{
int jogosultak = SzavazokNum();
int GYEP = 0;
int HEP = 0;
int TISZ = 0;
int ZEP = 0;
int FUG = 0;
foreach (var item in Data.kepviselok)
{
switch (item.part)
{
case "GYEP":
GYEP += item.szavazatok;
break;
case "HEP":
HEP += item.szavazatok;
break;
case "TISZ":
TISZ += item.szavazatok;
break;
case "ZEP":
ZEP += item.szavazatok;
break;
default:
FUG += item.szavazatok;
break;
}
}
Console.WriteLine($"Gyermek evők pártja: {RoundedPercentage(GYEP, jogosultak)}%");
Console.WriteLine($"Herpeszesek pártja: {RoundedPercentage(HEP, jogosultak)}%");
Console.WriteLine($"Tisztáltalanok pártja: {RoundedPercentage(TISZ, jogosultak)}%");
Console.WriteLine($"Zöldségevők pártja: {RoundedPercentage(ZEP, jogosultak)}%");
Console.WriteLine($"Független jelöltek: {RoundedPercentage(FUG, jogosultak)}%");
}
public static void Feladat6()
{
List<Kepviselo> legjobbak = new List<Kepviselo>();
int szavazatmax = Data.kepviselok[0].szavazatok;
foreach (var item in Data.kepviselok)
{
if (item.szavazatok > szavazatmax)
{
szavazatmax = item.szavazatok;
}
}
foreach (var item in Data.kepviselok)
{
if (item.szavazatok == szavazatmax)
{
legjobbak.Add(item);
}
}
Console.WriteLine($"A legtöbb szavazat: {szavazatmax}db");
foreach (var item in legjobbak)
{
Console.WriteLine($"{item.nev}, {item.part}");
}
}
static void Main(string[] args)
{
ReadData();
Feladat2();
Feladat3();
Feladat4();
Feladat5();
Feladat6();
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ConsoleApp1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConsoleApp1")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("48eb5391-192b-4002-8b5e-7c22d38453fa")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]

@ -0,0 +1,7 @@
C:\Users\szabomarton\Desktop\C#\20240212_valasztas\ConsoleApp1\bin\Debug\ConsoleApp1.exe.config
C:\Users\szabomarton\Desktop\C#\20240212_valasztas\ConsoleApp1\bin\Debug\ConsoleApp1.exe
C:\Users\szabomarton\Desktop\C#\20240212_valasztas\ConsoleApp1\bin\Debug\ConsoleApp1.pdb
C:\Users\szabomarton\Desktop\C#\20240212_valasztas\ConsoleApp1\obj\Debug\ConsoleApp1.csproj.AssemblyReference.cache
C:\Users\szabomarton\Desktop\C#\20240212_valasztas\ConsoleApp1\obj\Debug\ConsoleApp1.csproj.CoreCompileInputs.cache
C:\Users\szabomarton\Desktop\C#\20240212_valasztas\ConsoleApp1\obj\Debug\ConsoleApp1.exe
C:\Users\szabomarton\Desktop\C#\20240212_valasztas\ConsoleApp1\obj\Debug\ConsoleApp1.pdb

Binary file not shown.

@ -0,0 +1,40 @@
5 19 Ablak Antal -
1 120 Alma Dalma GYEP
7 162 Bab Zsuzsanna ZEP
2 59 Barack Barna GYEP
6 73 Birs Helga GYEP
1 154 Bors Botond HEP
5 188 Brokkoli Gyula ZEP
6 29 Ceruza Zsombor -
4 143 Fasirt Ferenc HEP
8 157 Gomba Gitta TISZ
3 13 Halmi Helga -
2 66 Hold Ferenc -
7 34 Hurka Herold HEP
5 288 Joghurt Jakab TISZ
4 77 Kajszi Kolos GYEP
2 187 Kapor Karola ZEP
6 13 Karfiol Ede ZEP
6 187 Kefir Ilona TISZ
7 130 Kupa Huba -
8 98 Languszta Auguszta -
1 34 Lila Lilla -
1 56 Medve Rudolf -
5 67 Meggy Csilla GYEP
3 45 Moly Piroska -
4 221 Monitor Tibor -
8 288 Narancs Edmond GYEP
2 220 Oldalas Olga HEP
3 185 Pacal Kata HEP
1 199 Petrezselyem Petra ZEP
8 77 Pokol Vidor -
8 67 Ragu Ida HEP
3 156 Retek Etelka ZEP
7 129 Sajt Hajnalka TISZ
4 38 Simon Simon -
3 87 Szilva Szilvia GYEP
3 187 Tejes Attila TISZ
2 65 Tejfel Edit TISZ
4 39 Uborka Ubul ZEP
6 288 Vadas Marcell HEP
5 68 Vagdalt Edit HEP
Loading…
Cancel
Save