IT150/IT152 Concepts Summary Sheet

Size: px
Start display at page:

Download "IT150/IT152 Concepts Summary Sheet"

Transcription

1 (Examples within this study guide/summary sheet are given in C#.) Variables All data in a computer program, whether calculated during runtime or entered by the user, must be stored somewhere in the memory (RAM) of the computer. To accomplish this, computer programs use variables, which can be defined as a named space in memory. To capture and name a piece of memory for use as storage, a programmer will declare a variable like this: Int32 imyinteger; String smystring; Double dmydouble; Boolean bmyboolean; Any variable declared in a program must also be initialized prior to use by the program. This is to prevent the program from inadvertently using a value that the program itself did not generate or obtain from a user. The initialization step assigns a known value into the variable at the outset of the program. Usually this value is 0 (in the case of numerical variables) or an empty string (in the case of text or string variables). A programmer will initialize a variable like this: imyinteger = 0; smystring = String.Empty; dmydouble = 0.0; bmyboolean = false; The declaration and initialization can occur on the same line like this: Int32 imyinteger = 0; String smystring = String.Empty; Double dmydouble = 0.0; Boolean bmyboolean = false; Other data types include Int64, Float, and Decimal. These are used when needed, depending on the values involved. H. W. Gould, Winter Page 1

2 Input/Output Input is handled differently in a console application from how it is handled in a Windows application. (All input in either type of application is in string format.) In a console application, a programmer will use the ReadLine( ) method of the Console class to get input from the user. Any input gathered from a user with the ReadLine( ) method must be assigned into a string variable like this: smystring = Console.ReadLine( ); When a user enters information into the computer and presses the <enter> key, the Console.ReadLine( ) function takes the input from the keyboard (console) and assigns it into the variable smystring. A single equal sign ( = ) is an assignment, meaning whatever value is produced by the code on the right side of the equal sign is stored into the variable on the left side of the equal sign. (For comparisons between values, the equals is represented by two equals signs ( == ).) If the user needs to enter numerical data (for calculations of some kind), the string value (being held in a string variable) must be converted to a number. The method to do this is the Convert.ToDouble(sMyString) or Convert.ToInt32(sMyString) method (or the appropriate corresponding method for other data types like Int64 or Float). Note that smystring would be replaced by whatever variable name the programmer used for his input string. Input in a Windows application (Windows Forms) would be accomplished by using the.text property of a textbox. When using the value out of a textbox, the programmer must refer to it with the textbox name and the Text property, Ex. txtinputvalue.text. Conversion of text in textboxes to numerical values is accomplished in the same fashion, using the Convert method. Output in a console application involves the use of the Console.Write( ) or Console.WriteLine( ) methods. The difference between the two is simple: Console.Write( ) writes a string value (represented here by ) to the screen and leaves the cursor on the same line as the output, while Console.WriteLine( ) writes a string value to the screen and moves the cursor to the left edge of the screen on the next line. In other words, WriteLine( ) automatically appends a carriage return (new line) to the text; Write( ) does not. The format for these output statements is: Console.Write( This will appear on the screen. ); Console.WriteLine( This will appear on the screen and the cursor will drop to the next line. ); Console.WriteLine(sMyString); (Writes the value stored in smystring to the screen.) To write numerical output to the screen involves invoking the.tostring( ) method that is a part of each of the numerical data types, for example, imyinteger.tostring( ) converts the integer value in imyinteger to a string representation of that value (such as 4 converting to 4 ). Output in a Windows application involves the use of labels and sometimes textboxes. Textboxes are usually reserved for input, though, and you can set the properties of a label to make it look like a textbox, if you desire to do so. The handling of numerical data being output to a label or textbox are the same as for console applications the ToString( ) method. H. W. Gould, Winter Page 2

3 Decision Statements IT150/IT152 Concepts Summary Sheet There are times when a computer program needs to do different things, depending on certain values that have been calculated or entered by the user. The example I gave in classes is a bank ATM responding to a user s request for twenty dollars. Quite simply, if the bank account in question has sufficient funds, one course of action will occur (the money will be dispensed), whereas if there are not sufficient funds, a different course of action will occur (a message telling the user that the request is declined.) The primary decision statements are the if, the if else, and the switch statements. The switch statement has several options (cases) which are distinguished from each other based on discrete values that can be distinctly determined. Here is an example of the syntax of the if else statement (using the ATM example): if(dacctbalance > damountrequested) else damounttodispense = damountrequested; damounttodispense = 0.0; Note: if there is a need to do one thing if a condition exists, but do nothing if the condition doesn t exist, the if statement can be used without the else portion (Assume braining is a Boolean variable and TakeUmbrella( ) is a method or function.): if(braining) TakeUmbrella( ); Switch statements operate on the basis of any number of possible values, each distinct from the others and specifically identified, such as integers. Values of type double are not used in switch statements due to their widely varied possible values. (Continued next page) H. W. Gould, Winter Page 3

4 A switch statement gets its name from electric switches that have several distinct settings, such as the temperature settings on a clothes dryer. The choice of which case to execute is determined by the value in the parameter of the switch statement. An example would be a code block that determines the name of the day of the week, based on the numerical calculation of the day s position in the week (1 st day of the week = Sunday, 2 nd day of the week = Monday, etc.): switch (idaynumber) Case 1: sdayname = Sunday ; Case 2: sdayname = Monday ; Case 3: sdayname = Tuesday ; Case 4: sdayname = Wednesday ; Case 5: sdayname = Thursday ; Case 6: sdayname = Friday ; Case 7: sdayname = Saturday ; default: sdayname = String.Empty; Remember that each Case must have a statement in it. H. W. Gould, Winter Page 4

5 Loops There are times when a block of code must be executed repeatedly, sometimes for a specified number of times and other times, for as long as a specified condition exists. The first kind, with the specified number of repeats, is accomplished with the use of a for loop. Here is the syntax of a for loop: for(int32 i = 0; i < count; i++) // do some junk // next statement after the loop completes. When the program execution reaches this code, the value in count will already be determined (as an integer). 1. The code executes Int32 i = 0; one time when the for loop is reached, creating the temporary variable i as a counter for the loop. This variable will disappear after the for loop is completed. 2. The code then tests the value of i in the second parameter (i < count;) of the for loop. If this statement returns a value of true, the loop will execute. 3. After the code inside the loop executes and the closing curly brace is encountered, the third parameter (i++) will execute, incrementing the value of i by one. 4. After that, the second parameter is tested once again, executing the code in the loop if the test condition returns true again. This continues until the test condition (i < count) returns false, at which time the code execution goes to the first statement after the for loop. An example of how this might be used is a case in which the user needs to add up a list of numbers. The app would inquire of the user how many values need to be summed up. After the user enters a number, the for loop would execute that many times, getting a number from the user and adding it to a running total. After the loop completes its execution, the code after it would do something with the sum, most likely printing it out for the user. The code might then ask if the user wishes to sum up another list of values, to which the user might reply yes. This brings up the other kinds of loop the while and dowhile loops. Either of these loops the while and the do-while will execute as long as the test condition returns a value of true. For example, a loop in a program that continues to increment a value as long as the value remains less than another value. An example of this is when we did our roll the dice application. As long as the user responded in the affirmative (said yes ) to the question Roll again? the loop would continue to repeat. This test condition can be any kind of comparison that returns a Boolean value. It is imperative, however, that code inside the loop affects that test condition such that the test condition at some point will return false. Otherwise, it becomes an infinite loop. In the case of the dice-roll application, it asks the user the Roll again? question inside the loop so that the test condition (suserresponse == Y ) can be affected to return false, such as if the suserresponse gets a value other than Y. H. W. Gould, Winter Page 5

6 A while or do-while loop will continue to repeat until the test condition returns false, giving the user control of how many times the loop executes. As long as the user wants more dice rolls, the dice will continue to roll. What is the difference, you ask, between a while and a do-while? (Why, I thought you d never ask!) A while loop: while(<test condition>) // do some garbage maybe A do-while loop: do // do some garbage at least once while(<test condition>); // note the semicolon here Note that the test condition on the while loop is at the beginning of the loop, but the test condition on the do-while loop is at the end. The primary difference between the two is that the do-while loop will always execute at least one time and then will check the test condition, whereas a while loop will test the condition prior to the first execution of the loop, meaning the code in the loop might never execute, in the case where the test condition is false prior to getting to the loop in code. The best example I can think of would be a program that controls a valve to a tank of fluid, based upon readings from an instrument. The programmer would use a while loop that tests to see if the fluid level in the tank is below a certain level, indicating the need to add more fluid. If the instrument indicates that the fluid in the tank is high enough, then the code to open the valve and fill the tank more will never execute. Only when the fluid level in the tank drops to a low level will the test condition return true, thus allowing the loop to add measured amounts of fluid into the tank. Another difference between the do-while and while loops is in syntax: a while loop has no semicolon after the loop. A do-while loop does have a semicolon. This is so the compiler can distinguish between the two. There are many instances in which either of the two will work, but for those occasions when one or the other is better suited, you ll have to make the determination. H. W. Gould, Winter Page 6

7 Methods, Functions, and Subroutines A method is a block of code that is given a name and that performs a specific purpose that may be needed from various places in the overall application. Executing this block of code is as simple as calling the name of the method from the point in code at which you wish to run the code. In some cases, the method will have a parameter list for which values must be sent (example to follow). These parameters are to hold values that are passed into the method so the method can do its work. There are two kinds of methods (functions and subroutines), although the three terms listed above tend to be used interchangeably, albeit incorrectly. A method that returns a value back to the calling program is called a function. A method that does not return a value, but simply does a chore or task for the calling code (the code that calls for the method to execute), is called a subroutine. Either can take parameters. Here is an example of each: A Function static Int32 AddThem(Int32 ifirstvalue, Int32 isecondvalue) Int32 iresult = ifirstvalue + isecondvalue; Return iresult; Note several things: the return type (in the example, Int32) is the data type of the value you are returning to the main program. The names of the variables in your parameter list (in this case, ifirstvalue and isecondvalue) are irrelevant. They exist only while the function is running. You could just as easily call the variables Abbott and Costello, or Laurel and Hardy. Ideally, though, you d use intuitive names as is the convention for professional software engineers. When the calling code passes information to the function, it passes the value by default. It does not pass the variable, even if the variable in the function has the same name as the variable in the main program. This is important to remember. This is due to the scope of the variables. When you are in the code in the function, everything in the main program is hidden, or in cyber-limbo. The above function example takes two integer values passed into it, which it stores in its two variables ifirstvalue and isecondvalue. It creates a third variable named iresult, which holds the sum of the two that results from the addition in the first statement. The second statement returns the value that is stored in iresult back to the main program, where the call to this function is in an assignment statement. That assignment statement might look like this: isum = AddThem(iAlpha, ibeta); The above statement involves isum, ialpha, and ibeta all being Int32 variables. H. W. Gould, Winter Page 7

8 A Subroutine static void Roll(Int32 ifv, Int32 isv) Console.WriteLine( Your sum is + (ifv+isv).tostring() +. ; This subroutine takes the two values sent to it and use them to complete the addition and output it to the screen, using the WriteLine( ) and an accompanying string literal. Notice that any value or mathematical equation that results in a number has the built-in ToString( ) method with it. So, ifv + isv results in an Int32 value, which means it has the ToString( ) in it. We do the math, then we convert to string, then we include it into a text output for the reader s sake. No value is returned in this case, which is why we use the void return type. This method simply does the task of writing output to the screen. Just as the function Roll in the dice program we did at midterm did not return a value, but simply handled the task of printing the correct dice to the screen. H. W. Gould, Winter Page 8

9 Classes and Objects (IT152) IT150/IT152 Concepts Summary Sheet Object-oriented programming established the concept of writing computer programs that more accurately reflect the real world. Objects can be designed to match real world objects such as cars or buildings or even abstract things like hotel reservations or client accounts. The relationship between a class and an object can easily be explained with the words automobile and your specific automobile. The word automobile has with it certain understood properties. Automobiles have tires, doors, motors, windshields, etc., regardless of make and model. However, the specifications on these various properties varies with each individual automobile. A class (and any object or instance of that class) will have certain data properties and functions in it that affect its own data. The automobile class, for example, has the data value of how much fuel is onboard. A member function might be one that adds gas in the amount specified when the method is called. An objects methods will only affect that particular object, not all objects of the same class. If I add gas to my car, it doesn t affect the fuel level of all the other cars in the parking lot. If my car is blue and I paint it red, the color data property of my car will change, but your car will remain the same color as always, unless you run the same function in your instance of automobile. To create an object of a particular class is to instantiate the class. It means, simply put, that you created a specific instance of that class, just as your car is a specific instance of the automobile class. To run a method or function in a particular object, you run it using the object name and the method/function name, like this: omycar.paintme( Red ); which would run the method inside the object omycar. Thus, the object omycar s data value for color would now be red. The data value for color on oyourcar would remain untouched. By designing well-planned objects, such as a Person class, you can use and re-use your classes. A Person class might be used to track employees of a company, passengers on a plane, or clients of a law firm among other possibilities. Anywhere in the world of software development where dealing with people, this class would apply. A class has two methods in it which must always be included the Constructors. This is a method that creates the object of the class. One of them will take parameters such as (for the car class) make, model, year, engine size, number of doors, etc. The other, the default Constructor, takes no parameters whatsoever, and creates an object of the class that fits default values. Even if you do not believe you will ever need it, you always (by convention) include a default constructor. Everything that applies in a main program can also be done in a class. Classes can contain functions, subroutines, and data values of all data types. Generally, the data members are listed as private, which means they cannot be viewed nor modified from outside the object. A well-written class will have methods that will display the values to the calling program, and will have methods that modify the values, if it is appropriate to do so. H. W. Gould, Winter Page 9

10 Summary Writing software it not difficult once the concept of think like a computer is achieved, which simply means that the software developer can think through a process step-by-step without worrying about what will happen several steps down the road, so to speak. We all do this; we just don t think about this. When you go to Facebook, you follow the individual steps like going to your computer, logging into it, opening your browser, entering the Facebook URL into it, and entering your login and password. You don t think about this process; you simply do it. It comes naturally to you. H. W. Gould, Winter Page 10

IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

More information

Introduction To C#.NET

Introduction To C#.NET Introduction To C#.NET Microsoft.Net was formerly known as Next Generation Windows Services(NGWS).It is a completely new platform for developing the next generation of windows/web applications. However

More information

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet. Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

More information

CHAPTER 7 OBJECTS AND CLASSES

CHAPTER 7 OBJECTS AND CLASSES CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and

More information

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu if Statements Designing Classes Abstraction and Encapsulation Readings This Week s Reading: Review Ch 1-4 (that were previously

More information

CHAPTER 7 OBJECTS AND CLASSES

CHAPTER 7 OBJECTS AND CLASSES CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and

More information

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015 COMP-202: Foundations of Programming Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015 Announcements Check the calendar on the course webpage regularly for updates on tutorials and office hours.

More information

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like?

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like? Chapter 3 - Simple JavaScript - Programming Basics Lesson 1 - JavaScript: What is it and what does it look like? PP presentation JavaScript.ppt. Lab 3.1. Lesson 2 - JavaScript Comments, document.write(),

More information

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)... Remembering numbers (and other stuff)... Let s talk about one of the most important things in any programming language. It s called a variable. Don t let the name scare you. What it does is really simple.

More information

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments Basics Objectives Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments 2 Class Keyword class used to define new type specify

More information

Some Computer Preliminaries

Some Computer Preliminaries Some Computer Preliminaries Before we get started, let's look at some basic components that play a major role in a computer's ability to run programs: 1) Central Processing Unit: The "brains" of the computer

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

CSE 113 A. Announcements - Lab

CSE 113 A. Announcements - Lab CSE 113 A February 21-25, 2011 Announcements - Lab Lab 1, 2, 3, 4; Practice Assignment 1, 2, 3, 4 grades are available in Web-CAT look under Results -> Past Results and if looking for Lab 1, make sure

More information

PIC 10A Flow control. Ernest Ryu UCLA Mathematics

PIC 10A Flow control. Ernest Ryu UCLA Mathematics PIC 10A Flow control Ernest Ryu UCLA Mathematics If statement An if statement conditionally executes a block of code. # include < iostream > using namespace std ; int main () { double d1; cin >> d1; if

More information

The Big Python Guide

The Big Python Guide The Big Python Guide Big Python Guide - Page 1 Contents Input, Output and Variables........ 3 Selection (if...then)......... 4 Iteration (for loops)......... 5 Iteration (while loops)........ 6 String

More information

CSE 142 Su 04 Computer Programming 1 - Java. Objects

CSE 142 Su 04 Computer Programming 1 - Java. Objects Objects Objects have state and behavior. State is maintained in instance variables which live as long as the object does. Behavior is implemented in methods, which can be called by other objects to request

More information

Coding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic.

Coding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic. Coding Workshop Learning to Program with an Arduino Lecture Notes Table of Contents Programming ntroduction Values Assignment Arithmetic Control Tests f Blocks For Blocks Functions Arduino Main Functions

More information

4. Java Project Design, Input Methods

4. Java Project Design, Input Methods 4-1 4. Java Project Design, Input Methods Review and Preview You should now be fairly comfortable with creating, compiling and running simple Java projects. In this class, we continue learning new Java

More information

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types. Class #07: Java Primitives Software Design I (CS 120): M. Allen, 13 Sep. 2018 Two Types of Types So far, we have mainly been dealing with objects, like DrawingGizmo, Window, Triangle, that are: 1. Specified

More information

T H E I N T E R A C T I V E S H E L L

T H E I N T E R A C T I V E S H E L L 3 T H E I N T E R A C T I V E S H E L L The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform. Ada Lovelace, October 1842 Before

More information

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects Administrative Stuff September 12, 2007 HW3 is due on Friday No new HW will be out this week Next Tuesday we will have Midterm 1: Sep 18 @ 6:30 7:45pm. Location: Curtiss Hall 127 (classroom) On Monday

More information

Create a Login System in Visual Basic. Creating a login system. Start a new visual basic Windows Forms application project. Call it Login System

Create a Login System in Visual Basic. Creating a login system. Start a new visual basic Windows Forms application project. Call it Login System Creating a login system Start a new visual basic Windows Forms application project Call it Login System Change the form TITLE from Form1 to Login System Add the following to the form Component Text Name

More information

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 10A Lecture - 20 What is a function?

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

Storing Data in Objects

Storing Data in Objects Storing Data in Objects Rob Miles Department of Computer Science 28d 08120 Programming 2 Objects and Items I have said for some time that you use objects to represent things in your problem Objects equate

More information

General Syntax. Operators. Variables. Arithmetic. Comparison. Assignment. Boolean. Types. Syntax int i; float j = 1.35; int k = (int) j;

General Syntax. Operators. Variables. Arithmetic. Comparison. Assignment. Boolean. Types. Syntax int i; float j = 1.35; int k = (int) j; General Syntax Statements are the basic building block of any C program. They can assign a value to a variable, or make a comparison, or make a function call. They must be terminated by a semicolon. Every

More information

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2. Class #10: Understanding Primitives and Assignments Software Design I (CS 120): M. Allen, 19 Sep. 18 Java Arithmetic } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = 2 + 5 / 2; 3.

More information

CHAPTER : 9 FLOW OF CONTROL

CHAPTER : 9 FLOW OF CONTROL CHAPTER 9 FLOW OF CONTROL Statements-Statements are the instructions given to the Computer to perform any kind of action. Null Statement-A null statement is useful in those case where syntax of the language

More information

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics COMP-202 Unit 1: Introduction Announcements Did you miss the first lecture? Come talk to me after class. If you want

More information

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Fundamentals of Programming. Lecture 3: Introduction to C Programming Fundamentals of Programming Lecture 3: Introduction to C Programming Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department Outline A Simple C

More information

Lesson 3: Accepting User Input and Using Different Methods for Output

Lesson 3: Accepting User Input and Using Different Methods for Output Lesson 3: Accepting User Input and Using Different Methods for Output Introduction So far, you have had an overview of the basics in Java. This document will discuss how to put some power in your program

More information

Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras

Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras Module 12B Lecture - 41 Brief introduction to C++ Hello, welcome

More information

Handout 9: Imperative Programs and State

Handout 9: Imperative Programs and State 06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 9: Imperative Programs and State Imperative

More information

COMP 202 Java in one week

COMP 202 Java in one week CONTENTS: Basics of Programming Variables and Assignment Data Types: int, float, (string) Example: Implementing a calculator COMP 202 Java in one week The Java Programming Language A programming language

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

C# Programming for Developers Course Labs Contents

C# Programming for Developers Course Labs Contents C# Programming for Developers Course Labs Contents C# Programming for Developers...1 Course Labs Contents...1 Introduction to C#...3 Aims...3 Your First C# Program...3 C# The Basics...5 The Aims...5 Declaring

More information

Basic Programming Language Syntax

Basic Programming Language Syntax Java Created in 1990 by Sun Microsystems. Free compiler from Sun, commercial from many vendors. We use free (Sun) Java on UNIX. Compiling and Interpreting...are processes of translating a high-level programming

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba Laboratory Session: Exercises on classes Analogy to help you understand classes and their contents. Suppose you want to drive a car and make it go faster by pressing down

More information

Section 0.3 The Order of Operations

Section 0.3 The Order of Operations Section 0.3 The Contents: Evaluating an Expression Grouping Symbols OPERATIONS The Distributive Property Answers Focus Exercises Let s be reminded of those operations seen thus far in the course: Operation

More information

CPS122 Lecture: From Python to Java

CPS122 Lecture: From Python to Java Objectives: CPS122 Lecture: From Python to Java last revised January 7, 2013 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

CPS122 Lecture: From Python to Java last revised January 4, Objectives: Objectives: CPS122 Lecture: From Python to Java last revised January 4, 2017 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

public class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() {

public class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() { Scoping, Static Variables, Overloading, Packages In this lecture, we will examine in more detail the notion of scope for variables. We ve already indicated that variables only exist within the block they

More information

Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment

More information

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage: Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;

More information

Variables. Data Types.

Variables. Data Types. Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

More information

LOOPS. Repetition using the while statement

LOOPS. Repetition using the while statement 1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while

More information

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to: Get JAVA To compile programs you need the JDK (Java Development Kit). To RUN programs you need the JRE (Java Runtime Environment). This download will get BOTH of them, so that you will be able to both

More information

Ticket Machine Project(s)

Ticket Machine Project(s) Ticket Machine Project(s) Understanding the basic contents of classes Produced by: Dr. Siobhán Drohan (based on Chapter 2, Objects First with Java - A Practical Introduction using BlueJ, David J. Barnes,

More information

CGS 3066: Spring 2015 JavaScript Reference

CGS 3066: Spring 2015 JavaScript Reference CGS 3066: Spring 2015 JavaScript Reference Can also be used as a study guide. Only covers topics discussed in class. 1 Introduction JavaScript is a scripting language produced by Netscape for use within

More information

Introduction. In this preliminary chapter, we introduce a couple of topics we ll be using DEVELOPING CLASSES

Introduction. In this preliminary chapter, we introduce a couple of topics we ll be using DEVELOPING CLASSES Introduction In this preliminary chapter, we introduce a couple of topics we ll be using throughout the book. First, we discuss how to use classes and object-oriented programming (OOP) to aid in the development

More information

Unit 3 Decision making, Looping and Arrays

Unit 3 Decision making, Looping and Arrays Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.

More information

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style CS125 : Introduction to Computer Science Lecture Notes #4 Type Checking, Input/Output, and Programming Style c 2005, 2004, 2002, 2001, 2000 Jason Zych 1 Lecture 4 : Type Checking, Input/Output, and Programming

More information

Working with Objects. Overview. This chapter covers. ! Overview! Properties and Fields! Initialization! Constructors! Assignment

Working with Objects. Overview. This chapter covers. ! Overview! Properties and Fields! Initialization! Constructors! Assignment 4 Working with Objects 41 This chapter covers! Overview! Properties and Fields! Initialization! Constructors! Assignment Overview When you look around yourself, in your office; your city; or even the world,

More information

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

A variable is a name for a location in memory A variable must be declared

A variable is a name for a location in memory A variable must be declared Variables A variable is a name for a location in memory A variable must be declared, specifying the variable's name and the type of information that will be held in it data type variable name int total;

More information

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Abstraction and Encapsulation javadoc More About if Statements Readings This Week: Ch 5.1-5.4 (Ch 6.1-6.4 in 2 nd ed). (Reminder:

More information

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University AN OVERVIEW OF C, PART 3 CSE 130: Introduction to Programming in C Stony Brook University FANCIER OUTPUT FORMATTING Recall that you can insert a text field width value into a printf() format specifier:

More information

Chapter 1 - What s in a program?

Chapter 1 - What s in a program? Chapter 1 - What s in a program? I. Student Learning Outcomes (SLOs) a. You should be able to use Input-Process-Output charts to define basic processes in a programming module. b. You should be able to

More information

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing.

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing. CISC-124 20180115 20180116 20180118 We continued our introductory exploration of Java and object-oriented programming by looking at a program that uses two classes. We created a Java file Dog.java and

More information

The Dynamic Typing Interlude

The Dynamic Typing Interlude CHAPTER 6 The Dynamic Typing Interlude In the prior chapter, we began exploring Python s core object types in depth with a look at Python numbers. We ll resume our object type tour in the next chapter,

More information

Computer Science II. OO Programming Classes Scott C Johnson Rochester Institute of Technology

Computer Science II. OO Programming Classes Scott C Johnson Rochester Institute of Technology Computer Science II OO Programming Classes Scott C Johnson Rochester Institute of Technology Outline Object-Oriented (OO) Programming Review Initial Implementation Constructors Other Standard Behaviors

More information

Object-Oriented Programming Paradigm

Object-Oriented Programming Paradigm Object-Oriented Programming Paradigm Sample Courseware Object-Oriented Programming Paradigm Object-oriented programming approach allows programmers to write computer programs by representing elements of

More information

Chapter 2: Functions and Control Structures

Chapter 2: Functions and Control Structures Chapter 2: Functions and Control Structures TRUE/FALSE 1. A function definition contains the lines of code that make up a function. T PTS: 1 REF: 75 2. Functions are placed within parentheses that follow

More information

Introduction to the Java Basics: Control Flow Statements

Introduction to the Java Basics: Control Flow Statements Lesson 3: Introduction to the Java Basics: Control Flow Statements Repetition Structures THEORY Variable Assignment You can only assign a value to a variable that is consistent with the variable s declared

More information

do fifty two: Language Reference Manual

do fifty two: Language Reference Manual do fifty two: Language Reference Manual Sinclair Target Jayson Ng Josephine Tirtanata Yichi Liu Yunfei Wang 1. Introduction We propose a card game language targeted not at proficient programmers but at

More information

COMP 202. Java in one week

COMP 202. Java in one week COMP 202 CONTENTS: Basics of Programming Variables and Assignment Data Types: int, float, (string) Example: Implementing a calculator Java in one week The Java Programming Language A programming language

More information

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab. University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Second week Variables Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable.

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

More information

CS1004: Intro to CS in Java, Spring 2005

CS1004: Intro to CS in Java, Spring 2005 CS1004: Intro to CS in Java, Spring 2005 Lecture #23: OO Design, cont d. Janak J Parekh janak@cs.columbia.edu Administrivia HW#5 due Tuesday And if you re cheating on (or letting others see your) HW#5

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

Programming with Java

Programming with Java Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules

More information

Enumerated Types. CSE 114, Computer Science 1 Stony Brook University

Enumerated Types. CSE 114, Computer Science 1 Stony Brook University Enumerated Types CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Enumerated Types An enumerated type defines a list of enumerated values Each value is an identifier

More information

Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3

Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3 Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3 Ziad Matni Dept. of Computer Science, UCSB Compiling Programs in C++ Input and Output Streams Simple Flow

More information

Michele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring

Michele Van Dyne Museum 204B  CSCI 136: Fundamentals of Computer Science II, Spring Michele Van Dyne Museum 204B mvandyne@mtech.edu http://katie.mtech.edu/classes/csci136 CSCI 136: Fundamentals of Computer Science II, Spring 2016 1 Review of Java Basics Data Types Arrays NEW: multidimensional

More information

Static Methods. Why use methods?

Static Methods. Why use methods? Static Methods A method is just a collection of code. They are also called functions or procedures. It provides a way to break a larger program up into smaller, reusable chunks. This also has the benefit

More information

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3).

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3). CIT Intro to Computer Systems Lecture # (//) Functions As you probably know from your other programming courses, a key part of any modern programming language is the ability to create separate functions

More information

6 Functions. 6.1 Focus on Software Engineering: Modular Programming TOPICS. CONCEPT: A program may be broken up into manageable functions.

6 Functions. 6.1 Focus on Software Engineering: Modular Programming TOPICS. CONCEPT: A program may be broken up into manageable functions. 6 Functions TOPICS 6.1 Focus on Software Engineering: Modular Programming 6.2 Defining and Calling Functions 6.3 Function Prototypes 6.4 Sending Data into a Function 6.5 Passing Data by Value 6.6 Focus

More information

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122 Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122 I. Logic 101 In logic, a statement or proposition is a sentence that can either be true or false. A predicate is a sentence in

More information

Math Modeling in Java: An S-I Compartment Model

Math Modeling in Java: An S-I Compartment Model 1 Math Modeling in Java: An S-I Compartment Model Basic Concepts What is a compartment model? A compartment model is one in which a population is modeled by treating its members as if they are separated

More information

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program: Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams

More information

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. Lesson 2 VARIABLES Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. WHAT ARE VARIABLES? When you input data (i.e. information) into a computer

More information

3 The L oop Control Structure

3 The L oop Control Structure 3 The L oop Control Structure Loops The while Loop Tips and Traps More Operators The for Loop Nesting of Loops Multiple Initialisations in the for Loop The Odd Loop The break Statement The continue Statement

More information

Chapter Goals. Contents LOOPS

Chapter Goals. Contents LOOPS CHAPTER 4 LOOPS Slides by Donald W. Smith TechNeTrain.com Final Draft Oct 30, 2011 Chapter Goals To implement while, for, and do loops To hand-trace the execution of a program To become familiar with common

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

Microsoft Visual Basic 2015: Reloaded

Microsoft Visual Basic 2015: Reloaded Microsoft Visual Basic 2015: Reloaded Sixth Edition Chapter Three Memory Locations and Calculations Objectives After studying this chapter, you should be able to: Declare variables and named constants

More information

Object Oriented Programming in C#

Object Oriented Programming in C# Introduction to Object Oriented Programming in C# Class and Object 1 You will be able to: Objectives 1. Write a simple class definition in C#. 2. Control access to the methods and data in a class. 3. Create

More information

egrapher Language Reference Manual

egrapher Language Reference Manual egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction

More information

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++ Repetition Contents 1 Repetition 1.1 Introduction 1.2 Three Types of Program Control Chapter 5 Introduction 1.3 Two Types of Repetition 1.4 Three Structures for Looping in C++ 1.5 The while Control Structure

More information

Fundamental Concepts and Definitions

Fundamental Concepts and Definitions Fundamental Concepts and Definitions Identifier / Symbol / Name These terms are synonymous: they refer to the name given to a programming component. Classes, variables, functions, and methods are the most

More information

Maciej Sobieraj. Lecture 1

Maciej Sobieraj. Lecture 1 Maciej Sobieraj Lecture 1 Outline 1. Introduction to computer programming 2. Advanced flow control and data aggregates Your first program First we need to define our expectations for the program. They

More information

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1 OBJECT ORIENTED SIMULATION LANGUAGE OOSimL Reference Manual - Part 1 Technical Report TR-CSIS-OOPsimL-1 José M. Garrido Department of Computer Science Updated November 2014 College of Computing and Software

More information

CHAPTER 9 FLOW OF CONTROL

CHAPTER 9 FLOW OF CONTROL CHAPTER 9 FLOW OF CONTROL FLOW CONTROL In a program statement may be executed sequentially, selectively or iteratively. Every program language provides constructs to support sequence, selection or iteration.

More information

Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007

Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007 Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007 Java We will be programming in Java in this course. Partly because it is a reasonable language, and partly because you

More information