Pages

Wednesday, December 7, 2011

Introduction To Object Oriented Programming










Introduction To Object Oriented Programming

By: razi.smartcomputing123@gmail.com



OOP Concept

The following part is extracted from: http://en.wikipedia.org/wiki/Object-oriented_programming



What is Object Oriented Programming?

Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs.



What is Programming Paradigm?

Programming Paradigm simply means the way programmers look at problem solving approach using computers.

Example type of paradigm

Procedure Oriented Programming, i.e. Programmers writes instructions in block of codes that carry out specific action.

This paradigm has some limitations and OOP concept is now receiving attention.






What does “object” in OOP mean?

Object is a kind of Data Structure that consists of data (properties) and procedures (methods) to work with them.

Object is the natural way we recognize entities in the real world, for e.g, a postman (an object) is a person (known by his name and employee number) that delivers parcels (his associated role)



What are other examples of “Object”?

A Washing Machine

Properties: (Machine Serial Number, Wash_Type, Rinse_Type, Spin_Type)

Methods: (Wash, Rinse, Spin)

Exam Session Manager;

Properties: (Exam Date, Subject, Candidate_Lists, Session_Status)

Methods: (Register_Candidate, Run_Session, Close_Session)



What is the problem of non-OOP program?

Simple, non-OOP programs may be one "long" list of statements (or commands).

More complex programs will often group smaller sections of these statements into functions or subroutines each of which might perform a particular task.

With designs of this sort, it is common for some of the program's data to be 'global', i.e. accessible from any part of the program.

As programs grow in size, allowing any function to modify any piece of data means that bugs can have wide-reaching effects.



How does OOP address the ‘global’ data issue in non-OOP program?

object-oriented approach encourages the programmer to place data where it is not directly accessible by the rest of the program.

Instead, the data is accessed by calling specially written functions, commonly called methods, which are either bundled in with the data.

This protects the consistency of the data.



The following part is extracted from: http://www.jrobbins.org/ics121f03/lesson-uml-structure.html

OOP and UML Modeling



Why make models?

Software systems are very complex and hard to understand

Models are abstractions of systems:

They express certain aspects of the system and ignore others

They are less complex and easier to understand

Models can make certain aspects more clearly visible than in the real system

What can you do with models?

Express your ideas and communicate with other engineers

Reason about the system: detect errors, predict qualities

Generate parts of the real system: code, schemas

Reverse-engineer the real system to make a model



What is UML?

Unified Modeling Language

A modeling language standardized between 1995 and 1997 by Rational, IBM, HP, Microsoft, Oracle, MCI, Unisys, DEC, and others

“Unified” means:

Unified existing approaches to OO design notations: Booch, OMT, Objectory, and Statecharts

Unified notation used in multiple phases of development: Requirements, design, and implementation

Unified industry interest, training, and skills/job market

The UML notation consists of:

Class diagrams

Object diagrams

Use case diagrams

Collaboration diagrams

Sequence diagrams

Statechart diagrams

Activity diagrams

Component and deployment diagrams



UML Class Diagram

Class Diagram shows the structure of a class (template for object), i.e the Class Name, Properties and Methods

WASHING MACHINE

Machine_No

Wash_Type

Rinse_Type

Spin_Type

Wash()

Rinse()

Spin()

EXAM SESSION MANAGER

Exam_Date

Exam_Subject

Candidate_Lists

Session_Status

RegisterCandidate()

RunSession()

CloseSession()



UML Use Case Diagram

Use Case Diagram shows the behavior of an object

Washing

Machine

Wash

Rinse

Spin

Exam Session Manager

Register

Run

Close

Saturday, December 3, 2011

Basic Problem Solving Using Computers 1





By: razi.smartcomputing123@gmail.com



Pre-requisite

You are expected to know the following topics before moving to the next slides. Click the links to learn more about them.

What is Computer Programming? (learn more)

What is ideone.com compiler? (learn more)

How to write the basic program structure? (learn more)



Introduction

This presentation demonstrates the concept of problem-solving using computer machine.

All codes can be tested on ideone.com compiler.



