Outline of Chapters 1 Through 7

Outline of Chapters 1 Through 7 - CS 170: High Level...

Info iconThis preview shows pages 1–4. 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 DocumentRight Arrow Icon

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

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

Unformatted text preview: CS 170: High Level Programming II Outline of chapters 17 in the text Jason Hanson DigiPen Institute of Technology * January 5, 2006 1 Naming conventions 1.1 Program file names 1. .hpp for interface (header) files 2. .cpp for implementation files 1.2 Included header files 1. No files extension; e.g., (a) #include <iostream> (b) #include <string> 2. C header files have c prepended; e.g., (a) #include <cstdlib> instead of #include <stdlib.h> (b) #include <cctype> instead of #include <ctype.h> * c 2006 DigiPen Institute of Technology. 1 2 Comments 1. C style comments: /* , */ pair, newline ignored /* blah, blah, blah */ 2. C++ style comments: // at beginning of comment, ends with newline // blah 3. Selfdocumenting code: descriptive variable and function names 4. Useful comments only, please 3 Banishment of macros 1. #include okay 2. #define okay only in header file code guard #ifndef CS170_HEADERFILE #define CS170_HEADERFILE ... #endif 3. const variables instead of #defined d values: #define TWO 2 // no const int TWO = 2; // yes 4. inline functions instead of macro functions: #define ABS(x) ((x)>=0) ? (x) : -(x)) // no inline int ABS(int x) { return (x>=0) ? x : -x; } // yes (templatized functions will be discussed later) 2 4 Namespaces (introduction) 1. Functions and variables can be declared to be within a namespace namespace <name> { // function prototypes // variables (const or otherwise) } 2. Scope resolution operator ( :: ) is used to access functions/variables within a namespace namespace fred { int f(int); float x; } namespace barney { int f(int); float x; } ... barney::x = fred::f(3); fred::x = barney::f(4); 3. Standard functions (and variables) are all within the standard names- pace , std #include <cmath> #include <cstdio> ... std::printf("%f",std::sqrt(3.4)); 4. Although macros can be declared inside a namespace, they are not part of any namespace (as if declared outside a namespace) namespace woof { #define WOOF 17 } ......
View Full Document

This note was uploaded on 04/18/2008 for the course CS 170 taught by Professor Hanson during the Spring '06 term at DigiPen Institute of Technology.

Page1 / 10

Outline of Chapters 1 Through 7 - CS 170: High Level...

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