csci261c e
play

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


  1. CSCI261C/E Lecture 3: C++ Fundamentals (continued) August 31, 2011

  2. ?

  3. Alan Turing 1912 - 1954 “Turing Machine” aka “Universal Machine” the man himself bombe code-breaking machine

  4. Review • C++ program structure • Preprocessing directives • main() • {code blocks} • Variable declarations & types (intro) • I/O ( cin, cout )

  5. Comments // a one line comment /* a multi- line comment */ /* omg! */

  6. Semicolon; ...is like a period at the end of a sentence. EXCEPT for preprocessing directives (they are special) #include<somelibrary> dude, no semicolon!

  7. C++ is Case-Sensitive double Porsche; double porsche; double pOrScHe; These are three different variables!

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

  9. Syntax Notation Guide [ this is optional ]

  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

  11. Modifiers const (for now)

  12. Types • short, int, long • float, double, long double • bool • char • string (#include<string>)

  13. An Abrupt Introduction to Classes and Objects

  14. ...to be continued

  15. Symbolic Constant const double PI = 3.14159; • it’s what you think it is (just a constant) • cannot change its value • for style, use ALL CAPS • often declared outside of main()

  16. Operators • think algebra • =, +, -, *, /, % • assignment (=) is not equality (==)! • follow precedence rules (p52)

  17. Increment & Decrement (with style) int x; x = 1; x++; x = x + 1;

  18. Order Matters int x, y; int x, y; x = 10; x = 10; y = ++x - 3; y = x++ - 3; x = x + 1; y = x - 3; y = x - 3; x = x + 1;

  19. Other “Tricks” • multiple assignment (p56)

  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’

  21. simple text formatting with cin and cout • see p58 - 62

  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!

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

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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend