|
1
|
|
|
2
|
- #include <iostream>
- using namespace std;
- int main() {
- statement1;
- …
- statement;
- return 0;
- }
|
|
3
|
|
|
4
|
- int someInt = 0;
- double someDub = 0.0;
- cout << someInt << endl;
- cout << someDub << endl;
- 0
- 0.0
|
|
5
|
- cin
- Sends data from the keyboard
- >> - extraction operator
- cin skips blanks and line breaks looking for data
- cout
- Sends output to the screen
- << - insertion operator
- \n – newline - used with literal text
- endl; - newline – used when \n can’t be used
|
|
6
|
- int someInt;
- double someDub;
- cout << someInt << endl;
- cout << someDub << endl;
|
|
7
|
|
|
8
|
|
|
9
|
- Names for a variables
- Part of the human readability
- Must start with alpha character or “_”
- Other characters must be characters must be alpha, numeric, or an “_”
- Case-sensitive
- Should be descriptive of the data they contain
- Course uses the following style
- Lowercase letter for the first word
- All subsequent words are capitalized
- Can’t be a C++ reserved word
|
|
10
|
- asm false sizeof
- auto float static
- bool for static_cast
- break friend struct
- case goto switch
- catch if template
- char inline this
- class int throw
- const long true
- const_cast mutable try
- continue namespace typedef
|
|
11
|
- int main() {
- int someInt = -35;
- double someDub = 1.25;
- return 0;
- }
|
|
12
|
- Literal Values
- someInt = 27;
- someDub = 33.33;
- Expressions
- someInt = 27+ 23;
- someDub = 5.55 * 1.0;
- Values of other Variables
- someInt = someOtherInt;
- someDub = someOtherDub;
- someInt = someInt2 + someInt3;
- someDub = someDub2 / someDub3;
|
|
13
|
- int someInt = 0, someOtherInt = 22, myInt = 87;
- double myDub = 2.2, otherDub = 4.55;
|
|
14
|
- int someInt = 0;
- int someOtherInt = 22;
- int myInt = 87;
- double myDub = 2.2;
- double otherDub = 4.55;
|
|
15
|
|
|
16
|
- Provided by iostream
- #include directive
- #include <iostream>
using namespace std;
|
|
17
|
- Enclosed in double quotes
- Uses the insertion operator
<<
- cout << “Hello Class\n”
- << “Do you prefer Coke
or Pespi?\n”
- << “What was the score
of the Laker “
- << “Heat Game?\n”;
|
|
18
|
- Text is defined in double quotes “TEXT”
- Special Characters
- “\n” – newline
- “\v” – vertical tab
- “\r” – carriage return
- “\a” – alert bell
- “\”” – double quote
- “\’” – single quote
- “\t” – tab
- “\b” – backspace
- “\\” – back slash
|
|
19
|
- “\n” is usually used when string literals are output
- cout << “I love this stuff!\nIsn’t this cool?\n”;
- cout << “The current lotto numbers are:\n”
- << lottoNums <<
endl;
- endl – sends a newline to the output stream and flushes the output
buffer.
|
|
20
|
- Assigning values from the keyboard
- cin >> numOfHomeOnMarket
- >> avgSellingPrice;
- >283 634000.99[ENTER]
- or
- >283[ENTER]
- >634000.33[ENTER]
|
|
21
|
- int
- 32 bits
- contains whole numbers
- Ranges from -2,147,483,648
to 2,147,483,647
- double
- 64 bits
- Fraction – usually around 14
decimal places
- Ranges from 10-308 to 10308
- Float
- 32 bits
- Fraction
- Ranges from 10-38 to 10 38
|
|
22
|
- double radius = 6.66666667;
- cout.setf(ios::fixed);
- cout.setf(ios::showpoint);
- cout.precision(2);
- cout << radius << endl;
|
|
23
|
- char
- 8 bits
- ASCII character
- Alphanumeric and
punctuation
- short
- 16 bits
- Ranges from -32767 to 32767
- long
- 32 bits
- Fraction
- Ranges from ~ -2 billion t0 ~ 2 billion
|
|
24
|
- bool
- 8 bits
- either true or false
- string
- Class type
- Defined in double quotes
- Must include the <string> library
- This is not a primitive type
|
|
25
|
- The following actions are possible but generally
not recommended!
- Values of type bool can be assigned to int
variables
- True is stored as 1 (any
positive integer)
- False is stored as 0
- Values of type int can be assigned to bool
variables
- Any non-zero integer is stored as true
- Zero is stored as false
|
|
26
|
- Declarations
- type nameOfTheVar;
- Assignments
- nameOfTheVar = someValue;
- One Statement
- type nameOfTheVar = someValue;
|
|
27
|
- Can be used for literal values and variables (in order of precedence)
- Parentheses ( )
- Multiplication *
- Division /
- Modulus %
- Addition +
- Subtraction –
- Same precedence as algebraic operations
- Please Excuse My Dear Aunt Sally
- Operands can be number or variable
- Calculating Right Circular
Cylinder ∏r2h
|
|
28
|
- If you were a computer, what would you give as a result for:
y = 2 * 5 * 5 + 3 * 5 + 7;
|
|
29
|
|
|
30
|
- foo = foo op bar
foo op= bar
|
|
31
|
- If both operands are type int
- Then the result is an int type
- 23 * 38 = integer result
- 23 / 38 = integer result
- If one of the operands is a double
- Then the result is a double type
- 23.56 * 38 = double result
- 23.56 / 38 = double result
- 5 / 2.0 = double result
|
|
32
|
- cout << "We can output "
- << "variables values\n";
- cout << "12/4 = " << 12/4 << endl;
- cout << "4+12 = " << 4+12 << endl;
- cout << "18%4 = " << 18%4 << endl;
|
|
33
|
|
|
34
|
- if (Boolean Expression) {
- statement1;
- statement2;
- ...
- }
- if (Boolean Expression) {
- }
|
|
35
|
|
|
36
|
|
|
37
|
- The “and” operator &&
- Allow multiple boolean expressions
- if ((fuel >= 30) && (milesTraveled > 5000)) {
- The “or” operator ||
- Allow multiple boolean expressions
- if ((fuel >= 30) || (milesTraveled
< 5000)) {
|
|
38
|
|
|
39
|
|
|
40
|
- Repetition statement (iteration statement)
- Set of statements is executed as long as the condition remains true
- Pseudocode
- While there are more items on my shopping list
- Purchase next item and cross it off my list
|
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
|
|
45
|
- Try to avoid this situation at all costs
- The end result is abnormal termination of your application
- THIS IS A BAD THING!!!
|
|
46
|
|
|
47
|
- Single line Comments
- // - single line comment
- // Name: Brad Rippe
- // File: Assignment23.cpp
- // Date: 1/21/07
- Multiple line Comments
- /* … */
- /*
- Name: Brad Rippe
- File: Assignment23.cpp
- Date: 1/21/07
- */
|
|
48
|
- Program cannot modify the variable
- Uses the keyword “const” in the declaration
- Known as the const modifier
- Identifier is capitalized
- Words are separated by “_”
- const double PIE = 3.14159;
- const string CON_DRIVER = “SQLServerDriver”;
|
|
49
|
|
|
50
|
|
|
51
|
- Course Web Site
- http://staffwww.fullcoll.edu/brippe/csci123
- Course Style Guide
- http://staffwww.fullcoll.edu/brippe/csci123/style.aspx
- Course Syllabus
- http://staffwww.fullcoll.edu/brippe/csci123/syllabus.aspx
- Course Schedule (tentative)
- http://staffwww.fullcoll.edu/brippe/csci123/schedule.aspx
|