CSCI261C/E Lecture 3: C++ Fundamentals (continued) August 31, 2011 - - PowerPoint PPT Presentation

csci261c e
SMART_READER_LITE
LIVE PREVIEW

CSCI261C/E Lecture 3: C++ Fundamentals (continued) August 31, 2011 - - PowerPoint PPT Presentation

CSCI261C/E Lecture 3: C++ Fundamentals (continued) August 31, 2011 ? Alan Turing 1912 - 1954 Turing Machine aka Universal Machine the man himself bombe code-breaking machine Review C++ program structure Preprocessing


slide-1
SLIDE 1

CSCI261C/E

Lecture 3: C++ Fundamentals (continued) August 31, 2011

slide-2
SLIDE 2

?

slide-3
SLIDE 3

Alan Turing

1912 - 1954 “Turing Machine” aka “Universal Machine”

bombe code-breaking machine

the man himself

slide-4
SLIDE 4

Review

  • C++ program structure
  • Preprocessing directives
  • main()
  • {code blocks}
  • Variable declarations & types (intro)
  • I/O (cin, cout)
slide-5
SLIDE 5

Comments

// a one line comment /* a multi- line comment */ /* omg! */

slide-6
SLIDE 6

Semicolon;

...is like a period at the end of a sentence. EXCEPT for preprocessing directives (they are special) #include<somelibrary>

dude, no semicolon!

slide-7
SLIDE 7

C++ is Case-Sensitive

double Porsche; double porsche; double pOrScHe; These are three different variables!

slide-8
SLIDE 8

Variables

  • are names pointing to values (like algebra)
  • should start w/ lower case
  • should not contain special characters
  • ($%^&@#! and the like)
slide-9
SLIDE 9

Syntax Notation Guide

[this is optional]

slide-10
SLIDE 10

Declaring Variables

[modifier] type name [= initial value]; [modifier] type name [(initial value)]; int x; int q = 0; double height(23.0); const int DAYS = 7; double z, y(0); // two at once, for style char initial = ‘j’; // character values need single-quotes

slide-11
SLIDE 11

Modifiers

const (for now)

slide-12
SLIDE 12

Types

  • short, int, long
  • float, double, long double
  • bool
  • char
  • string (#include<string>)
slide-13
SLIDE 13

An Abrupt Introduction to Classes and Objects

slide-14
SLIDE 14

...to be continued

slide-15
SLIDE 15

Symbolic Constant

  • it’s what you think it is (just a constant)
  • cannot change its value
  • for style, use ALL CAPS
  • often declared outside of main()

const double PI = 3.14159;

slide-16
SLIDE 16

Operators

  • think algebra
  • =, +, -, *, /, %
  • assignment (=) is not equality (==)!
  • follow precedence rules (p52)
slide-17
SLIDE 17

Increment & Decrement (with style)

int x; x = 1; x++; x = x + 1;

slide-18
SLIDE 18

Order Matters

int x, y; x = 10; y = ++x - 3; x = x + 1; y = x - 3; int x, y; x = 10; y = x++ - 3; y = x - 3; x = x + 1;

slide-19
SLIDE 19

Other “Tricks”

  • multiple assignment (p56)
slide-20
SLIDE 20

Operations w/ Multiple Types

int age = 21; double grade = 4.0; age = 21.5; // age = 21 grade = 2; // grade = 2.0 grade = ‘a’; // grade = ?*

* the ascii numeric value for the lower case letter ‘a’

slide-21
SLIDE 21

simple text formatting with cin and cout

  • see p58 - 62
slide-22
SLIDE 22

Functions in the Standard C++ Library

#include<cmath> Gives you the power of... fabs(x) sqrt(x) pow(x,y) log(x) and more!

slide-23
SLIDE 23

Functions (in brief)

const double PI = acos(-1.0); Are like “mini programs” your program can use Are abstractions Take input (usually) Return a value (usually)

slide-24
SLIDE 24

Homework

  • First read 2.8 (p 78 - 82)
  • Continue reading all of chapter 2
  • Complete assignment 03_aircraft