Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,37 @@ namespace ooad_csharp_oop
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
public static void Main(string[] args) {
// ឧទាហរណ៍ទី១
double distance, hour, fuel = 0.0;
Console.Write("Enter the Distance: ");
distance = Double.Parse(Console.ReadLine());
Console.Write("Enter the Hours: ");
hour = Double.Parse(Console.ReadLine());
Console.Write("Enter the Fuel: ");
fuel = Double.Parse(Console.ReadLine());

Car objCar = new Car(distance, hour, fuel);
Vehicle objVeh = objCar;
objCar.Average();
objVeh.Average();
objCar.Speed();
objVeh.Speed();
Console.ReadKey();

// ឧទាហរណ៍ទី២
double length, width, radius = 0.0;
Console.Write("Enter the Length: ");
length = Double.Parse(Console.ReadLine());
Console.Write("Enter the Width: ");
width = Double.Parse(Console.ReadLine());
Rectangle objRectangle = new Rectangle(length, width);
objRectangle.Area();
Console.Write("Enter the Radius: ");
radius = Double.Parse(Console.ReadLine());
Circle objCircle = new Circle(radius);
objCircle.Area();
Console.ReadKey();
}
}
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"# ooad-csharp-oop"

**OOP Part2** Virtual Class in C#

<br>

What is a Virtual Method in C#?
In object-oriented programming, a virtual method can be changed by an overriding member in a derived class by a method with the same signature. In order to create virtual method, precede the method's declaration in the base class with the "virtual" modifier.
<br>
43 changes: 43 additions & 0 deletions Shape.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;

