GTECH 731 Lab Session 4 Lab 3 Review, Lab 4 Intro 9/28/10 Lab 3 Review Lab 4 Overview.

Slides:



Advertisements
Similar presentations
Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
Advertisements

Getting Started with C# 1 SWE 344 Internet Protocols & Client Server Programming.
Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
GTECH 731 Lab Session 5 Lab 4 Review, Lab 5 Intro 10/5/10 Lab 4 Review Lab 5 Overview.
GTECH 731 Lab Session 3 Lab 2 Review, Lab 3 Intro 9/20/10 Lab 2 Review Lab 3 Overview.
Declaring Variables You must first declare a variable before you can use it! Declaring involves: – Establishing the variable’s spot in memory – Specifying.
Overview creating your own functions calling your own functions.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Information Hiding and Encapsulation
C# Programming: From Problem Analysis to Program Design1 2 Your First C# Program.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Copyright © 2012 Pearson Education, Inc. Chapter 2 Introduction to Visual C#
GTECH 731 Lab Session 2 Lab 1 Review, Lab 2 Intro 9/6/10 Lab 1 Review Lab 2 Overview.
11 Chapter 5 METHODS. 22 INTRODUCTION TO METHODS A method is a named block of statements that performs a specific task. Other languages use the terms.
Introduction to Methods
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
C# Tutorial From C++ to C#. Some useful links Msdn C# us/library/kx37x362.aspxhttp://msdn.microsoft.com/en- us/library/kx37x362.aspx.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
1 Web Based Programming Section 6 James King 12 August 2003.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Methods and You. Up to this point, I have covered many different data types with you. Variables can be considered the nouns of an English sentence. If.
BIM313 – Advanced Programming Techniques Object-Oriented Programming 1.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Data Types in Java James Burns. Recitation Name some characteristics of objects Name some characteristics of objects Chemical Bank Chemical Bank Describe.
1 JavaScript in Context. Server-Side Programming.
Functions Why we use functions C library functions Creating our own functions.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
CS590VC – Tutorial 6 Client-side connection through external application.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Functions Overview Functions are sequence of statements with its own local variables supports modularity, reduces code duplication Data transfer between.
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
PseudocodeFORTRAN (original) INPUT number INPUT divisor intermediate = divisor intermediate
Java methods Methods break down large problems into smaller ones Your program may call the same method many times saves writing and maintaining same code.
Objects and Classes Continued Engineering 1D04, Teaching Session 10.
1 JavaScript in Context. Server-Side Programming.
CPSC 481 Fateme Rajabiyazdi #W4. Visual Studio Download Visual Studio 2013 (Ultimate) from – MSDN Academic Alliance Software Center – IT account.
By Mr. Muhammad Pervez Akhtar
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Module 1 Introducing C# and the.NET Framework. Module Overview Introduction to the.NET Framework 4 Creating Projects Within Visual Studio 2010 Writing.
Catie Welsh February 14,  Program 2 Due Tonight by 11:59pm  Program 3 Assigned 2.
1 Working with Controls at Run Time. 2 Objectives You will be able to Add controls to a Windows form at run time. Modify controls at run time.
Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
Exception and Exception Handling. Exception An abnormal event that is likely to happen during program is execution Computer could run out of memory Calling.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
C++ Lesson 1.
Method Mark and Lyubo.
Statements, Comments & Simple Arithmetic
Introduction to Computer Programming
عرض اجمالي المهام الشرطية في سي شارب (الأمر if)
How to organize and document your classes
Methods/Functions.
Presentation transcript:

GTECH 731 Lab Session 4 Lab 3 Review, Lab 4 Intro 9/28/10 Lab 3 Review Lab 4 Overview

