• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key

image

Play button

image

Play button

image

Progress

1/33

Click to flip

33 Cards in this Set

  • Front
  • Back
What are some historical points about C++?
Designed and implemented byBjarne Stroustrup. A super set of C. Originally called C with classes (1980).
C++ is designed to...
...be a statically typed, general-purpose language that is as efficient and portable as C, support multiple programming styles, function without a sophisticated programming environment, and a zero-overhead principle
Describe the structure of a program
Comments
preprocessor directives
using directives
Block of code
{
comments
statements
}
Here is an example of a program
/* Simple C++ Program */

/* This program computes the */
/* distance between two points. */
#include <iostream> // Required for cout, endl.
#include <cmath> // Required for sqrt()
using namespace std;
int main()
{
// Declare and initialize objects.
double x1(1), y1(5), x2(4), y2(7), side1, side2, distance;
// Compute sides of a right triangle.
side1 = x2 - x1;
side2 = y2 - y1;
distance = sqrt(side1*side1 + side2*side2);
// Print distance.
cout << "The distance between the two points is "
<< distance << endl;
// Exit program.
return 0;
}
What are comments?
Comments help people read programs, but are ignored by the compiler.
Comments are optional.
In C++ there are two types of comments.
Line comments begin with // and continue for the rest of the line.
Delimited comments begin with /* and end with */
What are preprocessor directives?
Provide instructions to the compiler that are performed before the program is compiled.
Begin with a #
Example:
#include <iostream>
The #include directive instructs the compiler to include statements from the file iostream.
What is the using directive?
The using directive instructs the compiler to use files defined a specified namespace.
Example:
using namespace std;
std is the name of the Standard C++ namespace.
Otherwise you need to write std::cin, std::cout, std::endl
What is a C fashion header file?
Some old compilers do not support namespace.
Omit using directive
Instead write
#include <iostream.h>
#include <math.h>
(include a “.h”)
Header file: includes declarations of function, variables, classes, etc.
Source codes are in another file (.c .cc .cpp).
Separate interface from implementation
What is a block of code?
A block of code is defined by a set of curly braces {…}. Every C++ problem solution contains exactly one function named main(). C++ program solutions always begin execution in main()
What is the main function?
The main function contains two types of commands: declarations and statements.
Indentation and blank lines are not required, but they are needed for readability.
Note that all C++ statements are required to end with a semicolon.
The statement return(0) returns the control to the operating system.
What are constants and variables?
Constants and variables represent memory locations that we reference in our program solutions.
Constants are objects that store specific data that can not be modified.
10 is an integer constant
4.5 is a floating point constant
"Side1" is a string constant
'a' is a character constant
Variables are memory locations that store values that can be modified.
double x1(1.0), x2(4.5), side1;
side1 = x2 - x1;
x1, x2 and side1 are examples of variables that can be modified.
What are symbolic constants?
A symbolic constant is defined in a declaration statement using the modifier const.
Ex. const double pi(3.14); or #define pi 3.14;
A symbolic constant allocates memory for an object that can not be modified during execution of the program. Any attempt to modify a constant will be flagged as a syntax error by the compiler.
A symbolic constant must be initialized in the declaration statement.
Note: the cmath (math.h) library includes many mathematical constants.
What are memory snapshots?
Memory snapshot: shows the content of a memory location at a specified point in the execution of the program.
Variables uninitialized will have values unpredictable (another program can take that memory space and insert any values into it).
int x, y (1), z;
z = x + y;
z = ?
What are some common C++ data types?
Keyword, Example of a constant
bool, true
char, '5'
int, 25
double, 25.0
string, "hello" //#include<string>
What are identifiers?
Identifiers are used to name objects in C++.
Rules for selecting valid identifiers:
Identifier must begin with a letter or underscore _
Identifiers consists of alphanumeric characters and underscore character only.
An identifier cannot be a reserved word.
Only the first 31 characters of an identifier are used to distinguish it from other identifiers.
C++ is case sensitive. Thus, Side1 and side1 are unique identifiers that represent different objects.
What are declarations?
A type declaration statement defines new identifiers and allocates memory (type specifier).
An initial value may be assigned to a memory location at the time an identifier is defined.
Syntax: [modifier] data_type identifier_list;
Examples:
double length( 20.75), width(11.5), volume;
int numberOfFeetInYard(3);
const int MIN_SIZE = 0;
What is an assignment statement?
The assignment operator (=) is used in C++ to assign a value to a memory location.
The assignment statement:
x1 = 1.0;
assigns the value 1.0 to the variable x1.
Thus, the value 1.0 is stored in the memory location associated with the identifier x1.
Example
int x, y, z;
x=y=0;
z=2;
What is scientific notation?
Floating point: can present both integer and non-integer values, such as 2.5, -0.004.
A floating point value expressed in scientific notation: expressed as a mantissa times a power of 10.
Mantissa part must be between 1.0 and 10.0.
Exponential notation:
256.1 = 2.561 * 10^2
-0.004 = -4.0e-3
Are there restrictions on data types?
Yes, such as short, int, long, float, double, and long double.
What are the main arithmetic operators?
Addition +
Subtraction -
Multiplication *
Division /
Modulus %
Modulus returns remainder of division between two integers
Example
5 % 2 returns a value of 1
Note: 5/2 returns 2 but 5.0/2.0 returns 2.5
What is the cast operator?
The cast operator is a unary operator that requests that the value of the operand be cast, or changed, to a new type for the next computation. The type of the operand is not affected.
Example:
int count(10), sum(55);
double average;
average = (double)sum/count;
What is the precedence of arithmetic and assignment operators?
1. Parentheses, innermost first
2. Unary operators (+ - ++ __), right to left
3. Binary operators (* / %), left to right
4. Binary operators (+ -), left to right
5. Assignment operators (= += -= *= /= %=), right to left
Describe overflow and underflow
Overflow: answer too large to store
Example: using 16 bits for integers
result = 32000 +532;
Exponent overflow: answer’s exponent is too large
Example: using float, with exponent range –38 to 38
result = 3.25e28 * 1.0e15;
Exponent underflow: answer’s exponent too small
Example: using float, with exponent range –38 to 38
result = 3.25e-28 *1.0e-15;
What are the increment and decrement operators?
ncrement Operator ++
post increment x++;
pre increment ++x;
Decrement Operator - -
post decrement x- -;
pre decrement - -x;
Assume k = 5 prior to executing the statement.
m= ++k; both m and k become 6
n = k- -; n becomes 5 and k becomes 4
w = ++x –y;
w = x++ - y;
What are some abbreviated assignment operators?
operator example equivalent statement
+= x+=2; x=x+2;
-= x-=2; x=x-2;
*= x*=y; x=x*y;
/= x/=y; x=x/y;
%= x%=y; x=x%y;
What is the standard input and output stream?
cin is an istream object defined in the header file iostream
cin is defined to stream data from standard input (the keyboard)
We use the input operator >> with cin to assign values to variables
General Form: cin >> identifier >> identifier;

