Unit 2 Programming.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Pointer. Warning! Dangerous Curves C (and C++) have just about the most powerful, flexible and dangerous pointers in the world. –Most other languages.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
IWBAT compare and order positive and negative numbers.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Sahar Mosleh California State University San MarcosPage 1 A for loop can contain multiple initialization actions separated with commas Caution must be.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
This will all add up in the end. Assignment operator =Simple Assignment operator Arithmetic Operators +Additive operator – Subtraction operator * Multiplication.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
 Most C programs perform calculations using the C arithmetic operators (Fig. 2.9).  Note the use of various special symbols not used in algebra.  The.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Chapter 3 Structured Program Development in C Part II C How to Program, 8/e, GE © 2016 Pearson Education, Ltd. All rights reserved.1.
Chapter 2 Variables.
Expressions.
Chapter 7: Expressions and Assignment Statements
CHAPTER 4 REPETITION CONTROL STRUCTURE / LOOPING
Lecture 3 Java Operators.
Expressions.
Tokens in C Keywords Identifiers Constants
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
ITEC113 Algorithms and Programming Techniques
Object Oriented Programming
Chapter 7: Expressions and Assignment Statements
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Multiple variables can be created in one declaration
Assignment and Arithmetic expressions
Chapter 3 Assignment Statement
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Looping and Repetition
Lecture 3 Expressions Richard Gesick.
Arithmetic Operators in C
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Basic Notions Review what is a variable? value? address? memory location? what is an identifier? variable name? keyword? what is legal identifier? what.
Expressions Chapter 4 Copyright © 2008 W. W. Norton & Company.
Introduction to C++ Programming
Introduction to Java, and DrJava part 1
Introduction to Object-Oriented Programming with Java--Wu
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
Arithmetic Operators in C
Arithmetic Expressions & Data Conversions
Chapter 2 Variables.
C Operators, Operands, Expressions & Statements
Introduction to Java, and DrJava
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
INC 161 , CPE 100 Computer Programming
Data Types and Expressions
SSEA Computer Science: Track A
Introduction to Primitives
Introduction to Primitives
Operations and Arithmetic
Homework Finishing Chapter 2 of K&R. We will go through Chapter 3 very quickly. Not a lot is new. Questions?
Unit 3: Variables in Java
Introduction to Java, and DrJava part 1
Chapter 2 Variables.
Just Enough Java 17-May-19.
OPERATORS in C Programming
is multiplied by a variable of type to yield a result of type
Data Types and Expressions
OPERATORS in C Programming
Looping and Repetition
Arithmetic Expressions & Data Conversions
Data Types and Expressions
Presentation transcript:

Unit 2 Programming

Assuming that "final" is an int variable, what is the value of "final" after the following code fragment? final = 17; final /= 3; The result of integer division is truncated, which means that any remainder is discarded. The integer result therefore is 5.

Compiling Compiling is the process of converting 'C' program statements into a format the machine can execute (machine language).

Wait() The Wait() command is used to pause a program for the number of milliseconds specified in the input parameter. Any turning Motor Modules continue to run during this time.

While() loops While() loops are used to execute a section of code until some condition is met, usually until an expression evaluates to FALSE.

Assuming "headcount" is a variable of type unsigned char, and its current value is 175, what is the most you can add to it before it starts to wrap? An unsigned char can never be larger than 255 (8 bits). Thus the most you can add is 255 minus 175, or 80.

PWM In the context of EasyC, a PWM value of 0 will cause a Motor Module to stop turning.

The code "if (students = 14) {conditional code};" ___________. This is a hard-to-spot program error, where a single equals sign is used instead of a double equals sign. The programmer probably wanted the computer to execute the conditional code only if the value of "students" is 14. However, this error causes the assignment of a non-zero value to "students", which is evaluated as TRUE, and therefore the conditional code is always executed.

syntax error A syntax error is when you try to compile a code statement that cannot be understood by the compiler, due to typographic error or improper 'C' format.

After the following fragment of code, what is the value of "count"? count = 5; // Start with 5 count += 25; // Adding 25 yields 30 count -= 10; // Subtracting 10 yields 20 count *= 10; // Multiplying by 10 yields 200 count /= 5; // Dividing by 5 yields 40

You have a bin full of good tires ("tires"), and you need to know how many will be left over ("leftovers") after you take out all the full sets of 4. The code would look like: leftovers = tires % 4 The modulus operator (%), called "mod" for short, is used to find the remainder after division.

while()" statements You may always nest "while()" statements inside loops of any kind, including "for()" loops.

double equals sign, '==' The double equals sign, '==', means a comparison or test is performed. It does not do an assignment.

Signed ints versus unsigned ints: When a variable is declared to be signed, the wrap point is approximately 1/2 as large as that of an unsigned variable. Therefore a signed variable will wrap at a much lower value. This is true at the lower end as well, because signed variables can hold negative values, where the smallest possible value in an unsigned variable is zero.