These are notes for the third lecture; if statements and loops.
|
|
- Terence Whitehead
- 6 years ago
- Views:
Transcription
1 These are notes for the third lecture; if statements and loops. 1
2 Yeah, this is going to be the second slide in a lot of lectures. 2
3 - Dominant language for desktop application development - Most modern operating systems are written in C and C++ - Much faster than interpreted languages - Tons of library support for both C and C++ 3
4 - Interpreted languages are usually much slower than compiled languages - But! The difference is a lot less noticeable if the user is waiting on something (e.g., the internet) other than the processor to calculate things - Often easier to work with - Often more portable - Less drama when they crash - Web developed is almost exclusively interpreted (or bytecode compiled) languages - More secure 4
5 The tools we ll be using this semester. The IDE is what ties them together, but it is effectively just a wrapper for the other tools. The compiler compiles the code the text we send it into machine-readable binary code. The linker connects the function calls we make in our source code to the libraries the operating system uses, so when the computer executes our code it knows where to find the functions we call but don t describe. The debugger makes software engineering survivable. 5
6 Two separate things. We #include headers, this tells the compiler what functions we can call and what classes we can use. The linker connects our compiled code to the libraries that contain the machine code for the functions we call and classes we use. They are different concepts. 6
7 #include to include header files in our source code files. These are the two we ve used iostream (cout, endl) and string (uh, string) This is a preprocessor directive as a result, it follows different rules from other statements. Preprocessor directives are (largely) a relic left over from C; there are some others, but #include is the only one that s important for this course. 7
8 Will show up in all programs. Needed to prevent us from having std:: everywhere. Not to much to really think about, but make sure it s there. 8
9 The important scalar types we use. Slide says it all. 9
10 Sending output to the console. cout : console output. String literal. endl: end line 10
11 Big subject of the previous lecture we ll get to why this can be a serious problem later. 11
12 We also learned that the 70s were not a good time for fashion. 12
13 13
14 I m going to mention (and show) a few things I will describe as bad form. This is stuff that will work, but is considered (whether a loose consensus or fairly universally) to be bad form as in, stuff you just shouldn t do. 14
15 The boolean type. A basic type in C++. Can be true or false. Storage size is not specified by the C++ standard. 15
16 Literals are values embedded in the code itself. Note that these very frequently end up being magic numbers and should be avoided, but they have to be defined somewhere. (To repeat; magic numbers are values embedded in the code of a program that are not explicitly declared as constants. 0, 1, -1 and sometimes 2 do not qualify as magic numbers) 16
17 A number without a decimal point is an integer. A number with a decimal point is a double. Anything within double quotes is a string. A single character within single quotes is a char. The words true or false (no quotes of any type!) are literal bool values. 17
18 How to embed quotes in literal strings. These special sequences to represent values that would otherwise have meaning within the string (or character) are called escape sequences. The process of doing so is called escaping. Backslashes must be escaped themselves because they are used to escape other characters. 18
19 Result of program execution. 19
20 Now, we ll talk about something else important to variables converting from one type to another. We will talk about explicit conversion later, but now we ll talk about implicit conversion. This happens when we put an expression in a place where we need it to be of a different type. Scalar types have some fairly simple rules for this; objects (like strings) work very differently, but we ll cover those a good bit later in the class. 20
21 When you take a floating point value, and assign it to an integer, C++ performs a truncation. This strips everything past the decimal point and gives you what s left over. It does not perform rounding, only truncation. This will throw a warning in the compiler as you are losing precision anything after the decimal point is lost, so the compiler will tell you about it. Assigning an integer value to a double just puts that value in the double (or as close as it can manage!) 21
22 Bools work only slightly differently. If the expression evaluates to zero (integer or floating point), the boolean value is false. Otherwise, it s true. This will be very important later 22
23 We re going to talk a little bit about expressions. In C++, everything is an expression. There is a special type called void which does not evaluate to any value (and the compiler will tell you in no uncertain terms when you try to assign a void value to a variable), but anything that is not void (which is just about everything) evaluates to a value. This deserves to be repeated everything (well, almost) is an expression. That was one of the goals of the original C language, and C++ follows it faithfully. 23
24 Everybody loves this, don t they? 24
25 Everyone seen something like this before on the internet? Seen the huge flamewar that usually crops up? I m going to give you the answer from the engineering perspective (remember that?) for not just this one but all such problems. 25
26 This isn t a puzzle. This isn t a competition to show off expression parsing abilities. At the core of software engineering is the desire to maximize the clarity of expression of our ideas. Clarity of expression is something that s going to come up a lot in this class; it s a vital part of software engineering. Writing code that s difficult to read for no good reason is the epitome of poor engineering. 26
27 That said, we ve got to talk about order of operations in C++ a little bit. Red marked operators on the slide (increment (++), decrement(--), and assignment (=)) all have side effects they do something other than return the result. Increment (++) adds one to the variable it s attached to. Decrement (--) subtracts one from the variable it s attached to. Assignment (=) sets the variable on its left side to the value on its right side. And then returns that value Also noted above are the insertion(<<) and extraction(>>) operators, which we use a lot to send stuff to the console; their position in the list is good to know when writing expressions to the console. 27
28 Note the error squiggle. Comments in the slide explain this pretty well; the compiler follows the order of operation rules, and will throw an error in the second case because what it evaluates to doesn t make sense. 28
29 Increment/decrement unary operators. ++ increments the variable. -- decrements it. The order they appear in relation to the variable depends on how the expression evaluates if the operator is before, the operation happens before the expression s value is evaluated, if it s after the operation happens afterward. 29
30 Just some code to demonstrate the difference 30
31 And the results. 31
32 This does raise the question shouldn t the language be called ++C if it is an enhancement to C, as while C++ (as an expression) does increment the value of C, it evaluates to what was in C before the operation 32
33 This is the non-intuitive one. The assignment operator (=) can be part of an expression itself; in the above code, (a = 5) does assign the value 5 to a, but also evaluates to 5. Results follow on the next slide. 33
34 34
35 This isn t going into a long conceptual rambling, like the slides with Why on them, but we re talking about the if statement. 35
36 If is a conditional statement. We usually just call this a conditional (plural conditionals), as engineers typically aren t big fans of a lot of extra syllables. 36
37 Things to note: The if statement does not terminate with a semicolon. A block immediately follows it. If the expression inside evaluates to true, what is in the block is executed. 37
38 What goes in the parentheses immediately following the if is called the condition. The block (or single statement) that follows is called the body. 38
39 We can execute more statements within the block; everything within the block gets executed if the condition is true, nothing inside the block gets executed if it is not. 39
40 We can also just put a single statement after the if statement, although this is often considered to be bad form; please avoid this. 40
41 The compiler will warn you about this one. 41
42 The next step is to add the else statement to the if This lets us execute some different code if the condition is false. 42
43 Format of the if statement with else included. 43
44 Again with the bad form. While an if with a single statement body is sometimes acceptable, I m going to assert that single-statement if/else pairs are always bad form. Page 98 in your book describes the dangling else problem, which is a pretty big reason why I say single-statement if/else pairs are bad. It s worth reading, but we won t go over it in class because we re going to be using full blocks in all of our if/else pairs, so it won t matter. 44
45 You should have all covered the basics of ands and ors and complex conditions. They work just like normal expressions. CS 115 should have covered the basics. Most of you will take (have taken, or are taking) EE 280, which is an excellent course (taught by an excellent educator, no less) that covers an awful lot about boolean mathematics, and it applies pretty directly to computer science. 45
46 That said, you should understand what this means... What I will talk about, though 46
47 We have mentioned this concept. What does it actually mean? 47
48 The condition in an if statement gets converted to a bool value; it always gets converted to either true or false using the implicit conversion rules for bools mentioned earlier (to recap: numerically equal to zero (integer or floating point)? False. Anything else? True.). This combines with assignment being a normal operator that can be evaluated as a normal expression to allow some pretty vicious mistakes to happen. 48
49 Explanation of the evaluation process in the first example. This is the simplest case; the expression directly evaluates to a bool value, so no more conversion has to happen. 49
50 This is an example of implicit conversion to bool the expression evaluates to a numeric value, and that value is compared to zero. Since it s not zero, it gets converted to true. 50
51 And here we have the problem! In almost all of these cases, the programmer meant to have a comparison (==) operator instead of an assignment (=) operator. But the assignment operator is part of a legitimate expression which evaluates to a legitimate integer value which can then be implicitly converted to a bool value. Which is all perfectly valid C++ -- but almost never what the programmer intended! 51
52 Just to recap 52
53 Now for loops. 53
54 The simplest loop type is the while loop. It, uh, loops while a condition is true. 54
55 Like if statements, while loops have a condition and body. The condition is evaluated. If false, the loop ends (note that the body is not guaranteed to be execited at all!). If true, the body is executed and then we return to the condition. 55
56 Output of the previous program. 56
57 Visual representation. The loop can be terminated at the red statement. Note that the test condition always is checked first, and there s no guarantee that the body is ever executed. 57
58 What do we think this is going to do? Other than make your computer seem really happy, it keeps executing the body and never stops this is an infinite loop. 58
59 And what does this one do? Nothing a all the condition is false at the start, so the body is never executed. 59
60 The next style of loop; the do/while loop. Turns out to be a subtle variant of the while loop 60
61 Syntax of the do/while loop. 61
62 It has a condition and body just like ifs and whiles. They re just in the opposite order, because (unlike the while loop) the body is always executed at least once; first the body is executed, and then the condition is tested. 62
63 Program output. 63
64 Visual description. Body executed first (and always at least once!), then the condition is tested. The loop can terminate at the test condition. 64
65 Another example; condition is false to start. 65
66 But unlike the while loop, the body still gets executed once. 66
67 Single statement loops are bad form. Don t write them. 67
68 And now, the big one the for loop. Most programmers prefer to use for loops because of their versitility. 68
69 A basic for loop. 69
70 And its output. 70
71 The parts of the for loop: - The initializer gets executed (and is always executed) at the start of the loop. As you can see here, you can declare variables here. - The condition is much like the other conditions; it is tested before the first execution of the body (like a while loop, a for loop is not guaranteed to execute the body!), and at each iteration of the loop. - The increment gets executed after the body and before the condition is tested during each iteration. 71
72 Visual description. Initializer is executed first, always, and only once. Then the condition is tested the loop ends if the condition is false. Then the body is executed. Then the increment is executed. Then we go back to the condition. 72
73 The sub-statements within a for are optional, but it s bad form to not use them (unless you have a good reason not to). This will be discussed more when we get to scope 73
74 Here s an example of a for loop working from 10 to 1; note that the increment step uses the decrement operator (--). Yes, we still call it the increment step in this case. 74
75 Here s the output. Note! While we used the same numbers (0 and 10) as the forward loop, in the forward loop, we printed out 0 through 9, here we printed out 10 through 1. Why the difference? Because we need to be careful with our conditions; if we use greater than/less than (>/<; as opposed to >=/<=), the loop will never get to the last value. i > 0 is false when i gets to zero, so we don t execute the body of the loop with i equal to zero. If we wanted the loop to do something at i equal to zero, this would be an off by one error it s what happens when you write code that stops one iteration before you want it to (or starts one iteration late!). It s an easy mistake to make be careful to have the correct comparison operator in your conditions! 75
76 And a recap and comparison of the three loop types. 76
Sixth lecture; classes, objects, reference operator.
Sixth lecture; classes, objects, reference operator. 1 Some notes on the administration of the class: From here on out, homework assignments should be a bit shorter, and labs a bit longer. My office hours
More informationNumerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2
Numerical Computing in C and C++ Jamie Griffin Semester A 2017 Lecture 2 Visual Studio in QM PC rooms Microsoft Visual Studio Community 2015. Bancroft Building 1.15a; Queen s W207, EB7; Engineering W128.D.
More informationC++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5
C++ Data Types Contents 1 Simple C++ Data Types 2 2 Quick Note About Representations 3 3 Numeric Types 4 3.1 Integers (whole numbers)............................................ 4 3.2 Decimal Numbers.................................................
More informationCOSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14
COSC 2P91 Introduction Part Deux Week 1b Brock University Brock University (Week 1b) Introduction Part Deux 1 / 14 Source Files Like most other compiled languages, we ll be dealing with a few different
More informationMaciej 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 informationprintf( Please enter another number: ); scanf( %d, &num2);
CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful
More information1007 Imperative Programming Part II
Agenda 1007 Imperative Programming Part II We ve seen the basic ideas of sequence, iteration and selection. Now let s look at what else we need to start writing useful programs. Details now start to be
More informationPIC 10A Objects/Classes
PIC 10A Objects/Classes Ernest Ryu UCLA Mathematics Last edited: November 13, 2017 User-defined types In C++, we can define our own custom types. Object is synonymous to variable, and class is synonymous
More informationThe 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 informationIntro. 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 informationPIC 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 informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More informationC++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay
C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming
More informationPIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics
PIC 10A Pointers, Arrays, and Dynamic Memory Allocation Ernest Ryu UCLA Mathematics Pointers A variable is stored somewhere in memory. The address-of operator & returns the memory address of the variable.
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More informationC++ Support Classes (Data and Variables)
C++ Support Classes (Data and Variables) School of Mathematics 2018 Today s lecture Topics: Computers and Programs; Syntax and Structure of a Program; Data and Variables; Aims: Understand the idea of programming
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions
More informationUnit 7. 'while' Loops
1 Unit 7 'while' Loops 2 Control Structures We need ways of making decisions in our program To repeat code until we want it to stop To only execute certain code if a condition is true To execute one segment
More informationControl Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003
Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an
More informationProgramming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur
Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 04 Programs with IO and Loop We will now discuss the module 2,
More informationStructured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:
Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language Dr. Amal Khalifa Lecture Contents: Introduction to C++ Origins Object-Oriented Programming, Terms Libraries and Namespaces
More informationVariables and literals
Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of
More informationExpressions and Casting
Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence
More informationCoding 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 informationCSCI 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 informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationControl Structures. Lecture 4 COP 3014 Fall September 18, 2017
Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls
More informationCS102: Variables and Expressions
CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of
More informationChapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the
More informationLooping and Counting. Lecture 3 Hartmut Kaiser hkaiser/fall_2012/csc1254.html
Looping and Counting Lecture 3 Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2012/csc1254.html Abstract First we ll discuss types and type safety. Then we will modify the program
More informationCh. 12: Operator Overloading
Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42
More informationComputer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons
Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite
More informationCS125 : 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 informationCOMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods
COMP-202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,
More information5. Control Statements
5. Control Statements This section of the course will introduce you to the major control statements in C++. These control statements are used to specify the branching in an algorithm/recipe. Control statements
More informationDivisibility Rules and Their Explanations
Divisibility Rules and Their Explanations Increase Your Number Sense These divisibility rules apply to determining the divisibility of a positive integer (1, 2, 3, ) by another positive integer or 0 (although
More informationExpressions and Casting. Data Manipulation. Simple Program 11/5/2013
Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence
More informationLecture 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 informationCIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)
CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts) Problem 0: Install Eclipse + CDT (or, as an alternative, Netbeans). Follow the instructions on my web site.
More informationChapter 2: Introduction to C++
Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++
More informationCS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation
CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;
More informationChapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley
More informationReview: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements
Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja
More informationo Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement
Last Time Let s all Repeat Together 10/3/05 CS150 Introduction to Computer Science 1 1 We covered o Counter and sentinel controlled loops o Formatting output Today we will o Type casting o Top-down, stepwise
More informationCS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output
CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables
More informationIntroduction to C ++
Introduction to C ++ Thomas Branch tcb06@ic.ac.uk Imperial College Software Society October 18, 2012 1 / 48 Buy Software Soc. s Free Membership at https://www.imperialcollegeunion.org/shop/ club-society-project-products/software-products/436/
More informationChapter 2 Basic Elements of C++
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion
More information(Refer Slide Time: 02:59)
Numerical Methods and Programming P. B. Sunil Kumar Department of Physics Indian Institute of Technology, Madras Lecture - 7 Error propagation and stability Last class we discussed about the representation
More informationLecture 3. Input, Output and Data Types
Lecture 3 Input, Output and Data Types Goals for today Variable Types Integers, Floating-Point, Strings, Booleans Conversion between types Operations on types Input/Output Some ways of getting input, and
More informationThe Basics. chapter 2. Why You Should Read This Chapter
02 csp ch02 10/4/04 2:16 PM Page 13 chapter 2 Chapter 1 showed you some history on why.net and C# were created. Now it s time to dive deep into the abyss and learn just how to use C#. In this chapter,
More informationLecture 4 CSE July 1992
Lecture 4 CSE 110 6 July 1992 1 More Operators C has many operators. Some of them, like +, are binary, which means that they require two operands, as in 4 + 5. Others are unary, which means they require
More informationText 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 informationVariables and Constants
HOUR 3 Variables and Constants Programs need a way to store the data they use. Variables and constants offer various ways to work with numbers and other values. In this hour you learn: How to declare and
More informationCS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore
CS 115 Data Types and Arithmetic; Testing Taken from notes by Dr. Neil Moore Statements A statement is the smallest unit of code that can be executed on its own. So far we ve seen simple statements: Assignment:
More informationCS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist
CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist In Handout 28, the Guide to Inductive Proofs, we outlined a number of specifc issues and concepts to be mindful about when
More informationLooping and Counting. Lecture 3. Hartmut Kaiser hkaiser/fall_2011/csc1254.html
Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2011/csc1254.html 2 Abstract First we ll discuss types and type safety. Then we will modify the program we developed last time (Framing
More informationHow to approach a computational problem
How to approach a computational problem A lot of people find computer programming difficult, especially when they first get started with it. Sometimes the problems are problems specifically related to
More informationTOPIC 2 INTRODUCTION TO JAVA AND DR JAVA
1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationFast Introduction to Object Oriented Programming and C++
Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming
More informationGetting started with C++ (Part 2)
Getting started with C++ (Part 2) CS427: Elements of Software Engineering Lecture 2.2 11am, 16 Jan 2012 CS427 Getting started with C++ (Part 2) 1/22 Outline 1 Recall from last week... 2 Recall: Output
More information4. Structure of a C++ program
4.1 Basic Structure 4. Structure of a C++ program The best way to learn a programming language is by writing programs. Typically, the first program beginners write is a program called "Hello World", which
More informationMobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02
Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Hello, in this lecture we will learn about some fundamentals concepts of java.
More informationOperator overloading
1 Introduction 2 The copy constructor 3 Operator Overloading 4 Eg 1: Adding two vectors 5 The -> operator 6 The this pointer 7 Overloading = 8 Unary operators 9 Overloading for the matrix class 10 The
More information3. Simple Types, Variables, and Constants
3. Simple Types, Variables, and Constants This section of the lectures will look at simple containers in which you can storing single values in the programming language C++. You might find it interesting
More informationMITOCW watch?v=0jljzrnhwoi
MITOCW watch?v=0jljzrnhwoi The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To
More informationC++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.
EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic
More informationChapter 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 informationC++ for Java Programmers
Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even
More informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More informationLECTURE 02 INTRODUCTION TO C++
PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION
More information2SKILL. 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 informationT 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 informationFundamentals 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 informationCS Introduction to Data Structures How to Parse Arithmetic Expressions
CS3901 - Introduction to Data Structures How to Parse Arithmetic Expressions Lt Col Joel Young One of the common task required in implementing programming languages, calculators, simulation systems, and
More informationChapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved
Chapter 1 C++ Basics Copyright 2010 Pearson Addison-Wesley. All rights reserved Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment
More informationBITG 1233: Introduction to C++
BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token
More information2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C
University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Expressions and Operators in C (Partially a Review) Expressions are Used
More informationCSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018
CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values
More informationFundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials
Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine
More informationDiscussion 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 informationcis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1
topics: introduction to java, part 1 cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 cis20.1-fall2007-sklar-leci.2 1 Java. Java is an object-oriented language: it is
More informationCOSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26
COSC 2P95 Procedural Abstraction Week 3 Brock University Brock University (Week 3) Procedural Abstraction 1 / 26 Procedural Abstraction We ve already discussed how to arrange complex sets of actions (e.g.
More informationThis watermark does not appear in the registered version - Slide 1
Slide 1 Chapter 1 C++ Basics Slide 2 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output Program Style
More informationC++ Basics. Lecture 2 COP 3014 Spring January 8, 2018
C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing
More informationOverview (4) CPE 101 mod/reusing slides from a UW course. Assignment Statement: Review. Why Study Expressions? D-1
CPE 101 mod/reusing slides from a UW course Overview (4) Lecture 4: Arithmetic Expressions Arithmetic expressions Integer and floating-point (double) types Unary and binary operators Precedence Associativity
More informationLecture 1: Overview
15-150 Lecture 1: Overview Lecture by Stefan Muller May 21, 2018 Welcome to 15-150! Today s lecture was an overview that showed the highlights of everything you re learning this semester, which also meant
More informationComputer Science II Lecture 1 Introduction and Background
Computer Science II Lecture 1 Introduction and Background Discussion of Syllabus Instructor, TAs, office hours Course web site, http://www.cs.rpi.edu/courses/fall04/cs2, will be up soon Course emphasis,
More informationAnnotation Annotation or block comments Provide high-level description and documentation of section of code More detail than simple comments
Variables, Data Types, and More Introduction In this lesson will introduce and study C annotation and comments C variables Identifiers C data types First thoughts on good coding style Declarations vs.
More informationOverview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program
Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of
More informationWhat Every Programmer Should Know About Floating-Point Arithmetic
What Every Programmer Should Know About Floating-Point Arithmetic Last updated: October 15, 2015 Contents 1 Why don t my numbers add up? 3 2 Basic Answers 3 2.1 Why don t my numbers, like 0.1 + 0.2 add
More informationCompiling 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 informationc++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.
Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object
More information2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program
More informationHardware versus software
Logic 1 Hardware versus software 2 In hardware such as chip design or architecture, designs are usually proven to be correct using proof tools In software, a program is very rarely proved correct Why?
More informationFull 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 informationIntroduction. 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 informationLab # 02. Basic Elements of C++ _ Part1
Lab # 02 Basic Elements of C++ _ Part1 Lab Objectives: After performing this lab, the students should be able to: Become familiar with the basic components of a C++ program, including functions, special
More information