What are the advantages of using computer to solve problem?

Computer processing is fast,

millions instructions executed per second

Computer is a reliable processing agent;

it follows instructions exactly as they are.

Computer is consistent;

no such thing as tiredness,

Computer has efficient memory;

huge data collection can be kept in relatively small physical space.



Types of problem that can be solved through programming

Problem can be solved through programming if it can be expressed either as

Arithmetic form, or

Logic form



To perform computer processing we need…

Algorithm

Steps to perform processing

Data Structures

To hold the values prior to, during and post processing

Control Structures

To control program statement execution

These 3 elements are required for computer processing



Algorithm



Narrative Format (Pseudo-Code)

BEGIN

READ integer1, integer2

LET integer3=integer1 + integer2

PRINT integer3

END




Visual Format (Flow Chart)

BEGIN

READ integer1, integer2

LET integer3=integer1 + integer2

PRINT integer3

END

Data Structure

Describe the structure that contains the data value.

Must be designed correctly to achieve efficiency.

Basic data types:

Numbers; integer or decimal point

Text; a character or strings (group of characters)

Compound data types:

Array






Control Structures

Later, we shall see some variations of control structures to add programming flexibility



Problem 1 : Finding area of dimensions

The following table provides a mathematical formula to calculate area for various shapes. Write a program to implement this.






Shape

Formula

Input Values

Rectangle

length x width

Length=5, width=6

Triangle

½ x length x width

Length=3, width=4

Circle

PI x r2

R=2.4

Solution 1a. Area of rectangle

C++

#include «iostream»

using namespace std;

int main() {

int length, width,rectangle;

length=5;

width=6;

rectangle=length * width;

cout«« "area= "««rectangle;

return 0;

}

VB.net

Imports System

Public Class Test

Public Shared Sub Main()

Dim length,width,rectangle as integer

length=5

width=6

rectangle=length * width

Console.WriteLine("area= " & rectangle)

End Sub

End Class



Line 4 declares integer variables. Line 5,6,7 sets the value of the variables. Line 8 outputs the result.

Solution 1b. Area of triangle

C++

#include «iostream»

using namespace std;

int main() {

double length, width, triangle;

length=5;

width=6;

triangle=0.5 * length * width;

cout«« "area= "««triangle;

return 0;

}

VB.net

Imports System

Public Class Test

Public Shared Sub Main()

Dim length,width,triangle as double

length=5

width=6

triangle=0.5*length * width

Console.WriteLine("area= " & triangle)

End Sub

End Class



Line 4 declares integer variables. Line 5,6,7 sets the value of the variables. Line 8 outputs the result.

Solution 1c. Area of circle

C++

#include «iostream»

using namespace std;

int main() {

double PI, radius;

PI=3.14;

radius=2.4;

circle=PI * radius * radius;

cout«« "area= " ««circle;

return 0;

}

VB.net

Imports System

Public Class Test

Public Shared Sub Main()

Dim PI, radius as double

PI=3.14

radius=2.4

circle=PI * radius * radius

Console.WriteLine("area= " & circle)

End Sub

End Class



Line 4 declares integer variables. Line 5,6,7 sets the value of the variables. Line 8 outputs the result.

Problem 2 : Assigning Grades

Student marks range from 0 to 100

Their marks correspond to the grades based on the table below.

Write a program to assign grades to the input marks value.






Min Value

Max Value

Grade

0

39

F

40

59

C

60

79

B

80

100

A

Solution 2. Grades