cout is an ostream object defined in the header file iostream
cout is defined to stream data from standard input (the keyboard)
We use the input operator << with cout to assign values to variables
General Form: cout >> identifier >> identifier;
What are some Manipulators and Methods for i/o stream?
endl – places a newline character in the output buffer and flushes the buffer.
setf() and unsetf() to set the following modes
ios::showpoint display the decimal point
ios::fixed fixed decimal notation
ios::scientific scientific notation
ios::right right justification
ios::left left justification
What are the <cmath> trigonometric functions?
cos Compute cosine
sin Compute sine
tan Compute tangent
acos Compute arc cosine
asin Compute arc sine
atan Compute arc tangent
atan2 Compute arc tangent with two parameters
What are the <cmath> hyperbolic functions?
cosh Compute hyperbolic cosine
sinh Compute hyperbolic sine
tanh Compute hyperbolic tangent
What are the <cmath> exponential and logarithmic functions?
exp Compute exponential function
frexp Get significand and exponent
ldexp Generate number from significand and exponent
log Compute natural logarithm
log10 Compute common logarithm
modf Break into fractional and integral parts
What are the <cmath> power functions?
pow Raise to power
sqrt Compute square root
What are the <cmath> rounding, absolute value and remainder functions?
ceil Round up value
fabs Compute absolute value
floor Round down value
fmod Compute remainder of division
What are some common <cctype> functions?
isalnum Check if character is alphanumeric
isalpha Check if character is alphabetic)
iscntrl Check if character is a control character
isdigit Check if character is decimal digit
isgraph Check if character has graphical representation using locale
islower Check if character is lowercase letter
isprint Check if character is printable
ispunct Check if character is a punctuation character
isspace Check if character is a white-space
isupper Check if character is uppercase letter
isxdigit Check if character is hexadecimal digit