Lab 3 – Working with Functions Functions are self-contained blocks of code that perform a single, easily-identified task and return a single value “Curly brackets” define scope of function Avoid temptation to add unrelated tasks to function Can write code in one place and call whenever needed Key elements of any function Name is action verb or statement describing what function does Parameters function acts upon Return type Steps to accomplish task May have local variables required to perform function static string Hello(string name) { return "Hello " + name; } static double SquareRoot(double pNumber) { return Convert.ToDouble(Math.Sqrt(pNumber)); } static double PowerOf(double pBase, double pExponent) { double dProduct = 1; for (int i = 0; i == pExponent; i++) { dProduct = dProduct * pBase; } return dProduct; }

Lab 3 – Functions in Console Program Newly created Console Project automatically generates hierarchy... Namespace Program class Main method The scope of each level is defined by “curly bracket pairs” Misplaced “curly brackets” source of many errors Everything happens within the “curly brackets” of the Program class Main() method is “entry point” for console program Main logic of program Functions are called from within Main() method namespace ConsoleApplication1 { class Program { static int iVariable = 1; static double dVariable = 0; static double FunctionName(int pInput) { double dOutputVariable = pInput + 1; return dOutputVariable; } static void Main(string[] args) { dVariable = FunctionName(iVariable); }

Lab 3 – Functions in Windows Form Program Newly created Windows Form Project automatically generates hierarchy... Namespace Form1 class Form1 method The scope of each level is defined by “curly bracket pairs” Misplaced “curly brackets” source of many errors Everything happens within the “curly brackets” of the Form1 class Form1 is entry point for the program but much of logic is controlled in event handler modules Control of events happens behind the scenes Functions are called from within “Event” handlers for objects in the design window namespace WindowsFormCodeTesting { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private double FunctionName(int Parameter) { double dVariable = Parameter; return dVariable; } private void button1_Click(object sender, EventArgs e) { double dVariable = 0; dVariable = FunctionName(); }

Lab 3 – Layout and Readability Indenting Let Visual Studio set your indents for you Grouping Group like items together Constant or variable declarations Keep lines of function together so function displays on one screen White space Even consistent spacing Separate logical groupings Documentation When trying to understand someone else’s code or code you typed in the past Comment functions & methods Statements that need explanation using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static int AddOne(int pInput) /* This function returns pInput plus one. */ { return pInput + 1; // Add one to pInput } static void Main(string[] args) { /* Variable Declarations */ int iVar1 = 0; // First Variable... int iVar2 = 0; // Second Variable... int iVar3 = 0; // Third Variable... /* Main Body of Program */ iVar1 = AddOne(iVar2); // Explanation... iVar2 = AddOne(iVar3); // Explanation... }

Lab 4 – Object Class Previously treated functions and data as separate entities Mouse position e.X, e.Y coordinates Conversion function used coordinates as parameter input OOP allows data and functions to be merged into contained objects Variables represent current state of object Methods represent abilities of object Less need for long parameter lists Objects represent real-world or conceptual things More intuitive and expressive than procedural approach Object-oriented design involves modeling real-world entities through hierarchy of inheritance Animal: Living Thing Mammal: Warm blooded : Living Thing Feline: Fluffy : Warm blooded : Living Thing MyCat: Rosie: Fluffy : Warm blooded : Living Thing

Lab 4 – Object Class Code Implementation How do you represent the object in code? Define classes within a namespace Animal: Living Thing Mammal: Warm blooded : Living Thing Feline: Fluffy : Warm blooded : Living Thing MyCat: Rosie: Fluffy : Warm blooded : Living Thing namespace MyProjectName { public class Animal { public bool bHeartBeating = true; public void Walk() { // code to implement walk } public class Mammmal : Animal { public bool bWarmBlooded; public void MammalAction() { // code to implement action } public class Feline : Mammmal { public bool bFluffy; public void Feline() { bFluffy = true; } public void Purr() { // code to implement purr } class Program { static void Main(string[] args) { Feline MyCat = new Feline(); MyCat.bFluffy = false; MyCat.Walk(); MyCat.Purr(); MyCat.bWarmBlooded = true; MyCat.bHeartBeating = true; }

Lab 4 – Object Overview of Lab 4 – Windows Form Only