Module 4 ass 1&2

This commit is contained in:
Philip Johansson 2022-07-25 16:50:29 +02:00
parent ab62aef528
commit 2c48e2ac47
33 changed files with 456 additions and 0 deletions

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32414.318
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Task1", "Task1\Task1.csproj", "{9971B944-1F40-4588-A867-17D2EE4F6E51}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Task2", "Task2\Task2.csproj", "{0C50AA3F-F49E-403A-A3E2-821336B52E9D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9971B944-1F40-4588-A867-17D2EE4F6E51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9971B944-1F40-4588-A867-17D2EE4F6E51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9971B944-1F40-4588-A867-17D2EE4F6E51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9971B944-1F40-4588-A867-17D2EE4F6E51}.Release|Any CPU.Build.0 = Release|Any CPU
{0C50AA3F-F49E-403A-A3E2-821336B52E9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C50AA3F-F49E-403A-A3E2-821336B52E9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C50AA3F-F49E-403A-A3E2-821336B52E9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C50AA3F-F49E-403A-A3E2-821336B52E9D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EDBB0A61-25C0-4EA2-A152-334D77C5F621}
EndGlobalSection
EndGlobal

View File

@ -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>

View File

@ -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("Task1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Task1")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[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("9971b944-1f40-4588-a867-17d2ee4f6e51")]
// 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")]

View File

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Task1
{
internal class Task1
{
static void Main(string[] args)
{
var shape = new Shape(1, 2);
Console.WriteLine(shape.Display());
var circle = new Circle(2, 3, 4);
Console.WriteLine(circle.Display());
var cylinder = new Cylinder(3, 4, 5, 6);
Console.WriteLine(cylinder.Display());
Console.WriteLine("press any key to exit");
Console.ReadKey();
}
}
}
class Shape
{
protected int _x;
protected int _y;
public Shape(int x, int y)
{
_x = x;
_y = y;
}
public int X
{
get { return _x; }
}
public int Y
{
get { return _y; }
}
public virtual string Display()
{
return $"X: {_x}, Y: {_y}";
}
};
class Circle : Shape
{
protected int _r;
public Circle(int x, int y, int r)
: base(x, y)
{
_r = r;
}
public virtual double Area
{
get => Math.PI * Math.Pow(_r, 2);
}
public override string Display()
{
return base.Display() + $", R: {Area}";
}
};
class Cylinder : Circle
{
protected int _h;
public Cylinder(int x, int y, int r, int h) : base(x, y, r)
{
_h = h;
}
public override double Area
{
get => (2 * Math.PI * Math.Pow(_r, 2)) + (2 * Math.PI * _r * _h);
}
public virtual double Volume
{
get => Math.PI * Math.Pow(_r, 2) * _h;
}
public override string Display()
{
return base.Display() + $", V: {Volume}";
}
}

View File

@ -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>{9971B944-1F40-4588-A867-17D2EE4F6E51}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Task1</RootNamespace>
<AssemblyName>Task1</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="Task1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Binary file not shown.

View File

@ -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>

Binary file not shown.

View File

@ -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")]

View File

@ -0,0 +1 @@
c30be9dfcf782c1ea85dc8ac3ce30d3f96bc76c7

View File

@ -0,0 +1,8 @@
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task1\bin\Debug\Task1.exe.config
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task1\bin\Debug\Task1.exe
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task1\bin\Debug\Task1.pdb
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task1\obj\Debug\Task1.csproj.AssemblyReference.cache
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task1\obj\Debug\Task1.csproj.SuggestedBindingRedirects.cache
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task1\obj\Debug\Task1.csproj.CoreCompileInputs.cache
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task1\obj\Debug\Task1.exe
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task1\obj\Debug\Task1.pdb

Binary file not shown.

Binary file not shown.

View File

@ -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>

View File

@ -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("Task2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Task2")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[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("0c50aa3f-f49e-403a-a3e2-821336b52e9d")]
// 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")]

View File

@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Task2
{
internal class Task2
{
static void Main(string[] args)
{
var sten = new SalariedEmployee("Sten", "Hard", "73403fjh91", 23.5);
Console.WriteLine($"Sten has a social security number of {sten.SSN} and a weekly salary of {sten.WeeklySalary} of some random currency");
var bjorn = new HourlyEmployee("Bjorn", "Rik", "fsjdklfd89", 37, 13);
Console.WriteLine($"Bjorns last name is {bjorn.LastName} and he earned {bjorn.Earning()} this week");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
}
abstract class Employee
{
private string _firstName, _lastName, _ssn;
public string FirstName { get => _firstName; }
public string LastName { get => _lastName; }
public string SSN { get => _ssn; }
public Employee(string firstName, string lastName, string ssn)
{
_firstName = firstName;
_lastName = lastName;
_ssn = ssn;
}
public override string ToString()
{
return FirstName + " " + LastName + " " + SSN;
}
public abstract double Earning();
};
class SalariedEmployee : Employee
{
private double _weeklySalary;
public double WeeklySalary { get => _weeklySalary; }
public SalariedEmployee(string firstName, string lastName, string ssn, double weeklySalary)
: base(firstName, lastName, ssn)
{
_weeklySalary = weeklySalary;
}
public override string ToString()
{
return base.ToString() + "\n" + $"Weekly Salary: {WeeklySalary}";
}
public override double Earning()
{
return _weeklySalary;
}
}
class HourlyEmployee : Employee
{
private int _weeklyWorkedHours;
private double _hourlyWage;
public HourlyEmployee(string firstName,
string lastName,
string ssn,
int weeklyWorkedHours,
double hourlyWage)
: base(firstName, lastName, ssn)
{
_weeklyWorkedHours = weeklyWorkedHours;
_hourlyWage = hourlyWage;
}
public int WeeklyWorkedHours { get => _weeklyWorkedHours; }
public double HourlyWage { get => _hourlyWage; }
public override string ToString()
{
return base.ToString() +
"\n" + $"Weekly worked hours: {WeeklyWorkedHours}" +
"\n" + $"Hourly Wage: {HourlyWage}";
}
public override double Earning()
{
return (double)_weeklyWorkedHours * _hourlyWage;
}
}

View File

@ -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>{0C50AA3F-F49E-403A-A3E2-821336B52E9D}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Task2</RootNamespace>
<AssemblyName>Task2</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="Task2.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Binary file not shown.

View File

@ -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>

Binary file not shown.

View File

@ -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")]

View File

@ -0,0 +1 @@
7ce87abeb702b8d44db011cb3c28101c90a5fb6e

View File

@ -0,0 +1,8 @@
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task2\bin\Debug\Task2.exe.config
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task2\bin\Debug\Task2.exe
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task2\bin\Debug\Task2.pdb
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task2\obj\Debug\Task2.csproj.AssemblyReference.cache
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task2\obj\Debug\Task2.csproj.SuggestedBindingRedirects.cache
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task2\obj\Debug\Task2.csproj.CoreCompileInputs.cache
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task2\obj\Debug\Task2.exe
D:\Git\Bashir C-sharp assignments\Module4-Assignments\Task2\obj\Debug\Task2.pdb

Binary file not shown.

Binary file not shown.