2. C++ Basics - ENGR 101 (Sec 100), Fall 2010 Announcements...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
ENGR 101 (Sec 100), Fall 2010 1 Introduction to C++ ENGR 101, Lecture 2: 13 Sep 10 Announcements Office hours begin this week schedule posted on CTools (exceptions TBA) Project 1 is posted Due Wednesday 15 Sep at 9pm Make sure you know how to submit your project Exam conflicts Notify Nader Jawad (njawad @umich.edu ) From Algorithms to Programs Algorithm: A precise specification of a computational process. If the specification is precise enough to execute automatically, we call it a program , and refer to the text as code . Last time: described algorithms using pseudocode . Good for communicating with people, but does not meet condition for “true” code. Today: real programs. Machine Language Computers directly execute instructions specifying very low-level operations. This machine language is ultimately encoded as strings of binary digits (bits) , specifying the instructions and data operated on. Writing directly in machine language is taxing for humans because it is so rudimentary. NOT
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ENGR 101 (Sec 100), Fall 2010 2 Programming Language The means to express algorithms in data. High-level programming language: Textual (usually) representation of programs, designed to be convenient for humans to express and understand. Examples: C++, Matlab Two dimensions to defining a programming language: Syntax : defines the legal programs (vocabulary and grammar) Semantics : defines the meaning , how the program corresponds to an actual computation To execute a program written in a high-level language, it must first be translated to machine language by a program (!) called a compiler or interpreter “heart” of the program A C++ Program #include <iostream> using namespace std; int main ( ) { double x, y; cin >> x; y = x * 7; cout << y; return 0; } “scaffolding” A C++ Program: Heart Algorithm: Read in a number Multiply by 7 Output result First line: a declaration Introduces identifiers x and y Names for data elements Declares the type of data associated with these names #include <iostream> using namespace std; int main ( ) { double x, y; cin >> x; y = x * 7; cout << y; return 0; } C++ Declaration Simple declarations are of the form: simple_type identifiers ; simple_type is a symbol specifying a type identifiers is a comma-separated list of identifiers In our example, we introduce the identifiers x and y, and declare that they are of type double . The type double is one of several numeric data types supported by C++. double x, y;
Background image of page 2
ENGR 101 (Sec 100), Fall 2010 3 Numeric Data Types Much (but not all!) computing is about numbers All programming languages have special facilities to handle numeric data Multiple types of numbers: differ on class of values that can be expressed Two basic C++ number types: int : an integer in restricted range (typically around –2 billion to +2 billion) double
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

2. C++ Basics - ENGR 101 (Sec 100), Fall 2010 Announcements...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online