namespace ooad_csharp_oop
{
// ឧទាហរណ៍ទី២
public class Shape
{
protected double length = 0.0;
protected double radius = 0.0;
protected double width = 0.0;

public Shape(double length, double width) {
this.length = length;
this.width = width;
}

public Shape(double radius) {
this.radius = radius;
}

public virtual void Area() {
double area = 0.0;
area = Math.PI * Math.Pow(radius, 2);
Console.WriteLine("Area of Shape is :{0:0.00} ", area);
}
}

public class Rectangle : Shape {
public Rectangle(double length, double width)
: base(length, width) {
}
public override void Area() {
double area = 0.0;
area = length * width;
Console.WriteLine("Area of Rectangle is : {0:0.00} ", area);
}
}
public class Circle : Shape {
public Circle(double radius)
: base(radius) {
}
}
}
46 changes: 46 additions & 0 deletions Vehicle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace ooad_csharp_oop
{
// ឧទាហរណ៍ទី១
public class Vehicle
{
protected double distance = 0.0;
protected double hour = 0.0;
protected double fuel = 0.0;

public Vehicle(double distance, double hour, double fuel) {
this.distance = distance;
this.hour = hour;
this.fuel = fuel;
}

public virtual void Average() {
double average = 0.0;
average = distance / fuel;
System.Console.WriteLine("Vehicle Average is {0:0.00}", average);
}

public virtual void Speed() {
double speed = 0.0;
speed = distance / hour;
System.Console.WriteLine("Vehicle Average is {0:0.00}", speed);
}
}

public class Car : Vehicle {
public Car(double distance, double hour, double fuel)
: base(distance, hour, fuel) {
}

public override void Average() {
double average = 0.0;
average = distance / fuel;
System.Console.WriteLine("Vehicle Average is {0:0.00}", average);
}

public override void Speed() {
double speed = 0.0;
speed = distance / hour;
System.Console.WriteLine("Vehicle Average is {0:0.00}", speed);
}
}
}
23 changes: 23 additions & 0 deletions bin/Debug/net5.0/ooad-csharp-oop.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v5.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v5.0": {
"ooad-csharp-oop/1.0.0": {
"runtime": {
"ooad-csharp-oop.dll": {}
}
}
}
},
"libraries": {
"ooad-csharp-oop/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
Binary file added bin/Debug/net5.0/ooad-csharp-oop.dll
Binary file not shown.
Binary file added bin/Debug/net5.0/ooad-csharp-oop.exe
Binary file not shown.
Binary file added bin/Debug/net5.0/ooad-csharp-oop.pdb
Binary file not shown.
8 changes: 8 additions & 0 deletions bin/Debug/net5.0/ooad-csharp-oop.runtimeconfig.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\DELL\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\DELL\\.nuget\\packages"
]
}
}
9 changes: 9 additions & 0 deletions bin/Debug/net5.0/ooad-csharp-oop.runtimeconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "5.0.0"
}
}
}
Binary file added bin/Debug/net5.0/ref/ooad-csharp-oop.dll
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v5.0", FrameworkDisplayName = "")]
Binary file added obj/Debug/net5.0/apphost.exe
Binary file not shown.
22 changes: 22 additions & 0 deletions obj/Debug/net5.0/ooad-csharp-oop.AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("ooad-csharp-oop")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("ooad-csharp-oop")]
[assembly: System.Reflection.AssemblyTitleAttribute("ooad-csharp-oop")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.

1 change: 1 addition & 0 deletions obj/Debug/net5.0/ooad-csharp-oop.AssemblyInfoInputs.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7b6ab281c8c6ab7e1e3827a9a4f484ff73b5835f
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
is_global = true
build_property.TargetFramework = net5.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.PublishSingleFile =
build_property.IncludeAllContentForSelfExtract =
build_property._SupportedPlatformList = Android,iOS,Linux,macOS,Windows
build_property.RootNamespace = ooad_csharp_oop
build_property.ProjectDir = D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\
Binary file added obj/Debug/net5.0/ooad-csharp-oop.assets.cache
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
509c4ee89f47d0d75b991614751ade6eb08e7501
16 changes: 16 additions & 0 deletions obj/Debug/net5.0/ooad-csharp-oop.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\bin\Debug\net5.0\ooad-csharp-oop.exe
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\bin\Debug\net5.0\ooad-csharp-oop.deps.json
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\bin\Debug\net5.0\ooad-csharp-oop.runtimeconfig.json
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\bin\Debug\net5.0\ooad-csharp-oop.runtimeconfig.dev.json
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\bin\Debug\net5.0\ooad-csharp-oop.dll
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\bin\Debug\net5.0\ref\ooad-csharp-oop.dll
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\bin\Debug\net5.0\ooad-csharp-oop.pdb
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\obj\Debug\net5.0\ooad-csharp-oop.csproj.AssemblyReference.cache
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\obj\Debug\net5.0\ooad-csharp-oop.GeneratedMSBuildEditorConfig.editorconfig
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\obj\Debug\net5.0\ooad-csharp-oop.AssemblyInfoInputs.cache
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\obj\Debug\net5.0\ooad-csharp-oop.AssemblyInfo.cs
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\obj\Debug\net5.0\ooad-csharp-oop.csproj.CoreCompileInputs.cache
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\obj\Debug\net5.0\ooad-csharp-oop.dll
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\obj\Debug\net5.0\ref\ooad-csharp-oop.dll
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\obj\Debug\net5.0\ooad-csharp-oop.pdb
D:\RUPP-Year4\OOAD\Object Oriented Programming\ooad-csharp-oop\obj\Debug\net5.0\ooad-csharp-oop.genruntimeconfig.cache
Binary file added obj/Debug/net5.0/ooad-csharp-oop.dll
Binary file not shown.
1 change: 1 addition & 0 deletions obj/Debug/net5.0/ooad-csharp-oop.genruntimeconfig.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
34449263d8659535b6222a9aa6e0c4f246eee350
Binary file added obj/Debug/net5.0/ooad-csharp-oop.pdb
Binary file not shown.
Binary file added obj/Debug/net5.0/ref/ooad-csharp-oop.dll
Binary file not shown.