• 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/92

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;

92 Cards in this Set

  • Front
  • Back
  • 3rd side (hint)
Bool has what possible values?
True or False
Boolean is logical, checking if something is in one of two conditions
Int is a simple data type for what?
Integers up to 2.1 billion or so, plus to negative
Integers are numbers without commas or decimal points. Use FLOAT or double for decimal (fractional) numbers
Char is a simple data type for what?
Char is used to store characters. Single quotes enclose each character. A space is a character
Char is short for what?
Float is a simple data type for what?
Float represents any real number from -3.48E+38 to 3.48E+38.
Float has 6 or 7 max significant digits.
Floating point hints at a _____ point in a number.
Double is a simple data type for what?
Double represents any real number -1.7E+308 to 1.7E+308. Double has 15 max significiant digits
Double is a larger version of float.
How is static_cast declared?
static_cast<datatype>(expression)
ex: static_cast<int>(7.9) evaluates to 7
static_cast converts the data to the type in <>
how is const data type declared?
const dataType identifier = value;
ex: const double NO_OF_DAYS;
const is used to hold a value unchanged in memory
How is a variable declared?
type variable = expression;

ex: int count = 0;
ex: int num1, num2;
variables are named memory locations, and are often initialized when created. They end with a ;
How do you increment or decrement a number?
++ increments a number
-- decrements a number
ex: count++ increases count by 1
two signs do it in both cases- before or after the variable give different results.
What is a preprocessor directive?
#include<headerFileName>
ex: #include<iostream>
think about the # at the start of the source code
What are compound assignment statements?
+=, -=, *=, /=, %= are compound assignments.
x *= y; is equal to x = x * y;
These combine arithmatic operators in code shorthand.
How is cin>> used?
cin >> variable >> variable..;
ex: cin >> age >> gender;
remember the carrets assign input to a variable
How is cin.get used?
cin.get(varChar);
ex: cin.get(number1);
get stores the next char, includes spaces, into the (variable)
get is a predefined function that loads characters. It uses a dot operator.
How is cin.ignore used?
cin.ignore(intExp, chExp)
ex: cin.ignore(25, 'x') ignores the next 25 characters, or x, whichever comes first
ignore is a predefined function that ignores the next x characters or until y occurs. It uses a dot operator
How is putback used?
istreamVar.putback(ch);
ex: cin.putback(ch); this puts the last character extracted by get back into the input stream
putback is a predefined function that puts the last character extracted by get back into the stream. It uses a dot operator
How is peek used?
ch = istreamVar.peek();
ex: ch = cin.peek();
this stores the value of input stream into a variable, but doesn't remove it from the stream.
peek is a predefined function that gets a value from the input stream, but doesn't change the input stream. It uses a dot operator and empty parens.
How is the clear function used?
istreamVar.clear();
ex: cin.clear(); This restores the input stream. Often used with ignore to clear garbage and restore input stream
clear is a predefined function that restores the input stream. its often used with another function. It uses a dot operator
How is setprecision used?
setprecision(n);
ex: setprecision(4); sets decimal places to 4 places
must include #include<iomanip>
setprecision is a predefined function that sets the number of decimal places
How is fixed used?
fixed; sets decimal output to fixed decimal output. Used with setprecision
ex: cout << fixed;
must include #include<iomanip>
fixed is a output manipulator that is part of an include library.
How is showpoint used?
ex: cout << showpoint;
This causes zeros to show after a decimal point
must include #include<iomanip>
showpoint makes zeros appear.
How is setw used?
ex: cout << setw(2); sets column width to 2 spaces.
must include #include<iomanip>
used to set column width. Must include a library to work.
How is setfill used?
ex: cout << setfill(ch); fills spaces with the (character).
must include #include<iomanip>
fills spaces with a selected character. Must include a library to work.
How is left, right used?
ex: cout << left; causes left align
ex: cout << right; causes right align
must include #include<iomanip>
used to left, right align,
must include library
How does getline work?
getline(istreamVar, strVar);
ex: getline(cin, myString);
used to put line into string variable, inlcuding spaces, till end of line
used to get a line, including spaces, into a variable. Uses dot operator
How does fstream work?
1) #include<fstream>
2)ifstream inData; //declare filestream var
ofstream outData; // delcare filestream var
3) fileStreamVar.open(sourceName); //open file
ex: inData.open("c:\\prog.dat");
4) inData >> payRate; (example)// input into var
outData << " Pay total is " << pay << endl; example) // stores output in output file prog.dat
5) inData.close(); // closes input file
outData.close(); // closes output file
five step process, includes header file, variables, tie to source and open, output, close
What is the difference between = and ==?
a = b assigns value b to variable a
a == b determines if b is equal to a
One places a value in a variable, one checks for equality...
Name six relational operators.
== is equal
! != is not equal
< is less than
<= is less than or equal
> is greater than
>= is greater than or equal
straight from mathmatics except for ascii, and equals is ==
What are && and ||?
&& is the AND logical operator
|| is the OR logical operator
Logic operators come from and, or
How is the if else statement used?
if (expression)
{ statement 1;}
else
{ statement 2;}
if something happens, do this
else, do this
What is short circuit evaluation?
C++ evaluates logical exp from left to right, and stops as soon as the expression is evaluated.
ex: age >= 21 || x == 5 stops if first exp is true, witout eval second exp.
used with logic evals, it stops when exp is resolved
How is a switch structure used?
switch(expression)
{
case value1:
statement 1
break;
case vaue 2:
statement2
break; ...
default:
}
}
swithh uses cases, compares to values, or does statements.
how is a while loop used?
while(expression)
{
statement;
}
while this is true, do this
What is a counter controlled while loop?
counter = 0;
while (counter < N)
{ counter++;}
// increments counter value N times
uses a counter variable to increment X times
What is a sentinel controlled while loop?
cin >> var; // input var, initialized
while (var != sentinel)
{ cin >> var;} // check each input until var = sentinel
check each variable until it equals a sentinel value
What is a flag controlled while loop?
found = false; // ini control var
while( !found)
{ if(expression)
found = true; // update value if true
}
compares var to expression while flag is not equal
What is an EOF while loop?
infile.get(ch);>> var // initialize loop control variable
while (!infile.eof()) // while there is input
{ cout << ch;
infile.get(ch);
} // update loop var
go till the end of file is reached
How do you use a FOR loop?
for(initial statement; loop condition, update statement)\
{ statement}
ex:
for(i = 0; i < 10; i++)
cout << i << endl;
shortcut to counter controlled loops. (start, go till, ++start)
How do you use a DoWhile loop?
do
statement
while( expression)
ex: do
{
cout << i << " ";
i += 5;
}
while (i <= 20);
do something first, then continue it if expression in following while statment is true.
When do you use a FOR loop?
For loops are used when you know or can determine the number of repetitions in advance
FOR knows the count
When do you use a WHILE loop?
While loops are used when the number of repetitions is not known
While doesn't know how many repeititions
When do you use a doWhile loop?
If the program doesn't know the number of repetitions, but it is at least 1 doWhile is the right choice
Use do while when you need at least 1 repetition, but don't know how many more.
List 5 cmath functions
abs(x) // returns absolute value of x
floor(x) // returns largest whole number not > x
pow(x,y) //returns value of x^y
sqrt(x) //returns nonnegative square root of x
tolower(x) //returns lowercase value of x
toupper(x) //returns uppercase value of x
requires #include<cmath>
What is the basic structure of a user defined function?
Each function must contain:
1) function name
2) parameters, each with data type
3) data type of output
4) code to accomplish function
4 elements of a value function
What is the syntax of a value returning function?
functionType functionName(formal parameter list)
{
statements
}
output type, funcName, input parameters, {code;}
What is the syntax of a formal parameter list?
datatype identifier; datatype identifier, ..
Can be values or variables created in parameter list
MUST have datatype,
FORMAL list is input for function, has data types and typically variables that link to actual expressions to pass data into function
What is the syntax of an actual parameter list?
(expression or variable, expression or variable...)
It can be empty, but () are still req'd. Actual values are variables or exp from the main or other function that are inputs to the called function
function inputs, typically in main program from variables or values in main program or other function
What is a return?
A return is the single output of a value returning function. The return statement is the last thing executed before control goes back to the main pgm
Malik page 328 has best diagram of function parts
What is afunction CALL?
functionName(actual parameter list)
ex: larger(one, two)
no data type is specified.
What is a formal parameter?
A formal parameter is a variable declared in the function heading
What is an actual parameter?
An actual parameter is a variable or expression listed in a function call
How do you declare a void function?
void functionName(formal parameter list)
What is a reference parameter?
Designated by a '&' after the data type in the formal parmeter list, a reference function receives the memory location of the actual parameter, effectively allowing the function to pass values to the actual parameter.
When are reference parameters used?
1) when actual parameter values needs to be changed
2) when you want to return more than one value from a function
What is an automatic variable?
An automatic variable is one that allocated memory at the beginning of a block, and deallocated at exit
What is a static variable?
static dataType identifier; declares a static variable
A static variable is one that holds memory as long as the program is executing. Global variables are static variables.
How do you overload a function?
Give the same function name but change formal parameters to change input to same function
Define the Enum type.
enum typeName {value1, value2, ..}
C++ lets you define datatypes and values, but no operations.
Enumerations are ordered sets of values
How do you declare a enum datatype variable?
dataType identifier, identifier
ex: enum sports { value1, value2}
sports popSport, mySport // declares popSport and mySport as variables of type Sports
How do you increment enums?
static_cast<sports>(popSport + 1)
What is the syntax for typedef statements?
typedef existingTypeName new TypeName;
What is the syntax for declaring a namespace?
namespace namespace_name
{ members}
Members can be variables, constants, functions, etc.
What is the syntax for accessing a namespace member?
namespace_name:: identifier
or
using namespace_name:: identifier
List five string functions
1) strVar(index) // returns the element at position (index)
2) strVar.compare(str) // compares strVar and str
3) strVar.erase(pos, n) // erases n characters starting at pos
4) strVar.find(str) // finds the first occurance of str in strVar
5) strVar.length() // returns the value string::size_type giving number of characters in strVar.
How do you declare a one dimension array?
dataType arrayName [intExp];
ex: int num[5] // array of five ints
intExp is any constant expression that evaluates to a positive integer.
const ARRAY_SIZE = 10
int list[ARRAY_SIZE] // declares an array that's size is determined by the variable ARRAY_SIZE.
How do you assign values to an array ?
list[5]=34 // assigns the value 34 to array component 5
How do you initialize a one dimension array?
for(index = 0; index < 10; index++)
sales[index] = 0.0
How do you read data into an array?
for(index = 0; index < 10; index++)
cin>> sales[index];
How do you print an array?
for(index = 0; index < 10; index++)
cout<< sales[index]; << " ";
How are arrays passed as parameters to functions?
Arrays are passed by reference only. You don't need the '&' symbol.
What do you prevent a function from changing an array by reference?
By making the reference constant . Include 'const' in front of the array name and it won't change the actual parameter.
Name 3 cstring functions
1) strcopy(s1, s2) // copies s2 into s1
2) strcomp(s1, s2) // returns value < 0 if s1 is < s2, etc
3) strlen(s) // returns string length less null character
How do you read c strings?
cin.get(str, m +1) // stores the next M characters until \n into str
How do you use getline with cstrings?
cin.getline(text, 100); //reads the next 99 characters into text
How do you convert a string to a c-string?
The function c_str is used
strVar.c_str() //where strVar is a string variable
Give an example of a simple parallel array
ex: infile >> studentID[numStudents] >> courseGrade[numStudents];
while( infile && numStudents < 50)
{
numStudents++;
infile>> studentID[numStudents]
>> courseGrade[numStudents];
}
How is a 2d function delcared?
double sales[10][5] ; // declares a 2D array with 10 rows and 5 columns
What is the syntax to access an array component?
arrayName[indexExp1][indexExp2]
exp1 is row position, exp2 is column position
How do you initialize 2D arrays?
Using nested for loops.
ex: for(row = 0; row < numRows; row++)
{ for(col = 0; col < numCol; col++)
arrayName[row][col];
}
Give an example of a string array declaration
string arrayName[numElements];
ex: string list[100];
How is typedef used in defining arrays?
Use typedef to define a 2d array,and declare variables of that type.
ex: typedef int tabletype[nr][nc];
tabletype matrix; // declares matrix of typedef specs
This can also be used when declaring formal parameters.
How do you declare a vector?
vector<elemType> vecList; // creates an empty vector called vecList
vector<elemType> vecList(n, elem); // creates vector vecList initialized with n copies of elem.
ex: vector<int> intList ; // creates empty vector named intList
Give 5 vector functions.
1) vecList.at(index) // gives value at index
2) vecList.front // gives first value in vector
3) vecList.size // gives number of elements
4) vecList.pushback // adds a copy of elem at end of vector
What must be included to use vectors?
You must include the header file vector, i.e. #include<vector> to use the vector class.
How do you define a struct?
struct structName
{
dataType1 identifier 1;
dataType2 identifier 2;
};
ex:
struct employeeType
{
string firstName;
string lastName;
string address1;
string address2;
double salary;
};
This defines a struct, but no memory is declared until a variable of that struct type is declared.
How do you declare a variable from a struct?
employeeType newEmployee;
This variable allocates memory for each component of the struct.
How do you access a struct member?
structVariableName.memberName
ex: newEmployee.firstName
How do you store a value in a struct?
ex: newemployee.firstName = " John" ;
Give an example of a void function with a struct parameter.
void print(studentType student)
where studentType is a struct type, and student is an instance of that type.
Give an example of an array within a struct.

Malik p. 621
struct listType
{
int listElem [ARRAY_SIZE];
int listLength;
};
Give an example of a struct in an array.
assume that struct employeeType already created, then:
employeeType employees[50]; creates an array of 50 structs of employeeType.
Give an example of loading file data into an array of structs.
Assuming a datafile is open, a for loop can load data:
for(int count=0; count<50; count++)
{
infile >> employee[count].firstName
>> employee[count].lastName
>> employee[count].salary;
}
Give an example of a struct within a struct
struct employeeType
{
nameType name; // struct type then variable
addressType address;
dateType hireDate;
contactType contact;
};