Comp Sci Ch 1, Ch 2 Flashcards
What is a program?
a set of instructions executing at one time
What is a variable?
holds a value, stores it in memory
What is an algorithm?
a sequence of instructions that solve a problem
What are the 1st two lines of code?
include <isostream></isostream>
using namespace std;
What outputs onto screen?
cout «
What gets input?
cin»_space;
What does an int hold?
an integer value
What starts the main function?
main () and everything inside {}
What ends a program?
return 0;
What starts a new line?
endl; or /n
What is a single line comment?
//text
What is a multi line comment?
/* text */
/*text
*text
*text */
What makes a program more readble?
whitespace
What is a syntax error?
violates programming language
How should you fix errors?
one at a time and compile
What is a logic error?
a bug, your sequencing or math is wrong
What is a bit?
a switch, binary digits, 0 and 1
What is a ciruit?
a connection of switches
What is a memory?
instructions and data stored in 0s and 1s in thousands of addressed locations
What is a processor?
executes instructions of program
What are machine instructions?
instructions represented in 0s and 1s
What is an executable program?
sequence of machine instructions
What are assembly language instructions?
translate high level (words and numbers) language to executable programs
What is moore’s law?
the doubling of integrated circuits capacity every 18 months
How many bits in a byte?
8 bits = 1 byte
Binary has a power of…
2
What does an assignment do?
assigns a variable a value
What are the rules for identifiers/variable names?
-sequence of letters, underscores, and digits
- start with letter or underscore
- no spaces or special characters
-case sensitive
What is a reserved word?
key word that is part of the language and cannot be used as an identifier
What is an expression?
individual item or combination that evaluates to a value
What is a literal?
a specific value in code
What is a floating point number?
- a real number with a decimal point
-measures measurements and fractions of countable items
What are the ways to force a computer to see a data type differently?
- change literal data type
- multiply by literal of that data type (times 1.0 goes first)
3.force it into a variable of that data type - use type casting
What happens when you divide a floating point number by 0?
NaN, not a number
What is data cast?
changing the number of places after the decimal
cout «_space;fixed «_space;setprecision(2) «_space;myFloat;
How do you initialize a constant variable?
const type NAME_OF_VAR;
What is used to enable math functions?
include <cmath></cmath>
What is an argument?
any function input values appearing within (), separated by a comma if more than one
What is the function of square root of x?
sqrt(x)
Function of a float absolute value and abosolute value
fabs(x) and abs(s)
Power function of x to the power of y
pow(x,y)
Round up and round down functions
ceil and floor
What happens with integer division?
does not generate a fraction and throws out remainder
What happens with floating point number and integer division?
floating point division does not throw out remainder like integer division
The second operand of / and % must never be..
0
What does Modulo do?
returns the remainder of the
Modulo cannot handle..
doubles
How do you shift a value right?
dividing by a power of 10, the number of 0s is the places moved
How do you get the rightmost digits?
% by a power of 10, the number of 0s is how many digits
What is type casting?
converting a value of a type to another
static_cast<type>(expression)</type>
to use
newVar = that above
then use newVar in expressions
or use directly when couting
What does char store?
a single character in single quotes
How is a character internally stored?
in ASCII, a number
A’s number and a’s ASCII number are..
65 and 97
What are escape sequences?
and what are the 5
used when special character would be read differently
\n - new line
\t- tab
' - single quote
" - double quotes
\ - backslash
-are used inside “ “
What does string hold?
A collection of characters surround by “
What should be enable to use strings?
include <string></string>
With whitespace input you need…
multiple cin»_space;
To get a whole line of input…
getline(cin, stringVar)
What are the 8 bit values?
128, 64, 32, 16, 8, 4, 2, 1
from 2 to the power of 0 increasing the power by 1 each time
What is overflow?
a value type holding more than its maximum value
What is unsigned?
use when we know a value will always be positive
prepend unsigned to type and varName
When debugging…
fix one thing at a time and compile
computer reads from left to right
comment out
insert cout «