Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 16, 2016
0 parents commit cb0ed47
Show file tree
Hide file tree
Showing 1,456 changed files with 37,771 additions and 0 deletions.
1 change: 1 addition & 0 deletions 03 - Classes 101/A Simple Class/Build1.bat
@@ -0,0 +1 @@
csc File_1.cs
1 change: 1 addition & 0 deletions 03 - Classes 101/A Simple Class/Build2.bat
@@ -0,0 +1 @@
csc File_2.cs
13 changes: 13 additions & 0 deletions 03 - Classes 101/A Simple Class/File_1.cs
@@ -0,0 +1,13 @@
// 05 - Classes 101\A Simple Class
// copyright 2000 Eric Gunnerson
class VerySimple
{
int simpleValue = 0;
}
class Test
{
public static void Main()
{
VerySimple vs = new VerySimple();
}
}
26 changes: 26 additions & 0 deletions 03 - Classes 101/A Simple Class/File_2.cs
@@ -0,0 +1,26 @@
// 05 - Classes 101\A Simple Class
// copyright 2000 Eric Gunnerson
using System;
class Point
{
// constructor
public Point(int x, int y)
{
this.x = x;
this.y = y;
}

// member fields
public int x;
public int y;
}

class Test
{
public static void Main()
{
Point myPoint = new Point(10, 15);
Console.WriteLine("myPoint.x {0}", myPoint.x);
Console.WriteLine("myPoint.y {0}", myPoint.y);
}
}
1 change: 1 addition & 0 deletions 03 - Classes 101/Member Functions/Build1.bat
@@ -0,0 +1 @@
csc File_1.cs
29 changes: 29 additions & 0 deletions 03 - Classes 101/Member Functions/File_1.cs
@@ -0,0 +1,29 @@
// 05 - Classes 101\Member Functions
// copyright 2000 Eric Gunnerson
using System;
class Point
{
public Point(int x, int y)
{
this.x = x;
this.y = y;
}

// accessor functions
public int GetX() {return(x);}
public int GetY() {return(y);}

// variables now private
int x;
int y;
}

class Test
{
public static void Main()
{
Point myPoint = new Point(10, 15);
Console.WriteLine("myPoint.X {0}", myPoint.GetX());
Console.WriteLine("myPoint.Y {0}", myPoint.GetY());
}
}
1 change: 1 addition & 0 deletions 03 - Classes 101/Overloading/Build1.bat
@@ -0,0 +1 @@
csc File_1.cs
29 changes: 29 additions & 0 deletions 03 - Classes 101/Overloading/File_1.cs
@@ -0,0 +1,29 @@
// 05 - Classes 101\Overloading
// copyright 2000 Eric Gunnerson
class Point
{
// create a new point from x and y values
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
// create a point from an existing point
public Point(Point p)
{
this.x = p.x;
this.y = p.y;
}

int x;
int y;
}

class Test
{
public static void Main()
{
Point myPoint = new Point(10, 15);
Point mySecondPoint = new Point(myPoint);
}
}
1 change: 1 addition & 0 deletions 03 - Classes 101/Ref and Out Parameters/Build1.bat
@@ -0,0 +1 @@
csc File_1.cs
1 change: 1 addition & 0 deletions 03 - Classes 101/Ref and Out Parameters/Build2.bat
@@ -0,0 +1 @@
csc File_2.cs
1 change: 1 addition & 0 deletions 03 - Classes 101/Ref and Out Parameters/Build3.bat
@@ -0,0 +1 @@
csc File_3.cs
35 changes: 35 additions & 0 deletions 03 - Classes 101/Ref and Out Parameters/File_1.cs
@@ -0,0 +1,35 @@
// 05 - Classes 101\Ref and Out Parameters
// copyright 2000 Eric Gunnerson
// error
using System;
class Point
{
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
// get both values in one function call
public void GetPoint(ref int x, ref int y)
{
x = this.x;
y = this.y;
}

int x;
int y;
}

class Test
{
public static void Main()
{
Point myPoint = new Point(10, 15);
int x;
int y;

// illegal
myPoint.GetPoint(ref x, ref y);
Console.WriteLine("myPoint({0}, {1})", x, y);
}
}
33 changes: 33 additions & 0 deletions 03 - Classes 101/Ref and Out Parameters/File_2.cs
@@ -0,0 +1,33 @@
// 05 - Classes 101\Ref and Out Parameters
// copyright 2000 Eric Gunnerson
using System;
class Point
{
public Point(int x, int y)
{
this.x = x;
this.y = y;
}

public void GetPoint(ref int x, ref int y)
{
x = this.x;
y = this.y;
}

int x;
int y;
}

