Skip to content
Snippets Groups Projects
Commit 8f7fd818 authored by Vesa Lappalainen's avatar Vesa Lappalainen :bicyclist:
Browse files

luento06

parent 3dacfcf4
No related branches found
No related tags found
No related merge requests found
Showing
with 296 additions and 126 deletions
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/modules.xml
/.idea.apu.iml
/contentModel.xml
/projectSettingsUpdater.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
using System;
/// @author Vesa Lappalainen
/// @version 25.9.2012
/// <summary>
/// Esimerkkejä funktioista ja muuttujista
/// </summary>
public class Funktioita
{
/// <summary>
/// Kutsutaan malliksi funktioita
/// </summary>
/// <param name="args">ei käytössä</param>
public static void Main(string[] args)
{
double ala;
ala = YmpyranAla(2);
Console.WriteLine("Ympyrän ala on {0:0.00}", ala);
ala = KolmionAla(3.0, 7.0);
Console.WriteLine("Kolmion ala on " + ala);
int a = 3, b = 4;
double ka = Keskiarvo(a, b);
Console.WriteLine("Keskiarvo on {0:0.000}", ka);
ka = Keskiarvo(3, 5);
Console.WriteLine("Keskiarvo on {0:0.000}", ka);
Console.WriteLine("Keskiarvo on {0:0.000}", Keskiarvo(9, 7));
Console.WriteLine("Keskiarvo on {0:0.000}", Keskiarvo(a, 6 + 2));
}
/// <summary>
/// Kahden luvun keskiarvo
/// </summary>
/// <param name="a">1. luku</param>
/// <param name="b">2. luku</param>
/// <returns>lukujen keskiarvo</returns>
/// <example>
/// <pre name="test">
/// Funktioita.Keskiarvo(3,4) ~~~ 3.5;
/// Funktioita.Keskiarvo(1,1) ~~~ 1.0;
/// Funktioita.Keskiarvo(0,1) ~~~ 0.5;
/// </pre>
/// </example>
public static double Keskiarvo(int a, int b)
{
int summa = a + b;
double ka = summa / 2.0;
return ka;
}
/// <summary>
/// Lasketaan ympyrän pinta-ala
/// </summary>
/// <param name="r">ympyrän säde</param>
/// <returns>ympyrän pinta-ala</returns>
/// <example>
/// <pre name="test">
/// Funktioita.YmpyranAla(1) ~~~ 3.1415926;
/// Funktioita.YmpyranAla(2) ~~~ 12.5663706;
/// </pre>
/// </example>
public static double YmpyranAla(double r)
{
return Math.PI * r * r;
}
/// <summary>
/// Lasketaan kolmion pinta-ala
/// </summary>
/// <param name="kanta">kolmion kannan pituus</param>
/// <param name="korkeus">kolmion korkeus</param>
/// <returns>kolmion pinta-ala</returns>
/// <example>
/// <pre name="test">
/// Funktioita.KolmionAla(1,1) ~~~ 0.5;
/// Funktioita.KolmionAla(5,3) ~~~ 7.5;
/// </pre>
/// </example>
public static double KolmionAla(double kanta, double korkeus)
{
double ala = kanta * korkeus / 2;
return ala;
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
</Project>

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Funktioita", "Funktioita\Funktioita.csproj", "{09FE59D1-397D-497B-9AE6-C8F24793F77B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{09FE59D1-397D-497B-9AE6-C8F24793F77B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09FE59D1-397D-497B-9AE6-C8F24793F77B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09FE59D1-397D-497B-9AE6-C8F24793F77B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09FE59D1-397D-497B-9AE6-C8F24793F77B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Funktioita", "Funktioita\Funktioita.csproj", "{09FE59D1-397D-497B-9AE6-C8F24793F77B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{09FE59D1-397D-497B-9AE6-C8F24793F77B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09FE59D1-397D-497B-9AE6-C8F24793F77B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09FE59D1-397D-497B-9AE6-C8F24793F77B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09FE59D1-397D-497B-9AE6-C8F24793F77B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Funktioita", "Funktioita\Funktioita.csproj", "{16CDE87C-4D89-443A-8EC4-0708958FFE14}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8795F3DE-3634-4EAC-ADA8-C3711D85DE5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8795F3DE-3634-4EAC-ADA8-C3711D85DE5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8795F3DE-3634-4EAC-ADA8-C3711D85DE5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8795F3DE-3634-4EAC-ADA8-C3711D85DE5E}.Release|Any CPU.Build.0 = Release|Any CPU
{1FF97298-9EFD-4C3A-A236-D81632A55E31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FF97298-9EFD-4C3A-A236-D81632A55E31}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FF97298-9EFD-4C3A-A236-D81632A55E31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FF97298-9EFD-4C3A-A236-D81632A55E31}.Release|Any CPU.Build.0 = Release|Any CPU
{DDD0109C-AA3F-4A41-8319-62FF01D3C9AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDD0109C-AA3F-4A41-8319-62FF01D3C9AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDD0109C-AA3F-4A41-8319-62FF01D3C9AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDD0109C-AA3F-4A41-8319-62FF01D3C9AA}.Release|Any CPU.Build.0 = Release|Any CPU
{C53450B9-0A47-4BA7-93A7-9CD443C0B3E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C53450B9-0A47-4BA7-93A7-9CD443C0B3E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C53450B9-0A47-4BA7-93A7-9CD443C0B3E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C53450B9-0A47-4BA7-93A7-9CD443C0B3E1}.Release|Any CPU.Build.0 = Release|Any CPU
{D673A206-F619-4DE4-8D9E-9BC97D3F3403}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D673A206-F619-4DE4-8D9E-9BC97D3F3403}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D673A206-F619-4DE4-8D9E-9BC97D3F3403}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D673A206-F619-4DE4-8D9E-9BC97D3F3403}.Release|Any CPU.Build.0 = Release|Any CPU
{C7CDCB02-B3E1-4796-A358-ACCF6DD4E70F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7CDCB02-B3E1-4796-A358-ACCF6DD4E70F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7CDCB02-B3E1-4796-A358-ACCF6DD4E70F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7CDCB02-B3E1-4796-A358-ACCF6DD4E70F}.Release|Any CPU.Build.0 = Release|Any CPU
{2A075536-7A2E-4269-B90D-2D3B3FD6ADAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A075536-7A2E-4269-B90D-2D3B3FD6ADAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A075536-7A2E-4269-B90D-2D3B3FD6ADAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A075536-7A2E-4269-B90D-2D3B3FD6ADAC}.Release|Any CPU.Build.0 = Release|Any CPU
{479DDDC3-F358-4AF7-8978-C26ABD4193A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{479DDDC3-F358-4AF7-8978-C26ABD4193A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{479DDDC3-F358-4AF7-8978-C26ABD4193A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{479DDDC3-F358-4AF7-8978-C26ABD4193A9}.Release|Any CPU.Build.0 = Release|Any CPU
{16CDE87C-4D89-443A-8EC4-0708958FFE14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16CDE87C-4D89-443A-8EC4-0708958FFE14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16CDE87C-4D89-443A-8EC4-0708958FFE14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16CDE87C-4D89-443A-8EC4-0708958FFE14}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
......@@ -11,11 +11,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="fc85cdb2-6a04-4042-bd67-bd7da4e7a5a1" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.luento05/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.luento05/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/KaannaTaulukkoAli/KaannaTaulukkoAli.cs" beforeDir="false" afterPath="$PROJECT_DIR$/KaannaTaulukkoAli/KaannaTaulukkoAli.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/luento05.sln" beforeDir="false" afterPath="$PROJECT_DIR$/luento05.sln" afterDir="false" />
</list>
<list default="true" id="fc85cdb2-6a04-4042-bd67-bd7da4e7a5a1" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
......@@ -158,7 +154,7 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1694811079122</updated>
<workItem from="1694811080272" duration="10304000" />
<workItem from="1694811080272" duration="10724000" />
</task>
<servers />
</component>
......
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/projectSettingsUpdater.xml
/.idea.luento06.iml
/contentModel.xml
/modules.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -39,9 +39,9 @@ public class Funktioita
/// <returns>lukujen keskiarvo</returns>
/// <example>
/// <pre name="test">
/// Funktioita.Keskiarvo(3,4) ~~~ 3.5;
/// Funktioita.Keskiarvo(1,1) ~~~ 1.0;
/// Funktioita.Keskiarvo(0,1) ~~~ 0.5;
/// Keskiarvo(3,4) ~~~ 3.5;
/// Keskiarvo(1,1) ~~~ 1.0;
/// Keskiarvo(0,1) ~~~ 0.5;
/// </pre>
/// </example>
public static double Keskiarvo(int a, int b)
......@@ -59,8 +59,8 @@ public class Funktioita
/// <returns>ympyrän pinta-ala</returns>
/// <example>
/// <pre name="test">
/// Funktioita.YmpyranAla(1) ~~~ 3.1415926;
/// Funktioita.YmpyranAla(2) ~~~ 12.5663706;
/// YmpyranAla(1) ~~~ 3.1415926;
/// YmpyranAla(2) ~~~ 12.5663706;
/// </pre>
/// </example>
public static double YmpyranAla(double r)
......@@ -77,8 +77,8 @@ public class Funktioita
/// <returns>kolmion pinta-ala</returns>
/// <example>
/// <pre name="test">
/// Funktioita.KolmionAla(1,1) ~~~ 0.5;
/// Funktioita.KolmionAla(5,3) ~~~ 7.5;
/// KolmionAla(1,1) ~~~ 0.5;
/// KolmionAla(5,3) ~~~ 7.5;
/// </pre>
/// </example>
public static double KolmionAla(double kanta, double korkeus)
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{5AD0ECB1-5777-41DD-8D14-B18775EAEEC4}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Funktioita</RootNamespace>
<AssemblyName>Funktioita</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<TargetFramework>net7.0</TargetFramework>
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</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|x86' ">
<PlatformTarget>x86</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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Funktioita.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E655F821-0F2A-485F-A457-E261E72E7005}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FunktioitaNC</RootNamespace>
<AssemblyName>FunktioitaNC</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</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|x86' ">
<PlatformTarget>x86</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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FunktioitaNC.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
using System;
using System;
// Tässä esimerkki ilman kommentteja. Näin ei saa tehdä, mutta jos
// tästä näkee paremmin rakenteen
public class FunktioitaNC
public class FunktioitaNc
{
public static void Main(string[] args)
{
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ExternalConsole>true</ExternalConsole>
</PropertyGroup>
</Project>
using NUnit.Framework;
using static Funktioita;
[TestFixture]
[DefaultFloatingPointTolerance(0.000001)]
public class TestFunktioita
{
[Test]
public void TestKeskiarvo41()
{
Assert.AreEqual( 3.5, Keskiarvo(3,4) , 0.000001, "in method Keskiarvo, line 42");
Assert.AreEqual( 1.0, Keskiarvo(1,1) , 0.000001, "in method Keskiarvo, line 43");
Assert.AreEqual( 0.5, Keskiarvo(0,1) , 0.000001, "in method Keskiarvo, line 44");
}
[Test]
public void TestYmpyranAla61()
{
Assert.AreEqual( 3.1415926, YmpyranAla(1) , 0.000001, "in method YmpyranAla, line 62");
Assert.AreEqual( 12.5663706, YmpyranAla(2) , 0.000001, "in method YmpyranAla, line 63");
}
[Test]
public void TestKolmionAla79()
{
Assert.AreEqual( 0.5, KolmionAla(1,1) , 0.000001, "in method KolmionAla, line 80");
Assert.AreEqual( 7.5, KolmionAla(5,3) , 0.000001, "in method KolmionAla, line 81");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment