C By Discovery (4th Edition)

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Intermediate Programming CSE 1320 Lecture 19 Chapter 12: 12.1-12.3 Introduction to C++ • General purpose language – Developed in early 1980’s – Bjarne Stroustrup • Goals – Retain power and flexibility of C • C is almost a subset of C++ (should compile) – Support Object Oriented Programming • Stronger type checking – More compile-time errors – Less run-time errors C++ Stream Output // Inline commenting style #include < iostream.h > int main () { cout << “CSE1320\n”; return 0; } type ostream Operator overloading insertion operator (ostream << display;) integer bitwise shift to the left (intval << nbits;) Displayed when program ends, buffer is full, program prepares for input, line buffering ‘\n’. #include <iostream.h> int main() { int width, height; cout << “Area of a Rectangle\n” << “--------------------------\n\n”; cout << “Enter the height: “; cin >> height; cout << “Enter the width: “; cin >> width; cout << “The area is “ << height*width << “\n”; return 0; } C++ Stream Input istream extraction operator cin >> height; Fundamental Types • Integer types – Signed • signed char • char • short • int • long – Unsigned • unsigned char • unsigned short • unsigned int • unsigned long • Floating point types – float – double – long double • bool: true (non-zero) and false (0) • Used for types of expressions – Conditionals: if and if-else statements – Loops • while loop • do-while loop • for statement test – any place where true and false Type bool 2 • inline as first token in function header (very short and no loops-control statements) + Speed up execution (avoid control transfer) + Use like macros, but safer since work exactly like functions (parameter passing) + Code is expanded at the point of the function call- Increase size of object code- Harder to debug Inline Functions #include <iostream.h>#include <iostream....
View Full Document

{[ snackBarMessage ]}

Page1 / 4

Lecture19 - 1 Intermediate Programming CSE 1320 Lecture 19...

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

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