0136022537StartingC.pdf

(5094 KB) Pobierz
779405369.028.png
C++ Quick Reference
C++Data Types
Data Type Descr i p t i on
char Character
unsigned char Unsigned Character
int Integer
short int Short integer
short Same as short int
unsigned short int Unsigned short integer
unsigned short Same as unsigned short int
unsigned int Unsigned integer
unsigned Same as unsigned int
long int Long integer
long Same as long int
unsigned long int Unsigned long integer
unsigned long
Commonly Used Operators
Ass i gnmen t Operator s
= A ssignment
+= Combined addition/assignment
-= Combined subtraction/assignment
*= Combined multiplication/assignment
/= Combined division/assignment
%= Combined modulus/assignment
Ar i t hme t ic Operat or s
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (remainder)
Re la t i ona l Operator s
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal to
!= Not equal to
Log ical Operat or s
&& AND
|| OR
! NOT
Incremen t /Decremen t
++
Same as unsigned long int
Single precision floating point
float
double precision floating point
double
Long double precision floating
point
long double
Increment
Forms of the if Statement
Simp le i f
Decrement
--
Examp le
if (expression)
if(x<y)
statement;
x++;
Conditional Operator ?:
Form:
expression ? expression : expression
Examp le :
x=a<b?a:b;
The statement above works like:
if (a < b)
x=a;
else
x=b;
i f /e l se
Examp le
if (expression)
if(x<y)
statement;
x++;
else
else
statement;
x--;
i f /e l se i f
Examp le
if (expression)
if(x<y)
statement;
x++;
else if (expression)
else if (x < z)
The while Loop
Form:
statement;
x--;
Examp le :
while (expression)
while (x < 100)
else
else
statement;
cout << x++ << endl;
statement;
y++;
while (expression)
while (x < 100)
To conditionally-execute more than one
statement, enclose the statements in braces:
Form
{
{
statement;
cout << x << endl;
statement;
x++;
Examp le
}
}
if (expression)
if(x<y)
{
{
statement;
x++;
The do- while Loop
Form:
statement;
cout << x;
Examp le :
}
}
do
do
statement;
cout << x++ << endl;
while (expression);
while (x < 100);
Web Sites
For the StartingOutwithC++Series
aw.com/gaddisbooks
For Addison-Wesley Computing
aw.com/computing
do do
{ {
statement; cout << x << endl;
statement; x++;
} while (expression); } while (x < 100);
779405369.029.png
Chapter 1
Introduction to Flowcharting, p. 19
Designing a Program with Pseudocode, p. 19
Designing the Account Balance Program, p. 25
Predicting the Result of Problem 33, p. 25
Chapter 2
Using cout , p. 31
Variable Definitions, p. 37
Assignment Statements and Simple Math Expressions, p. 59
Solving the Restaurant Bill problem, p. 75
Chapter 3
Reading Input with cin , p. 79
Formatting Numbers with setprecision , p. 115
Writing Data to a File, p. 140
Reading Data from a File, p. 141
Solving the Stadium Seating Problem, p. 152
Chapter 4
The if Statement, p. 164
The if/else Statement, p. 177
The if/else if Statement, p. 187
Solving the Time Calculator Problem, p. 235
Chapter 5
The while Loop, p. 246
The for Loop, p. 262
Solving the Calories Burned Problem, p. 291
Chapter 6
Functions and Arguments, p. 309
Value-Returning Functions, p. 322
Solving the Markup Problem, p. 365
Chapter 7
Accessing Array Elements with a Loop, p. 378
Passing an Array to a Function, p. 401
Solving the Chips and Salsa Problem, p. 443
Chapter 8
The Binary Search, p. 454
The Selection Sort, p. 469
Solving the Charge Account Validation Modification Problem, p. 487
Chapter 9
Dynamically Allocating an Array, p. 519
Solving the getString Function Problem, p. 538
Chapter 10
Writing a C-String-Handling Function, p. 564
Using the string Class, p. 570
Solving the Backward String Problem, p. 584
(continued on next page)
779405369.030.png 779405369.031.png 779405369.001.png 779405369.002.png 779405369.003.png 779405369.004.png 779405369.005.png 779405369.006.png 779405369.007.png 779405369.008.png 779405369.009.png
LOCATION OF VIDEONOTES IN THE TEXT
(continued)
Chapter 11
Creating a Structure, p. 591
Passing a Structure to a Function, p. 610
Solving the Weather Statistics Problem, p. 644
Chapter 12
Passing File Stream Objects to Functions, p. 661
Working with Multiple Files, p. 673
Solving the File Encryption Filter Problem, p. 703
Chapter 13
Writing a Class, p. 712
Defining an Instance of a Class, p. 717
Solving the Employee Class Problem, p. 792
Chapter 14
Operator Overloading, p. 819
Class Aggregation, p. 848
Solving the NumDays Problem, p. 864
Chapter 15
Redefining a Base Class Function in a Derived Class, p. 893
Polymorphism, p. 903
Solving the Employee and ProductionWorker Classes Problem, p. 936
779405369.010.png 779405369.011.png 779405369.012.png 779405369.013.png 779405369.014.png 779405369.015.png 779405369.016.png 779405369.017.png 779405369.018.png 779405369.019.png 779405369.020.png
From Control Structures
through Objects
6th Edition Brief Version
Tony Gaddis
779405369.021.png 779405369.022.png 779405369.023.png 779405369.024.png 779405369.025.png 779405369.026.png 779405369.027.png
Zgłoś jeśli naruszono regulamin