---LECTURE SHARE---
==LINKS WILL BE PUBLISHED SOON==
- Chapter 1
- Chapter 2
- Chapter 5
- Chapter 8
- Chapter 9
- Chapter 10
- Chapter 11
- Chapter 14
- Chapter 17
12:45 PM | 0 Comments
9:30 PM | 0 Comments
9:28 PM | 0 Comments
1 2 |
|
1 2 3 4 5 |
|
1 2 3 4 |
|
1 2 3 4 5 6 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
| Enter the starting number > 8 8, 7, 6, 5, 4, 3, 2, 1, FIRE! |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
| Enter number (0 to end): 12345 You entered: 12345 Enter number (0 to end): 160277 You entered: 160277 Enter number (0 to end): 0 You entered: 0 |
1 2 3 4 5 6 7 8 9 10 11 |
| 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, FIRE! |
1 2 3 4 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
| 10, 9, 8, 7, 6, 5, 4, 3, countdown aborted! |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
| 10, 9, 8, 7, 6, 4, 3, 2, 1, FIRE! |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
| 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, FIRE! |
|
switch (expression) { case constant1: group of statements 1; break; case constant2: group of statements 2; break; . . . default: default group of statements }
switch example | if-else equivalent |
---|---|
switch (x) { case 1: cout << "x is 1"; break; case 2: cout << "x is 2"; break; default: cout << "value of x unknown"; } | if (x == 1) { cout << "x is 1"; } else if (x == 2) { cout << "x is 2"; } else { cout << "value of x unknown"; } |
1 2 3 4 5 6 7 8 9 |
|
1 2 3 |
|
1 2 |
|
|
|
|
1 2 |
|
1 2 |
|
1 2 |
|
1 2 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
| Please enter an integer value: 702 The value you entered is 702 and its double is 1404. |
|
1 2 |
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
| What's your name? Juan Souliï¿Â½ Hello Juan Souliï¿Â½. What is your favorite team? The Isotopes I like The Isotopes too! |
1 2 3 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
| Enter price: 22.25 Enter quantity: 7 Total price: 155.75 |
6:22 AM | 0 Comments
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
| ==>a:4 b:7 |
|
1 2 |
|
|
+ | addition |
- | subtraction |
* | multiplication |
/ | division |
% | modulo |
|
expression | is equivalent to |
---|---|
value += increase; | value = value + increase; |
a -= 5; | a = a - 5; |
a /= b; | a = a / b; |
price *= units + 1; | price = price * (units + 1); |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
| ==>5 |
1 2 3 |
|
Example 1 | Example 2 |
---|---|
B=3; A=++B; // A contains 4, B contains 4 | B=3; A=B++; // A contains 3, B contains 4 |
== | Equal to |
!= | Not equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
1 2 3 4 5 |
|
1 2 3 4 |
|
1 2 3 4 |
|
a | b | a && b |
---|---|---|
true | true | true |
true | false | false |
false | true | false |
false | false | false |
a | b | a || b |
---|---|---|
true | true | true |
true | false | true |
false | true | true |
false | false | false |
1 2 |
|
1 2 3 4 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
| ==>7 |
|
operator | asm equivalent | description |
---|---|---|
& | AND | Bitwise AND |
| | OR | Bitwise Inclusive OR |
^ | XOR | Bitwise Exclusive OR |
~ | NOT | Unary complement (bit inversion) |
<< | SHL | Shift Left |
>> | SHR | Shift Right |
1 2 3 |
|
|
|
|
1 2 |
|
Level | Operator | Description | Grouping |
---|---|---|---|
1 | :: | scope | Left-to-right |
2 | () [] . -> ++ -- dynamic_cast static_cast reinterpret_cast const_cast typeid | postfix | Left-to-right |
3 | ++ -- ~ ! sizeof new delete | unary (prefix) | Right-to-left |
* & | indirection and reference (pointers) | ||
+ - | unary sign operator | ||
4 | (type) | type casting | Right-to-left |
5 | .* ->* | pointer-to-member | Left-to-right |
6 | * / % | multiplicative | Left-to-right |
7 | + - | additive | Left-to-right |
8 | << >> | shift | Left-to-right |
9 | < > <= >= | relational | Left-to-right |
10 | == != | equality | Left-to-right |
11 | & | bitwise AND | Left-to-right |
12 | ^ | bitwise XOR | Left-to-right |
13 | | | bitwise OR | Left-to-right |
14 | && | logical AND | Left-to-right |
15 | || | logical OR | Left-to-right |
16 | ?: | conditional | Right-to-left |
17 | = *= /= %= += -= >>= <<= &= ^= |= | assignment | Right-to-left |
18 | , | comma | Left-to-right |
|
|
|
6:19 AM | 0 Comments
|
5
in this piece of code was a literal constant.1 2 3 |
|
"
) nor any special character. There is no doubt that it is a constant: whenever we write 1776
in a program, we will be referring to the value 1776.0
(a zero character). And in order to express a hexadecimal number we have to precede it with the characters 0x
(zero, x). For example, the following literal constants are all equivalent to each other: 1 2 3 |
|
1 2 3 4 |
|
e
character (that expresses "by ten at the Xth height", where X is an integer value that follows the e
character), or both a decimal point and an e
character:1 2 3 4 |
|
f
or l
suffixes respectively:1 2 |
|
e
, f
, l
) can be written using either lower or uppercase letters without any difference in their meanings.1 2 3 4 |
|
'
) and to express a string (which generally consists of more than one character) we enclose it between double quotes ("
). 1 2 |
|
x
alone would refer to a variable whose identifier is x
, whereas 'x'
(enclosed within single quotation marks) would refer to the character constant 'x'.\n
) or tab (\t
). All of them are preceded by a backslash (\
). Here you have a list of some of such escape codes: \n | newline |
\r | carriage return |
\t | tab |
\v | vertical tab |
\b | backspace |
\f | form feed (page feed) |
\a | alert (beep) |
\' | single quote (') |
\" | double quote (") |
\? | question mark (?) |
\\ | backslash (\) |
1 2 3 4 |
|
\
) followed by the ASCII code expressed as an octal (base-8) or hexadecimal (base-16) number. In the first case (octal) the digits must immediately follow the backslash (for example \23
or \40
), in the second case (hexadecimal), an x
character must be written before the digits themselves (for example \x20
or \x4A
).\
) at the end of each unfinished line.1 2 |
|
|
L
prefix:
|
true
and false
.#define
preprocessor directive. Its format is:#define identifier value
1 2 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
| ===>31.4159 |
#define
directives is to literally replace any occurrence of their identifier (in the previous example, these were PI and NEWLINE) by the code to which they have been defined (3.14159
and '\n'
respectively).#define
directive is not a C++ statement but a directive for the preprocessor; therefore it assumes the entire line as the directive and does not require a semicolon (;
) at its end. If you append a semicolon character (;
) at the end, it will also be appended in all occurrences of the identifier within the body of the program that the preprocessor replaces.const
prefix you can declare constants with a specific type in the same way as you would do with a variable: 1 2 |
|
pathwidth
and tabulator
are two typed constants. They are treated just like regular variables except that their values cannot be modified after their definition.
1 2 3 4 |
|
a
, b
and result
, but we could have called the variables any names we wanted to invent, as long as they were valid identifiers._
). Neither spaces nor punctuation marks or symbols can be part of an identifier. Only letters, digits and single underscore characters are valid. In addition, variable identifiers always have to begin with a letter. They can also begin with an underline character (_
), but in some cases these may be reserved for compiler specific keywords or external identifiers, as well as identifiers containing two successive underscore characters anywhere. In no case they can begin with a digit.
asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while
and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq
RESULT
variable is not the same as the result
variable or the Result
variable. These are three different variable identifiers.Name | Description | Size* | Range* |
---|---|---|---|
char | Character or small integer. | 1byte | signed: -128 to 127 unsigned: 0 to 255 |
short int ( short ) | Short Integer. | 2bytes | signed: -32768 to 32767 unsigned: 0 to 65535 |
int | Integer. | 4bytes | signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 |
long int ( long ) | Long integer. | 4bytes | signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 |
bool | Boolean value. It can take one of two values: true or false. | 1byte | true or false |
float | Floating point number. | 4bytes | +/- 3.4e +/- 38 (~7 digits) |
double | Double precision floating point number. | 8bytes | +/- 1.7e +/- 308 (~15 digits) |
long double | Long double precision floating point number. | 8bytes | +/- 1.7e +/- 308 (~15 digits) |
wchar_t | Wide character. | 2 or 4 bytes | 1 wide character |
int
has the natural size suggested by the system architecture (one "word") and the four integer types char
, short
, int
and long
must each one be at least as large as the one preceding it, with char
being always one byte in size. The same applies to the floating point types float
, double
and long double
, where each one must provide at least as much precision as the preceding one.1 2 |
|
|
1 2 3 |
|
1 2 |
|
|
signed
)signed
or unsigned
if you intend to store numerical values in a char-sized variable.short
and long
can be used alone as type specifiers. In this case, they refer to their respective integer fundamental types: short
is equivalent to short int
and long
is equivalent to long int
. The following two variable declarations are equivalent:1 2 |
|
signed
and unsigned
may also be used as standalone type specifiers, meaning the same as signed int
and unsigned int
respectively. The following two declarations are equivalent: 1 2 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
| 4 |
{}
) where they are declared. For example, if they are declared at the beginning of the body of a function (like in function main) their scope is between its declaration point and the end of that function. In the example above, this means that if another function existed in addition to main, the local variables declared in main could not be accessed from the other function and vice versa.type identifier = initial_value ;
|
()
): type identifier (initial_value) ;
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
| 6 |
string
class. This is not a fundamental type, but it behaves in a similar way as fundamental types do in its most basic usage.<string>
and have access to the std
namespace (which we already had in all our previous programs thanks to the using namespace
statement).1 2 3 4 5 6 7 8 9 10 11 |
| This is a string |
1 2 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
| This is the initial string content This is a different string content |
We help you to get lecture sheets from various universities....
Copyright © 2008 Lecture Share. All Rights Reserved.
Design by Padd IT Solutions - Blogger Notes Template by Blogger Templates