oo-70-245-1

oo-70-245-1 Commit Details


Date:2014-08-24 18:50:54 (10 years 1 month ago)
Author:Natalie Adams
Branch:master
Commit:2e928509043c5ac5aa610ba098a4d5e884def0a9
Message:Initial commit of code

Changes:

File differences

Powerpoint Examples/Powerpoint 1/p2-strings.cs
1
2
3
4
5
6
7
8
9
10
using System;
class P2 {
static void Main()
{
string hi = "World";
Console.WriteLine("Hello {0}", hi);
}
}
Powerpoint Examples/Powerpoint 1/p3-loops.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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);
}
}
Powerpoint Examples/Powerpoint 1/p4-exceptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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!!!");
}
}
}
Powerpoint Examples/Powerpoint 1/p5-new.cs
1
2
3
4
5
6
7
8
9
10
11
12
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;
}
}
Powerpoint Examples/Powerpoint 1/p6-class.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System;
class P5 {
static void Main()
{
Console.WriteLine("Hello, world");
}
}
class cCar {
void go()
{
}
}
Powerpoint Examples/Powerpoint 2/p2-class-inherit-new.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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");
}
}
Powerpoint Examples/Powerpoint 2/p3-class-inherit-override.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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");
}
}
Powerpoint Examples/Powerpoint 2/p4-inherit-sealed.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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");
}
}*/
Powerpoint Examples/Powerpoint 2/p5-properties.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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; }
}
}
Powerpoint Examples/Powerpoint 2/p6-constructors.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;}
}
}
Powerpoint Examples/Powerpoint 2/p8-delegate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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);
}
}
Powerpoint Examples/Powerpoint 2/p9-operator-overload.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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; }
}
}
compile.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
)

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.12897s using 14 queries.