( Index )
Month

 

Brief Information about the December 2014 CSIG Meeting

Circles.cs - An Introduction to OOP - Object Oriented Programming    by B. Arnold

LATE BREAKING NEWS:   http://www.techsupportalert.com/ content/ microsoft-visual-studio- now-free-non-commercial-use.htm

(General Csig Info)    Object Oriented Programming (OOP) languages like C# have special characteristics. Two very important ones are "Inheritance" and "Polymorphism". We will concentrate on a program that uses the first of these, Inheritance. A simple example that demonstrates the feature will be presented. While the program is simple, the application of the concept cannot be underestimated. This program creates hundreds of images in only a second. These images can be dealt with as high level objects with all of the details hidden, or they can be dissected by the programmer down to the finest detail. Both options are available. The same concept can apply to an automobile database as to a bunch of circles.


Sample

Sample of OOPs Circle Program

Welcome to the CSIG, a Special Interest Group of the ACGNJ. This is an exciting time for the C Language programming since Microsoft now has 4 different language compilers: C++, C++ Express, C-Sharp, and C-Sharp Express. These are all capable of creating Windows (tm) programs. (Some are FREE!)

This month's program includes the following.

This is a CLI DOT NET program is coded using C-sharp (C#) and is very similar to C++.  It also still uses the same DOT NET libraries.

The program uses a number of DOT NET Library functions including the following:
OOP Windows Forms CLASSES Timers
Painting BRUSH Graphics Ellipse
FillEllipse DrawEllipse C# const int
DoubleBuffered WindowState Array ArrayList

There are a number of ways to refer to Microsoft's latest compilers and code. Here's what Wikipedia says: The Common Language Infrastructure (CLI) is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework. The specification defines an environment that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architectures.

Microsoft .Net Framework 4.5
C++ 9.0, etc.
.Net 4.5, etc.
CLI
Common Language Infrastructure

Sample Code

// FORM1.H ACGNJ CSIG MEETING December 16, 2014 - WRITTEN BY BRUCE ARNOLD using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Collections; namespace Circles { public partial class Form1 : Form { const int FIFTY_CIRCLES = 50; const int DIAMETER = 250; const int TIMER_INTERVAL = 2000; // milliseconds static ArrayList CircleArray = new ArrayList(); public Form1() { InitializeComponent(); this.DoubleBuffered = true; // for better, smoother screen updates. this.WindowState = FormWindowState.Maximized; } ~Form1() { CircleArray.RemoveRange(0, CircleArray.Count); // Clear memory. } // Here is where we create a brand new circle. The default constructor of "Circle" // then calls the constructors of its "base" classes. Remember: "It's turtles all // the way down!" A loop creates 50 circles at a time. private void timer1_Tick(object sender, EventArgs e) { this.timer1.Interval = TIMER_INTERVAL; int windowWidth = this.ClientRectangle.Width; int windowHeight = this.ClientRectangle.Height; Random autoRand = new Random(); int xorg, yorg; CircleArray.RemoveRange(0, CircleArray.Count); // Clear memory. for (int loop = 0; loop < FIFTY_CIRCLES; ++loop) { Circle cc = new Circle(); // Create new circle. cc.Diameter(windowHeight / 4); int bkg = autoRand.Next(9); switch (bkg) { case 0: cc.BkGround(Brushes.SandyBrown); break; // Random case 1: cc.BkGround(Brushes.Red); break; // color case 2: cc.BkGround(Brushes.Orange); break; // pick. case 3: cc.BkGround(Brushes.Yellow); break; case 4: cc.BkGround(Brushes.Green); break; case 5: cc.BkGround(Brushes.Blue); break; case 6: cc.BkGround(Brushes.Violet); break; case 7: cc.BkGround(Brushes.LightGray); break; case 8: cc.BkGround(Brushes.White); break; } xorg = windowWidth - cc.cx + 200; if (xorg < 0) xorg = 0; // Calculate limits. yorg = windowHeight - cc.cy + 200; if (yorg < 0) yorg = 0; xorg = autoRand.Next(xorg) - 100; // Randomize values yorg = autoRand.Next(yorg) - 100; cc.Position(xorg, yorg); CircleArray.Add(cc); } Invalidate(); } private void Form1_Paint(object sender, PaintEventArgs e) { foreach (Circle obj in CircleArray) { obj.Paint(e); } }

SOURCE CODE

Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page