diff --git a/Powerpoint Examples/Powerpoint 1/p1-hello-world.cs b/Powerpoint Examples/Powerpoint 1/p1-hello-world.cs new file mode 100644 index 0000000..e69de29 diff --git a/Powerpoint Examples/Powerpoint 1/p2-strings.cs b/Powerpoint Examples/Powerpoint 1/p2-strings.cs new file mode 100644 index 0000000..4c0d379 --- /dev/null +++ b/Powerpoint Examples/Powerpoint 1/p2-strings.cs @@ -0,0 +1,10 @@ +using System; + +class P2 { + + static void Main() + { + string hi = "World"; + Console.WriteLine("Hello {0}", hi); + } +} \ No newline at end of file diff --git a/Powerpoint Examples/Powerpoint 1/p3-loops.cs b/Powerpoint Examples/Powerpoint 1/p3-loops.cs new file mode 100644 index 0000000..926b84d --- /dev/null +++ b/Powerpoint Examples/Powerpoint 1/p3-loops.cs @@ -0,0 +1,32 @@ +using System; + +class P3 { + static void Main() + { + int x = 0; + int whilei = 0; + Console.WriteLine("Starting looping"); + Console.WriteLine(); + if (x > 5) + Console.WriteLine("x is greator than 5"); + else + Console.WriteLine("x is less than 5"); + Console.WriteLine(); + for(int i = 0; i < 4; i++) + { + Console.WriteLine("For loop..."); + } + Console.WriteLine(); + while(whilei < 5) + { + Console.WriteLine("While loop..."); + whilei++; + } + whilei = 0; + Console.WriteLine(); + do { + Console.WriteLine("do-while loop..."); + whilei++; + } while (whilei < 5); + } +} \ No newline at end of file diff --git a/Powerpoint Examples/Powerpoint 1/p4-exceptions.cs b/Powerpoint Examples/Powerpoint 1/p4-exceptions.cs new file mode 100644 index 0000000..428cef4 --- /dev/null +++ b/Powerpoint Examples/Powerpoint 1/p4-exceptions.cs @@ -0,0 +1,26 @@ +using System; +using System.Diagnostics; +using System.Text; + +class P4 { + static public void fail() + { + throw(new System.Exception("fail")); + } + static void Main(string[] args) + { + bool debug = false; + if (args.Length == 0) + Console.WriteLine("Possible parameters are -d"); + for(int i = 0; i < args.Length; i++) + { + if (args[i] == "-d") + debug = true; + Console.WriteLine("args at {0} is {1}", i, args[i]); + } + if (debug) + { + Console.WriteLine("DEBUGGED!!!"); + } + } +} \ No newline at end of file diff --git a/Powerpoint Examples/Powerpoint 1/p5-new.cs b/Powerpoint Examples/Powerpoint 1/p5-new.cs new file mode 100644 index 0000000..f6172f5 --- /dev/null +++ b/Powerpoint Examples/Powerpoint 1/p5-new.cs @@ -0,0 +1,13 @@ +using System; + +class P5 { + static void Main() + { + P5 Me = new P5(); + int n = Me.doublenum(2); + } + virtual int doublenum(int num) + { + return num*2; + } +} \ No newline at end of file diff --git a/Powerpoint Examples/Powerpoint 1/p6-class.cs b/Powerpoint Examples/Powerpoint 1/p6-class.cs new file mode 100644 index 0000000..c6ebc84 --- /dev/null +++ b/Powerpoint Examples/Powerpoint 1/p6-class.cs @@ -0,0 +1,15 @@ +using System; + +class P5 { + static void Main() + { + Console.WriteLine("Hello, world"); + } +} + +class cCar { + void go() + { + + } +} \ No newline at end of file diff --git a/Powerpoint Examples/Powerpoint 2/p2-class-inherit-new.cs b/Powerpoint Examples/Powerpoint 2/p2-class-inherit-new.cs new file mode 100644 index 0000000..7934c04 --- /dev/null +++ b/Powerpoint Examples/Powerpoint 2/p2-class-inherit-new.cs @@ -0,0 +1,26 @@ +using System; + +class P2 { + static void Main() + { + cDog ob2 = new cDog(); + cMammal ob1 = (cMammal)ob2; + //Notice that "Grunt" is still outputted EVEN though it is a dog? + ob1.speak(); + ob2.speak(); + } +} + +class cMammal { + public void speak() + { + Console.WriteLine("Grunt"); + } +} + +class cDog : cMammal { + public new void speak() + { + Console.WriteLine("woof woof"); + } +} \ No newline at end of file diff --git a/Powerpoint Examples/Powerpoint 2/p3-class-inherit-override.cs b/Powerpoint Examples/Powerpoint 2/p3-class-inherit-override.cs new file mode 100644 index 0000000..547524b --- /dev/null +++ b/Powerpoint Examples/Powerpoint 2/p3-class-inherit-override.cs @@ -0,0 +1,25 @@ +using System; + +class P2 { + static void Main() + { + cDog ob2 = new cDog(); + cMammal ob1 = (cMammal)ob2; + ob1.speak(); + ob2.speak(); + } +} + +class cMammal { + public virtual void speak() + { + Console.WriteLine("Grunt"); + } +} + +class cDog : cMammal { + public override void speak() + { + Console.WriteLine("woof woof"); + } +} \ No newline at end of file diff --git a/Powerpoint Examples/Powerpoint 2/p4-inherit-sealed.cs b/Powerpoint Examples/Powerpoint 2/p4-inherit-sealed.cs new file mode 100644 index 0000000..800bd9e --- /dev/null +++ b/Powerpoint Examples/Powerpoint 2/p4-inherit-sealed.cs @@ -0,0 +1,36 @@ +using System; + +class P2 { + static void Main() + { + cDog ob2 = new cDog(); + cMammal ob1 = (cMammal)ob2; + ob1.speak(); + ob2.speak(); + } +} + +class cMammal { + public virtual void speak() + { + Console.WriteLine("Grunt"); + } +} + +class cDog : cMammal { + public sealed override void speak() + { + Console.WriteLine("woof woof"); + } +} + +/* + Uncomment this section to see the compile complain that you are + trying to implment a function labeled as "sealed" +*/ +/*class cMutatedDog : cDog { + public override void speak() + { + Console.WriteLine("wriggle wriggle"); + } +}*/ \ No newline at end of file diff --git a/Powerpoint Examples/Powerpoint 2/p5-properties.cs b/Powerpoint Examples/Powerpoint 2/p5-properties.cs new file mode 100644 index 0000000..5a210e1 --- /dev/null +++ b/Powerpoint Examples/Powerpoint 2/p5-properties.cs @@ -0,0 +1,18 @@ +using System; + +class P5 { + static void Main() + { + Point p1 = new Point(); + p1.X = 10; + } +} + +class Point { + Int32 x; + Int32 y; + public Int32 X { + get { return x; } + set { x = value; } + } +} \ No newline at end of file diff --git a/Powerpoint Examples/Powerpoint 2/p6-constructors.cs b/Powerpoint Examples/Powerpoint 2/p6-constructors.cs new file mode 100644 index 0000000..61062eb --- /dev/null +++ b/Powerpoint Examples/Powerpoint 2/p6-constructors.cs @@ -0,0 +1,28 @@ +using System; + +class P6 { + static void Main() + { + Point p = new Point(5,5); + Console.WriteLine("x = {0}", p.X); + } +} + +class Point { + int x, y; + public Point() + { + this.x = 0; + this.y = 0; + } + public Point(int x, int y) + { + this.x = x; + this.y = y; + } + public int X{ + get{return x;} + set{x = value;} + } + +} \ No newline at end of file diff --git a/Powerpoint Examples/Powerpoint 2/p8-delegate.cs b/Powerpoint Examples/Powerpoint 2/p8-delegate.cs new file mode 100644 index 0000000..1b88be5 --- /dev/null +++ b/Powerpoint Examples/Powerpoint 2/p8-delegate.cs @@ -0,0 +1,22 @@ +using System; + +delegate void MyDelegate(String message); + +class App{ + public static void Main(){ + MyDelegate call = new MyDelegate(FirstMethod); + call += new MyDelegate(SecondMethod); + + call("Message A"); + call("Message B"); + call("Message C"); + } + + static void FirstMethod(String str){ + Console.WriteLine("1st method: "+str); + } + + static void SecondMethod(String str){ + Console.WriteLine("2nd method: "+str); + } +} \ No newline at end of file diff --git a/Powerpoint Examples/Powerpoint 2/p9-operator-overload.cs b/Powerpoint Examples/Powerpoint 2/p9-operator-overload.cs new file mode 100644 index 0000000..9424012 --- /dev/null +++ b/Powerpoint Examples/Powerpoint 2/p9-operator-overload.cs @@ -0,0 +1,33 @@ +using System; + +class P9 { + static void Main() + { + bigint n1 = new bigint(5); + bigint n2 = new bigint(2); + bigint n3; + n3 = n1 + n2; + Console.WriteLine("Value of n3 = {0}", n3.val); + } +} + +class bigint { + int num; + public static bigint operator +(bigint c1, bigint c2) + { + return new bigint(c1.val + c2.val); + } + + public bigint() + { + this.num = 0; + } + public bigint(int i) + { + this.num = i; + } + public int val { + get { return this.num; } + set { this.num = val; } + } +} \ No newline at end of file diff --git a/compile.bat b/compile.bat new file mode 100644 index 0000000..ca5860b --- /dev/null +++ b/compile.bat @@ -0,0 +1,36 @@ +@echo off +:: Nathan Adams +:: 8/13/2014 +:: 70-245 Object Oriented Design + +:: This script is designed to invoke the C# compiler assuming that they don't have VS installed +:: Microsoft bundles csc.exe with the .Net Framework itself which lives under: +:: C:\Windows\Microsoft.NET\Framework + +:: Note - .Net 3.0 does not seem to come packages with .Net compilers + +:: This script will go down and attempt to find one - the assumption is that every system has .Net installed. + +if exist C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe ( + echo Compiling with .Net 4.0 + C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe %* + goto :end +) + +if exist C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe ( + echo Compiling with .Net 3.5 + C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe %* + goto :end +) + +if exist C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe ( + echo Compiling with .Net 2.0 + C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe %* + goto :end +) + +:end + +if exist %CD%\%~n1.exe ( + %CD%\%~n1.exe +) \ No newline at end of file