class Test
{
public static void Main()
{
Point myPoint = new Point(10, 15);
int x = 0;
int y = 0;

myPoint.GetPoint(ref x, ref y);
Console.WriteLine("myPoint({0}, {1})", x, y);
}
}
33 changes: 33 additions & 0 deletions 03 - Classes 101/Ref and Out Parameters/File_3.cs
@@ -0,0 +1,33 @@
// 05 - Classes 101\Ref and Out Parameters
// copyright 2000 Eric Gunnerson
using System;
class Point
{
public Point(int x, int y)
{
this.x = x;
this.y = y;
}

public void GetPoint(out int x, out int y)
{
x = this.x;
y = this.y;
}

int x;
int y;
}

class Test
{
public static void Main()
{
Point myPoint = new Point(10, 15);
int x;
int y;

myPoint.GetPoint(out x, out y);
Console.WriteLine("myPoint({0}, {1})", x, y);
}
}
@@ -0,0 +1 @@
csc File_1.cs
@@ -0,0 +1 @@
csc File_2.cs
49 changes: 49 additions & 0 deletions 04 - Base Classes and Inheritance/Abstract Classes/File_1.cs
@@ -0,0 +1,49 @@
// 06 - Base Classes and Inheritance\Abstract Classes
// copyright 2000 Eric Gunnerson
using System;
class Engineer
{
public Engineer(string name, float billingRate)
{
this.name = name;
this.billingRate = billingRate;
}

virtual public float CalculateCharge(float hours)
{
return(hours * billingRate);
}

virtual public string TypeName()
{
return("Engineer");
}

private string name;
protected float billingRate;
}
class ChemicalEngineer: Engineer
{
public ChemicalEngineer(string name, float billingRate) :
base(name, billingRate)
{
}

// overrides mistakenly omitted
}
class Test
{
public static void Main()
{
Engineer[] earray = new Engineer[2];
earray[0] = new Engineer("George", 15.50F);
earray[1] = new ChemicalEngineer("Dr. Curie", 45.50F);

Console.WriteLine("{0} charge = {1}",
earray[0].TypeName(),
earray[0].CalculateCharge(2F));
Console.WriteLine("{0} charge = {1}",
earray[1].TypeName(),
earray[1].CalculateCharge(0.75F));
}
}
71 changes: 71 additions & 0 deletions 04 - Base Classes and Inheritance/Abstract Classes/File_2.cs
@@ -0,0 +1,71 @@
// 06 - Base Classes and Inheritance\Abstract Classes
// copyright 2000 Eric Gunnerson
using System;
abstract class Engineer
{
public Engineer(string name, float billingRate)
{
this.name = name;
this.billingRate = billingRate;
}

virtual public float CalculateCharge(float hours)
{
return(hours * billingRate);
}

abstract public string TypeName();

private string name;
protected float billingRate;
}

class CivilEngineer: Engineer
{
public CivilEngineer(string name, float billingRate) :
base(name, billingRate)
{
}

override public float CalculateCharge(float hours)
{
if (hours < 1.0F)
hours = 1.0F; // minimum charge.
return(hours * billingRate);
}

// This override is required, or an error is generated.
override public string TypeName()
{
return("Civil Engineer");
}
}

class ChemicalEngineer: Engineer
{
public ChemicalEngineer(string name, float billingRate) :
base(name, billingRate)
{
}

override public string TypeName()
{
return("Chemical Engineer");
}
}
class Test
{
public static void Main()
{
Engineer[] earray = new Engineer[2];
earray[0] = new CivilEngineer("Sir John", 40.0F);
earray[1] = new ChemicalEngineer("Dr. Curie", 45.0F);

Console.WriteLine("{0} charge = {1}",
earray[0].TypeName(),
earray[0].CalculateCharge(2F));
Console.WriteLine("{0} charge = {1}",
earray[1].TypeName(),
earray[1].CalculateCharge(0.75F));
}
}
@@ -0,0 +1 @@
csc File_1.cs
@@ -0,0 +1 @@
csc File_3.cs

0 comments on commit cb0ed47

Please sign in to comment.