C++ (http://ideone.com/mO3Lr)

#include «iostream»

using namespace std;

int main() {

double marks;

char grade;

cin»» marks;

if ((marks»=0) && (marks«=39)) {grade='F';}

if ((marks»=40) && (marks«=59)) {grade='C';}

if ((marks»=60) && (marks«=79)) {grade='B';}

if ((marks»=80) && (marks«=100)) {grade='B';}

cout««grade;

return 0;

}

VB.net (http://ideone.com/RirLS)

Imports System

Public Class Test

Public Shared Sub Main()

Dim marks as double

Dim grade as string

marks=val(console.ReadLine())

if ((marks»=0) and (marks«=39)) then grade="F"

if ((marks»=40) and (marks«=59)) then grade="C"

if ((marks»=60) and (marks«=79)) then grade="B"

if ((marks»=80) and (marks«=100)) then grade="B"

Console.WriteLine(grade)

End Sub

End Class



Line 4,5 declares integer variables. Line 6 gets the input value. Line 7,8,9,10 selectively sets the value of the variables. Line 8 outputs the result.

Problem 3 : Login Module

You are required to write codes for login process.

The input_pin value will be compared against the pin value (hardcoded as 1234)

Login trials is limited to 3 times only.

Use WHILE DO(…) LOOP to implement the solution.






Solution 3. Login Module

C++ (http://ideone.com/0CuYI)

#include «iostream»

using namespace std;

int main() {

int pin, input_pin;

int trial,logged;

trial=0;

logged=0;

pin=1234;

while ((trial«3) && (logged==0)) {

cin»»input_pin;

if (input_pin==pin) {

logged=1;}

else {

logged=0;

}

cout««"Trial:"««trial««",Logged:"««logged««endl;

trial++;

}

return 0;

}

VB.net (http://ideone.com/GsXo4)

Imports System

Public Class Test

Public Shared Sub Main()

Dim pin, input_pin as integer

Dim trial, logged as integer

trial=0

logged=0

pin=1234

While (trial«3) and (logged=0)

input_pin=val(console.ReadLine())

If (input_pin=pin) Then

logged=1

Else

logged=0

End If

Console.WriteLine("Trial:" & trial & ",Logged:" & logged)

trial +=1

End While

End Sub

End Class



Line 4,5 declares integer variables. Line 6,7,8 sets initial value for variables. Line 10 gets the input value. Line 11-15 evaluates the input and sets the logged value. Line 9-10 contains the WHILE () DO ...LOOP

Next topics:

More Control Structures

Friday, December 2, 2011

Writing basic program structure using ideone.com compiler





By: razi.smartcomputing123@gmail.com



Pre-requisite

You are expected to know the following topics before moving to the next slides. Click the links to learn more about them.

What is Computer Programming? (learn more)

What is ideone.com compiler? (learn more)



Introduction

This presentation demonstrates the application of basic control structure using C++ and VB.net language.

All codes can be tested on ideone.com compiler.



3 Basic Control Structures



Source Code Templates

C++

#include «iostream»

using namespace std;

int main() {

return 0;

}

VB.net

Imports System

Public Class Test

Public Shared Sub Main()

End Sub

End Class



The followings are the source code templates that is provided by ideone.com

Use this template as a starting point for you to do the programming exercises.

Sequential Control Structure

C++

#include «iostream»

using namespace std;

int main() {

cout««"Hello World"««endl;

cout««"........... "««endl;

return 0;

}






Sequential Control Structure is the default control structure, i.e computer execute statements one after another in top-down direction unless told otherwise.

The following codes display “Hello World” on the first line and dots on the second line.

Sequential Control Structure

Visual Basic .NET

Imports System

Public Class Test

Public Shared Sub Main()

Console.WriteLine("Hello World" & vbCrLf)

Console.WriteLine("..........." & vbCrLf)

Console.ReadLine() 'Wait for key to be pressed

End Sub

End Sub






Sequential Control Structure is the default control structure, i.e computer execute statements one after another in top-down direction unless told otherwise.

The following codes display “Hello World” on the first line and dots on the second line.

Sequential Control Structure & Variable Declaration

C++

#include «iostream»

using namespace std;

int main() {

int num1;

int num2;

int num3;

num1=1;

num2=2;

num3=num1+num2;

cout««"The output is "««num3««endl;

return 0;

}






Line 4,5,6 declare integer variables. Line 7,8,9 assign values to them. Line 10 outputs the value.

Sequential Control Structure & Variable Declaration

Visual Basic .NET

Imports System

Public Class Test

Public Shared Sub Main()

Dim num1 as integer

Dim num2 as integer

Dim num3 as integer

num1=1

num2=2

num3=num1+num2

Console.WriteLine("The output is " & num3 & vbCrLf)

End Sub

End Class






Line 4,5,6 declare integer variables. Line 7,8,9 assign values to them. Line 10 outputs the value.

Selection Control Structure

C++

#include «iostream»

using namespace std;

int main() {

int iMark;

iMark=50;

if (iMark»=40) {

cout««"Pass!"««endl;}

else {

cout««"Failed!"««endl;}

return 0;

}



Line 5 assigns the value for iMark. Line 6 evaluate whether the value is greater than or equals to 40. If TRUE, PRINT “Pass!”. Otherwise, PRINT “Failed!”

Selection Control Structure

Visual Basic .NET

Imports System

Public Class Test

Public Shared Sub Main()

Dim iMark as integer

iMark=50

if (iMark»=40) then

Console.WriteLine("Pass!" & vbCrLf)

else

Console.WriteLine("Failed!" & vbCrLf)

end if

End Sub

End Class



Line 5 assigns the value for iMark. Line 6 evaluate whether the value is greater than or equals to 40. If TRUE, PRINT “Pass!”. Otherwise, PRINT “Failed!”

Loop Control Structure

C++

#include «iostream»

using namespace std;

int main() {

int iMark;

iMark=30;

while (iMark«40) {

cout««iMark««endl;

iMark++;

}

return 0;

}



Line 5 assigns the value for iMark. Line 6 evaluate whether the value is less than 40. If it is TRUE, run a loop and add 1 to iMark in each loop. Line 8 uses increment operator ++

Loop Control Structure

Visual Basic .NET

Imports System

Public Class Test

Public Shared Sub Main()

Dim iMark as integer

iMark=30

do while (iMark«40)

Console.WriteLine(iMark & vbCrLf)

iMark+=1

loop

End Sub

End Class



Line 5 assigns the value for iMark. Line 6 evaluate whether the value is less than 40. If it is TRUE, run a loop and add 1 to iMark in each loop. Line 8 use increment operator +=

Summary

We have learned:

Console window output via ideone.com

3 basic control structures:

Sequential

Selection [IF … ELSE …]

Loop [WHILE (…) DO …]

Increment operator

Newline character



Next topics:

SWITCH SELECTION

DO (…) WHILE (…) LOOP

FOR LOOP

What is Computer Programming





By: razi.smartcomputing123@gmail.com


What is Computer Programming?

Computer Programming is …

the activities of writing set of instructions that will be executed by a computer machine.

A person who writes computer program is called …

a programmer.



Programming Activities

Programming activities involves:

Analyze user requirement

Design the program

Code the program

Test the program

Operate the program



1.Analyze User Requirement

Finding out:

What is the problem to be solved?

What are the constraints associated with the program?

What is the input/output that the program should get/produce?

Set the program objectives






INPUT

PROCESS

OUTPUT

integer1,

integer2

LET integer3 =sum of integer1 and integer2

integer3

A simple Input-Process-Output box showing the user requirement




2. Design The Program

Narrative Format (Pseudo-Code)

BEGIN

READ integer1, integer2

LET integer3=integer1 + integer2

PRINT integer3

END




Visual Format (Flow Chart)



BEGIN

READ integer1, integer2

LET integer3=integer1 + integer2

PRINT integer3

END

3. Code The Program

#include «iostream»

Using namespace std;

Int main(void){

int integer1,integer2,integer3;

cout««“Enter two integers:”;

cin»»integer1;

cin»»integer2;

integer3=integer1+integer2;

cout««“The sum is:”;

cout««integer3;

system(“PAUSE”);

return 0;

}

Enter two integers:

1

2

The sum is:

3



C++ Source Code Sample




C++ Console Output Sample




4. Test The Program

Test Case is …

a list of input values to be given to the program during runtime together with the expected outcome from the computer.

This helps to …

check whether a program is running according to its specified objectives.



(Test Cases for the program design in the previous slides)




5. Operate The Program

Install to the targeted platform

Training and support

Maintenance



Many types of programming languages

Programming languages…

Language used to construct the program codes

Various types exist…

To support different needs, focus and orientation of programming works

Popular ones are …

C, C++, Java, Visual Basic etc.



Programming Paradigm

The way programmer looks at problem-solving using computers

Procedure-oriented

Program is build from combination of code blocks (procedures)

Object-oriented

Problem-solving involves interaction between entities (objects) that incorporate data and functions.



Commonly Used Paradigm

Procedure-oriented programming

Why?

Simple

Easy to learn and apply

Practical

Available as…

Standalone (C++)

Script (VBA)



Which Language To Start?

It could be …

C++

It provides a starting point before moving to other languages such as Java, PHP etc.

Visual Basic

It provides a starting point for windows-based platform

Or whatever language that you may have found suitable reference and instructor to begin with :-)

Microsoft released a Visual Basic for kids called “Small Basic”

It is so ‘basic’ that a person could easily learn programming



Program Control Structures

Defines how program codes/statements should be executed by computer.

Generally…

Sequential

Execute from top to bottom (default)

Selection

Selectively Execute certain statements

Loop

Repeatedly Execute certain statements



Sequential Control Structure

Statements are executed one after another in a top-down direction.



Selection Control Structure

When the program control reaches a CHOICE point(diamond symbol), it must decide which branch to execute next.

Decision is based on the conditional statement (logic value, i.e TRUE or FALSE) that is placed at CHOICE point.






Loop Control Structure

When a program control reaches a CHOICE point, it must repeatedly execute certain instructions until a loop terminating condition is met.

The terminating condition can be determined either during programming or runtime.



Next?

Let’s start the coding!

Thursday, December 1, 2011

Visit - ideone.com






What is ideone?
Ideone is something more than a pastebin; it's an online compiler and debugging tool which allows
to compile and run code online in more than 40 programming languages.

How to use ideone?
Choose a programming language, enter your source code and input data into text boxes. Then check or uncheck run code(whether to execute your program) and private (whether not to list your code in the recent codes page) checkboxes, click the submit button and watch your snippet being executed.

Having problems?
Check the samples to see how to write a properly working code. To find out more, see the help section or the FAQ page.

Visit - FreeMySQL.net





Welcome

We are the leading provider for absolutely FREE MySQL Database Hosting. With our control panel we give you the extra edge to managing your free databases. We provide an even higher level of support and service to you and the rest of our clients. Also being the absolute first free mysql database provider to have a control panel for our clients to manage their free databases, we give you the option to have multiple databases under one account. You are never limited to how many you can create, with a max of five at one time.



Signup


Registration Form

Fields marked with a (*) are required.
* Username :
* Password :
* Re-type Password :
* Email :
Full Name :
Upon registration, you agree to our TOS.


[ Login ] [ Register ] [ Forgot password? ]

Visit - MySqlForFree.com





Welcome To MySQL For Free!

MySQL is an Open Source Database Server that was recently purchased from Sun Microsystems by Oracle. It is currently one of the most downloaded applications on the web! We at www.MySQLForFree.com are here to help you learn and practice MySQL, and SQL in General, by providing you with a Free MySQL Database up to 25MB.


MySQL For Free is overseen by Joel Hanger - a Certified MySQL Database Administrator with over a decade of experience utilizing and developing among the Unix, Linux, Apache, MySQL and PHP environments.


With this free MySQL database you can learn the basics of database administration, specifically MySQL databases, without a hassle. No strings, no gimmics, just 25MB of Free MySQL Database Space for you to learn, practice, and experiment on. Where you go with the free mysql database is up to you!


Username:
Password:
Verify:
E-Mail:
Privacy Policy


Account Features

  • 25 MB of Database Space
    • Unlimited Databases! - Now Implemented!
  • Subdomain with phpMyAdmin
  • Slow Query Logs Available
  • Error Logs Available
  • Usage Reports
  • Connections:
    • 5 Concurrent Connections
    • 2500 Max Queries Per Hour
    • 2500 Max Updates Per Hour
    • 2500 Max Connections Per Hour
Stats