• 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

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/59

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

59 Cards in this Set

  • Front
  • Back
Writing a program involves...
designing a strategy for solving a problem and then using a programming language to implement that strategy.
Every C++ function begins its execution from...
the main function.
Basic starting point when writing a program (header and footer):
#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main ( )
{

return 0
}
Variables are...
used to represent values that may be changed in the program.
Declaring a variable...
tells the compiler what type of data a variable can hold.
Identifiers are...
the names that identify elements such as variables and functions in a program.
3 rules of identifiers:
1 - must contain only letters, digits, and underscores.
2 - must start with a letter or underscore - never a digit.
3 - cannot be a reserved word
Syntax for reading an input from the console:
cin >>
What is the assignment operator?
=
What is the term for a variable declared in a function that has not been assigned a value? What happens if this occurs?
An uninitialized variable; its value is unpredictable.
A constant...
represents data that never changes.
conventional syntax for identifiers:
identifierSyntax
conventional syntax and keyword for constants:
CONSTANT; const
integer data types
int
short
long
byte
Unsigned integers are...
nonnegative integers
floating-point number types:
float
double
The % operator is for ...
integers only.
The -- operator (w. keyword) increments a variable by 1. The -- operator (w. keyword) decrements a variable by 1.
increment (++); decrement (--)
The double data type indicates...
that the values are double-precision decimal point values.
4 fundamental data types:
integers
floating point numbers
characters
Boolean types
tracing a program:
a method of reviewing how a program works.
What is the difference between sending the value of a variable and the name of that variable to the console?
The value is not enclosed in quotation marks, but the name of the value or variable is.
A single statement can be used to read multiple input.
Ex : to input three variables :

double num1, num2, num3;
cin >> num1 >> num2 >> num3;
.
syntax for declaring a variable:
datatype variableName;
A variable can be declared and -- in one step.
Ex : int count = 1
initialized
An expression represents...
a computation involving values, variables, and operators that evaluates to a value. Ex : int x = x - 1;
syntax for assigning a value to multiple variables:
i = j = k = l;
A constant must be...
declared and initialized in the same statement.
5 mathematical operators:
+ , - , / , x , %
A variable should be declared as unsigned when...
its value is always nonnegative.
For most applications, the -- numeric type is suitable for a decimal point number.
double
The -- function can be used to find the size of a type or a variable.
sizeof (can be used in conjunction with a type as in sizeof(int), or a variable as in sizeof(area))
A literal is...
a constant value that appears directly in a program.
Floating-point literals can be written in scientific notation (in the form of a x 10^b) with this syntax:
numberEpower, or numberepower
When both operands of a division are integers, the result of the division is the -- and the -- part is --.
quotient; fractional; truncated
The % operator is known as...
the modulo
The modulo works only with -- and yields the --
integer operands; remainder after division.
An exponent operation can be performed using...
the pow(a, b) function , found in the cmath library.
Some C++ compilers require that either a or b in pow(a, b) be...
a decimal value.
The -- function can be invoked to return the current time.
time(0), found in the ctime header file, which returns the current time in seconds elapsed since the UNIX epoch. This can be further developed using the modulo to return the current time.
An augmented assignment operator...
allows you to combine assignment and numerical (math) operators.

Ex : The following statements are equivalent. The second uses an addition assignment operator.

count = count + 8
count += 8

The same syntax applies to the remaining 4 numerical operators.
The syntax for increment and decrement operators:
int i = 3;
i++; // i becomes 4
i-- // i becomes 2
Floating-point numbers can be converted into integers using...
explicit casting
When assigning a floating-point value to an integer, the fractional part --
is truncated, not rounded.
A casting value...
allows you to convert a value from one type to another.
The syntax for explicit casting of a variable:
static_cast<type>(value) where value is a variable, a literal, or an expression and type is the type you wish to convert the value to.
"Widening a type" :
Casting a variable of a type with a small range to a variable of a type with a larger range.
"Narrowing a type" :
Casting a variable of a type with a large range to a variable of a type with a small range -- May cause loss of precision.
Example of static_cast:

double purchaseAmount;
cin >> purchaseAmount;
double tax = purchaseAmount * 0.06;
cout << "Sales tax is" << static_cast<int>(tax *100) / 100.0;

if user entered 197.55 for purchaseAmount...
tax is evaluated at 11.853
tax * 100 is 1185.3
static_cast<int>(tax * 100) is 1185
static_cast<int> (tax * 100) / 100.0 is 11.85
.
7 good programming habits
Analyze problem
develop algorithm (design)
write code for program (implement)
compile code
run program
test results
document the program
IPO
input, process and output; the essence of system analysis.
5 common elementary programming errors:
Undeclared or uninitialized variables
Integer overflow (when a variable is assigned a value too large for the data type specified)
Round-off errors (the diff. between the calculated approximation of a number and its exact mathematical value - calculations involving f-p #s are not stored with complete accuracy.)
Unintended integer division (division between integers needs to have one operand entered with a decimal point to reflect precise value)
Forgetting header files (ctime, cmath, iostream etc)
Compiler errors
are usually syntax errors or omissions
character data type
char, initialized as in: char firstLetter = 'A'
a character literal is enclosed in single quotation marks
ASCII code table
computers use unique numeric code to represent each character. each printable character is assigned a different integer code.
the operator prints in the direction of -
data flow
example - formatting double and float to limit number of digits after decimal point
<< static_cast<int>(tax * 100) / 100.0;

this will drop decimal amounts after two decimals that we want. change multiplier and divisor to change number of places required.
when our program compiles correctly, it means that it is free of -
syntax errors
programs that do not run correctly contain -
runtime errors (cause to terminate abnormally) or logic errors (to produce incorrect results). we discover them by testing the program.