1/31
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is modular programming
breaking our program into seperate files and functions, each handling a specific task
What are the 3 main benefits of modular programming
readability, reusability, and maintainability
what is readability?
code is easier to understand
what is reusability?
using the same function in multiple programs
what is maintainability?
fixing bugs in one module without effecting the whole program
What goes in header files (.h) ?
types, functions, classes, constant declarations, macros which can be used in multiple files
What are header guards?
#ifndef FILENAME_H
#define FILENAME_H
#endifwhat do header guards do?
prevent the file from being included multiple times in the same program
what is extern
used to declare variables/functions that exist in another file
what goes in implementation files (.cpp)?
function and class definitions
what goes in the main file (main.cpp) ?
main() function
include the header file and call the functions
what are namespaces?
containers for related identifiers (functions, variables, classes) that helps prevent naming conflicts
what is the C++ standard namespace?
standard C++ library is defined inside the namespace std::
std::cout << "Hello";what is a using directive?
using namespace std;used to bring names from a namespace into the current scope
this avoids writing std:: everywhere, but can cause naming conflicts in large programs
how to define namespaces?
namespace english {
int x = 2;
}
// english is the scope nameyou define the namespace with the namespace keyword, then declare your identifiers inside its block
how to access elements
english::x;outside that block, you refer to them using the scope resolution operator :: e.g. namespace::id
what is the compilation process?
process that turns source code into machine code
creates an executable that can run independently of your compiler/IDE
what is source code?
regular text file or multiple text files
What are the steps of compilation?
preprocessing, compilation, and linkage
what does the preprocessor do?
adds contents from included files according to directives
what does the compiler do?
translates the source into an object file containing machine code
what does the linker do
merges together all object code files into an executable
What are some common syntactic errors?
normally results in “wrong results”
mixing = and == or & and &&
uninitialized variable
infinite or off by one iterations
what is =
assignment operator
what is the assignment operator used for?
// used to store/change a value in a variable
int x = 5;
// meaning: put/store 5 in xwhat is ==
equality comparision operator
what is the equality comparision operator used for?
// used to check if two values are equal
if (x == 10)
// meaning: Is x equal to 10?
// this returns true or falsewhat is &&
logical AND
what is the logical AND used for?
// used to check if both conditions are true
if (x > 0 && y > 0)
// meaning: x is greater than 0 and y is greater than 0
// both must be true for the whole condition to be truewhat is &
address operator
what is the address operator used for?
// 1. & as address-of operator
// gets the memory address of a variable
int x = 5;
std::cout << &x;
// meaning: give me the memory address of x
// 2. & in parameters -> reference
void change (int &num)
// meaning: num is a reference to the original variable
// changes affect the real variableWhat are the common execution errors?
normally results in “crashes”
attempting to access invalid memory
division by zero
unhandled exceptions