C++
How do you declare an array?
(Data type) name[] = new (Matches the first type)[size]; int days[6];• char name[41];• long units[50];• doublesizes[1200];
Order of operations in C++
++ -- unary operations then PEMDAS
what is the difference between ++X and X++
++X is a pre increment operator so X will increment before statement is evaluated
what does dataFile.open("info.dat", ios::in | ios::out);
...This opens dataFile (info.dat) in both input and output modes.
What are the three steps when approaching a task
1. gain an understanding of the problem at hand 2.Identify key concepts involved 3.express key concepts in code
what are the four characteristics of a variable
1. name 2. location in memory 3. value 4.data type
What are the seven control structures in C++
1. sequence 2. if 3. if/else 4. for 5. While 6. do/while 7.switch
What does an IDE do?
1.we write source code onto it 2.compiler converts it into object code 3.Linker links the os libraries with object code
what does array[5] of int array[]{3, 4, 0, 2, 12, 13, 19} give?
13
What does passing a value include
A copy of the argument's value is made and passed to the function.• Changes made to the copy do not affect the original variable's value.• The contents in a function's value parameters are destroyed when the function returns, along with the contents of the local variables. Therefore, they cannot be used to return information to the calling code.• The difference between the value parameters and local variables is that the values of the local variables are undefined when a function starts to execute, whereas the value parameters area automatically initialized to the values of the corresponding arguments.
What are sequence control structures?
A sequence
what does ADT stand for
Abstract data type
what does a switch statement do?
Allow the value of a variable or expression to determine where the program will branch. a default section comes after all the case statements. This section is branched to if none of the case expressions match the switch expression. The default section is optional. If you leave it out, your program will exit the switch statement and execute the next statement if the switch statement doesn't match any of the case statements.
What is the first step when approaching a task?
Analysis, learn and understand the topic at hand.
os::app
Append mode. If the file exists, the contents are preserved and all output is appended to the end of the file. This flag causes the file to be created if it does not exist.
what is special about arrays
Arrays are the only "built-in" compound container C++ has.
ios::binary
Binary Mode. When a file is opened in binary mode, information is written to or read from it in pure binary format. (Default mode is text).
Who invented C++?
Bjarne Stroustrup
what are the advantages of c++
C++ is an object-oriented programming language and includes classes, inheritance, polymorphism, data abstraction, and encapsulation. C++ has a rich function library. C++ allows exception handling and function overloading, which is impossible in C. C++ is a powerful, efficient, and fast language.
why does a function need a prototype
C++ needs a definition for a function before it can be called,
What is the second step when approaching a task?
Design, learn the key concepts of the task and anything involved.
how does a recursion function work
Each call creates a new copy of the function's variables. Just about any recursive function can be solved via iteration.
What must functions have
Except for void functions all must have a return value
What is declaration of data
Has to be done for variables so C++ knows what it is.
ios::trunc
If the file already exists, its contents will be deleted. This is the default mode used byios::out.
ios::ate
If the file already exists, the program goes directly to the end of it. Output may be written anywhere in the file.
ios::noreplace
If the file already exists, this flag will cause the open function to fail.The existing file will not be opened.
ios::nocreate
If the file does not already exist, this flag will cause the open function to fail. The file will not be created
ios::in
Input mode. Information will be read from the file. If the file does not exist, it will not be created and the open function will fail
what does IDE stand for?
Integrated Development Environment, how code can run basically.
What is one purpose for code?
It is a vehicle for the programmer to specify actions to be executed.
when would you use a (while) statement?
It is used best in situations where you do not want the loop to iterate if the condition is false from the beginning. It is also ideal when you are using a sentinel flag. NOTE loop will not run if the test condition is false.
What does close to the problem to be solved mean?
It provides a set of concepts for the programmer to use when thinking about what can be done.
What are identifiers?
Letters - Digits - Underscore. C++ is case sensitive and identifiers must begin with letters or underscore
When storing variable data what does C++ have to keep track of?
Location/Address, value, data type
what are some advantages of functions
Makes programs more manageable. Reusability of the (write it once - use it often). Avoids redundant code - maintain it in just one place.• The typical way of getting something done in a C++ program is to call this to do it. This is also known as invoking with a call.• A function call is a statement that causes a function to execute.
ios::out
Output Mode. Information will be written to the file. By default, the file's contents will be deleted if it already exists
What is the third step when approaching a task?
Programming, translate the design method into code and execute.
It tests the value of an integer expression and then uses that value to determine which set of statements to branch to.
Property of a switch statement
What is a purpose for code?
Provides a set of concepts for the programmer to use when thinking about what can be done.
How do software and hardware interact?
Software pushes hardware
What are data types and what is their purpose?
Specific sets of values either system or user and the hold different amounts of storage and use memory.
When would you use a for loop?
The for loop is a pre-test loop that first executes an initialization expression. In addition, it automatically executes an update expression at the end of each iteration. It is ideal for situations where a counter variable is needed. The for loop is primarily used when the exact number of required iterations is known.
what is the difference between a function header and call
The function header is the first line of the function definition (not terminated by a semicolon) A function call is the statement that actually executes the function.• Note that the return type is not listed in the function call.
What does an (if) statement do?
The if statements is used to check a condition and if the conditions is true
what must the declaration of a function have?
The type of the value returned (even declare if nothing is returned). The name of the function. The number and types of the arguments (parameters) that must be supplied in a call to that function (parameter list) The body of the function.
what are the three part of an array.
Type Name Array size declarator (the value located inside the brackets)
What are arrays
Unlike regular variables, arrays can hold multiple values. An array is a variable that can store a group of values, all of the same type. These values are stored together in consecutive/contiguous memory locations. Once an array is declared, it's size cannot change (compile time only).
what are sting arrays and what is special about them
When initializing a character array with a string, simply enclose the string in quotation marks.• The array has to have enough elements to accommodate the char elements plus the null terminator at the end of the string. (the null terminator not automatically included when the array is initialized within individual characters.
What are reserved words
Words that belong already in the C++ libraries and cannot be identifiers.
to pass a double array into a function what needs to be a parameter
a double array that defines the number of columns
what is a struct
a package of variables under one common name
what is the pointer to term of a pointer
a pointer to is the memory location of the specified data type.
what is it called when a function calls on itself
a recursion function
what is the reference to of a pointer
a reference to a given data type. NOTA COPY
what is a default argument and what are it's properties
are passed to parameters automatically if no argument is provided in the function call. It is possible to assign arguments to function parameters. argument is passed to the parameter when the actual argument is left out of the function call. Note - the function's default arguments should be assigned in the EARLIEST occurrence of the function name (usually in the prototype). The value of a default argument must be a constant When an argument is left out of the function call, all the arguments that come after it must be left out too. When a function has a mixture of parameters both with and without default arguments, the parameters with default arguments must be declared last
where does a function prototype normally go?
at the top of a program so that it is read before any other code.
in the struct struct Employee { int number; string name; float hoursWrked; float payRate; float grossPay;}; what does ' Employee Worker{123, "Smith", 80, 15, 120} ' do?
declares and assigns all the variables for the employee worker
what does a function call look like?
displayMessage(); note, ended with a semicolon inside the main()
what does a two dimensional array look like
double dubarray[4][5];
what is a function prototype
eliminates the need to place a function definition before all calls to the function this defines the the functions types and parameters and the type of parameters
What are the three steps for using a file?
file must be opened and information is either saved and read to the file or just saved. Then the file is closed
Important idea
form follows function
How does an array organize its elements
from a 0-END number system
What does a (do/while) loop do?
he condition is tested at the end of the loop (post-test). WILL ALWAYS execute at least once.• can easily be a source of confusion and errors because the loop body is always executed once before the condition is evaluated. However, for the body to work correctly, something very much like the condition must hold even the first time through. More often than you would expect, the condition would not hold as expected when the program was first written and tested. the condition up front where you can see it is preferable. try to avoid.
What are selection control structures?
if, if/else, switch
what does ifstream do
implements high-level input operations on file-based streams. This data type can be used to create files and read information from them into memory. With the if stream data type, information may only be copied from the file into variables, but not vice- versa
what does fstream do
implements high-level input/output operations on file based streams. This data type can be used to create files, write information to them, and read information from them. With the fstream datatype, information may be copied into a file, or from the file into variables. Requires File Mode Flags.
what does ofstream do
implements high-level output operations on file based streams. This data type can be used to create files and write information to them. With the ofstream data type, information can only be copied from variables to the file but not vice-versa.
how do you define a pointer
int* ptr;
what is a function
is a collection of statements that performs a specific task (ideally, one). Every C++ program must have at least one (and it is called main()).• Programs may be broken up into many manageable ones Splits up a program into manageable pieces (divide and conquer). C++ is made up of numerous functions - user defined and standard library functions.(NOTE - take advantage of the Standard Library)
what is a (continue) statement
is used in the iterator control structures. skips the remainder of the iteration and proceeds with the next iteration.
what is a pointer
it is a variable that "points" to a spot in the memory where information can be found
What does close to the machine mean?
it provides a vehicle for the programmer to specify actions to be executed by a machine.
in the struct: struct Employee { int number; string name; float hoursWrked; float payRate; float grossPay;}; what does Employee foreman and foreman.name = "John Smith"; do?
it sets a new employee to foreman, and sets his name as John Smith
when would a (do / while) loop be used?
loop is a post-test loop. It is ideal in situations where you always want the loop to iterate at least once
What does the (for) statement do?
loops through a block of code a specified number of times
What does the while statement do?
loops through a block of code if and as long as a specified condition is true
what does a while statement do
loops through a block of code if and as long as a specified condition is true
What is a break statement?
manually allows you to alter the flow of control. escapes out of a loop or the remainder of the switch statement.
when would you use a switch statement
menu systems are good
what are the three file stream types
ofstream, ifstream, fstream
when are recursion functions used
routines are often used when completing a process is made easier if you can repeat the process on a smaller subset of items
what are the three types of control structures
sequence, selection, iteration
what does a two dimensional array do?
stores two sets of data in a column and row
what does a struct look like
struct Employee { int number; string name; float hoursWrked; float payRate; float grossPay;};
what is the value term of a pointer
the actual value of the specified data type
what must the expressions be inside a switch statement
the expressions of each case statement in the block must be unique.
what is the address of term of a pointer
the physical memory address of the given data type
what is the dereferenced value of a pointer
the value of the data type pointed to by a pointer
what are values inside of a function?
they are called arguments
why should cation be used with (break) and (continue) statements
they bypass the normal loop continues and program flows.
what is the new operator and what is it used for
used for dynamic memory allocation which puts variables on heap memory
what are pointer terms
value, pointer to, address of, reference to, dereferenced value
what would the function header look like?
void displayMessage() note not ended with a semicolon
when would you overload fucntions
when functions perform the same task but with different parameters
Why are (while) statements preferred over (for) statements sometimes?
when there is no obvious loop variable, or when the update of the loop variable naturally comes in the middle of the loop body.
What is function overloading
when two functions with the same name are used in a program.
What are iteration control structures?
while, do/while, for