You are on page 1of 7

//Chapter 2 Hello world

// A comment
// Created by Ephraim on 2015
<< Put into
cout << "God is love";
C++ A programming language.
Used from mars to the depths of the ocean.
Adobe/Autodesk uses it to create its products too.
Comment
Things which describe what the code says
Only for ourselves and fellow programmers
Computers do not even glace at it.
Compile time error
Errors found during compile time. Missing semicolons, undefined 'cout' etc.
Easier to correct than link time/run time errors.
cout Pronunced see-out. Stands for character output stream.
By default, it refers to the monitor.
Executable
This is what the computer actually executes
a.cpp --> a.obj --> a.exe
Function
Takes in something and gives an output.
In case of the main function, it is where the cpp program starts.
Header
Contains definitions of terms written by others so that we can use them.
IDE
Nice UI for writing code, debugging and compiling.
It automatically colour codes keywords, comments etc.
Library - code by others which can be ascessed by including it in #include
Linker
Links translation units to output an exe
a.obj + iostream.obj --> |Linker| --> a.exe
main()
This is where execution of a program starts.
It usually has an int datatype, with 0 indicating sucess and any other number fa
ilure
Object code
The code produced after compilation
a.cpp --> |Compiler| --> a.obj
.obj is not portable, so is .exe, not portable.
Output
What is displayed(usually on a screen)
Program
Written statements conveying the computer "what we want the computer to do".

Source code
Plain text of the program. Has the file extension .cpp (for c++)
Statement
A part of a program that specifies an action but is not an include or other preprocessor directive.
// Chapter 3 Objects Types and Values
Assigment '='
Assigning a value to an object. The object must already have an value.
Initilization also uses he same operator.
cin
Character input stream. cin >> a;
Usually the keyboard.
Concatenation
Joining two strings
str1 = "alpha"; str2 = "beta"; cout << str1 + str2; //alphabeta
Conversion
Converting from one data type to other.
May be explict or implict.
int a = 5; cout << (char)a;
cout << 5 / 5.0; // 5 is converted to double implictly
Declaration
A statement which gives name to an object.
int a;
Decrement
--a; // decreases a by one
Note that a-=2 decreases a by 2.
Definition
A definition is a declaration that sets aside memory for an object.
Increment
++a; // Increases a by one
Note that a+=2 increases a by 2;
Initilization
Gives a value to a variable such that it did not have a previous(even garbage) v
alue.
int a = 5;
Note that it has the datatype mentioned.
Name
Name of a variable. Used to refer to its vale.
Narrowing
Unsafe data type conversion where values get truncated
They put a value into an object that may be too small (

narrow

Object
Place in memory with a type which says what can be put into it.
Operation

) to hold it.

Something that can perform an operation such as a function or operator


Operator
Can be a symbol + - or a function sqrt()
Takes values on LHS and RHS and does something
c = a + b //Addition performed on a with b and gets stored to c
Type
Intreprets what the bits are.
Also specifies what operators can be used with the bits.
Type safety.
Prevent garbage values.
Checking truncation/ data loss.
Value
Set of bits in memory intrepreted according to type.
Variable
An object with a name.
//ch4 computations
22. What can you do to a string that you cannot do to an int?
6. What is an lvalue? List the operators that require an lvalue. Why do these op
erators, and not the others, require an lvalue?
abstraction - Dont worry about how its done, worry about details
Computations - Act of producing outputs based on inputs
conditional statement - Executes statement of condition is fulfilled - if else
Declaration - Specifying name with type
Definition : Declaration that allotes memory
Divide and conquer - Split the program into smaller managable parts Dictonary(in
put, sort, check for repeat,output)
else - The statement after else key word will be executed if the condition is no
t fulfilled
Expression - Value arising out of a mixture of operators and oprands. Can just b
e a name.
Function - Logically defined part of a program which takes in input and gives ou
tput.
if-statement - Execute statement after if , if condition is fulfilled
for statement - A kind of loop where you go through a number of times. Details a
re specified on the first line
Range for - Specially made for vectors/going through the elements in a vector
increment - a++, same as a = a + 1 or a+=1
input - What you give to a program or a part of a program. Can be air speed, nam
e, temperature etc.
iteration - Repeating a statement, to series of elements or data structure
loop - A way to repeat statement
lvalue - The location reffered by the object
rvalue - The value of the object reffered to by the name
output - What a program or a part of a program gives out. Can be well, lines, ci
rcles, computed data etc
push_back() A member function of vector which pushes back the value given in ()
selection - Selecting which statement to execute based on a condition
member function - call with dot notation
object_name.member_function(argument-list)

sort() - Defined in std lib facilities, takes a vector in its argument list and
sorts it
Switch statement - Compares a variable with a set of constants(case labels), exe
cuting statements for each case
Vector - A collection of elements with same data type. Unlike arrays, its number
of elements need not be specified at the start. They can be ascessed with an in
dex.
Statement - Anything that ends with a ;
while statement - a kind of loop where the loop variable is declared outside, an
d the increment of the loop varible is done inside. The loop continues as long a
s the control variable satisfies a condition
ch5 Errors
Argument error - When calling a function, bad arguments are given
Example - Negative width
Assertion - A statement that asserts an invariant
Catch - The process of catcing something thrown from a try block
In absence of a catcher for a throw the program terminates
Compile time error - Includes Type and syntax errors. These are found at compile
time by the
compiler(quicker to find) and are generally easier to fix.
Container - Collections of data (An object that holds other objects)
A vector is a container
Debugging - The process of removing bugs (not random, but by understanding how p
rogram works)
Error - A mismatch between what the user wants the program to do and what the pr
ogram really does
Execption - The object which is thrown by using throw and caught using catch. It
is used to indicate errors.
Invariant - A condition that must be true at that point in time of the program
Link time error - Errors found at link time. Takes more time to find than compil
e time errors. An example would be different datatypes for a same function in di
fferent translation units
Logic error - An error purely in logic of the programmer. A computer is a fast m
oron. Arises due to implict data type converion (converting temperatures 9/5, re
sults in 1 not 1.8), wrong formulas etc.
Post condition - A condition that must hold true upon end of a function or loop
Pre condition - A condition that must hold true at the start of a function or lo
op
Range error : Referring to anything outside [0, v.size()). Commonly occurs as [0
, v.size()]
Requirement - A descripting of the pre conditions of a function
Run time errors - Errors found at run-time, such as divide by zero. They are det
ected by computer, library or user code.

Syntax error - A statement which does not obey c++ grammar


Testing - A systematic way of finding errors by giving a large number of inputs
Throw - The process of throwing an exception when an error is found
Type error - Wrong number of arguments, wrong datatype given to function etc
//ch6 making a program
Analysis - Figure out what should be done and the requirements
Class - An user defined object which has data menbers or member functions(operat
ors of data members)
class member -A type may or may not have members. May be data members to hold va
lues or functions to opreate on values. Can be public or private(imprementation
details)
Data members - members of class which hold data may have a fundamental data type
or user defined data type
Design - The step which comes after analysis where you decide which libraries to
use and how program interacts with other components. Overall structure.
Divide by zero - A hardware error . Always throw an execption if it might happen
.
Grammar - The syntax of input.
Implementation - Comes after Analysis and design. Write the program debug and re
peat.
Interface - The public part of a class. It is meant for those who use the class
while hiding the implementation details.
Member functions - Operations defined in a class
Parser - A program which analysis input based on grammar rules
Private - THe part of the class which holds the implementation details which is
not needed by user to ascess directly.
Prototype - A minimal basic version of a program. If satisfied, add more feature
s. else rebuild. Used for experimentation.
Pseudo code - Written scribbles to explain logic, not real programming notation.
Syntax analyser : See praser
Use case : Cases of what the user would want the program to do.
Tokens : A sequence of characters we consider a unit, char or number
Public : The user interface part of the class which the users can ascess
ch 7
Code layout : The way(spaces, newlines,indentation) a program is typed. Wont cha
nge a single thing in compiling, but makes it easier to read and prevents errors
Commenting : Code says what it does, and comments say what we intend to do

Include input grammar in comments. Enough comments to hand over maintanence to s


omeone else but does not say things what can be said in code.
Error handling : Using exceptions and other tricks(while loops) to prevent error
s. Makes sure each case is handled.
Maintenence : After program is complete, it needs to be maintained over time as
new features are required/ bugs need fixing. Proper comments ensures good mainte
nence.
Recovery - To ensure that the program does not close after an error of user like
spelling mistake etc. Easy to implement, just use the try blocks somewhere in a
while loop
Revision history : Expressed in comments at the start, lists the changes made ov
er time
Scalfolding : Start program, end program and handle errors.
Aymbolic constant : const values and start of program with descriptive name to p
revent magic constants. Ensures the need to not change it everywhere.
Testing : A systematic way of finding errors. Include legal, illegal and silly
inputs.
ch 7
Activation Record : A data structure containing a called functionn's local vars
and implementation details and parameters
Argument : A value passed as parameter of a function
Argument passing : Passes the value to the argument. The formal parameter gets i
nitiliased with the actual parameter
Call Stack : A collection of actiavation Records. Last in first out
Class scope : Area within the scope of the class
For example, function in a class may use the data memb
ers to operate upon
const : When a variable declaration/definition is prefixed by a const, its value
cant be changed.
In case of a formal parameter with a const, the value of parameter is not change
d within function
Const can be initilaised once, at any point in the runtime.
constexpr : Same as const, differs in the fact that the value should be known at
compile time
Declaration : To introduce name to scope
Definition : A declaration that allocates memory
Extern : Used to declare a variable found in another cpp/header file
Forward declarition : When a function is indirectly recursive, the function it i
s calling may need a declaration above the original function
Function : A named set of statements/ expressions that perform a single logical
operation

Function Definition : Allocates memory to the function. Must contain the stateme
nts which will be executed when the function is called
Global scope : The scope which is not nested inside any other scope. Every other
scope is nested inside the global scope. Any object in the global scope can be
used by anyone.
Header file : file containing declarations to be shared between programs. A sin
gle header file contains similiraly logical declarations.
Initializer : THe initial value r body of function. Use {}
Local scope : Between braces of a block or function
Namespace : A named scope to organize classes,functions, types etc
Namespace scope : A scope nested in a global scope or other namespace
Nested block : A block nested inside a if-else statement etc. Blocks within bloc
ks and within other functions
Parameter : Formal arguments, when called, the parameters get initialised with t
he actual values
Pass by const reference - WHere, instead of the value of an object, the location
of the object is sent. Futhermore, the location's value is unchangeable
Pass by value : Sends the value to the function, the value is the initilazer to
the formal argument
Pass by reference : Send the location of object instead of the value. Such a met
hod implies that the value in the location will be modified by the function.
Recursicion : When a function calls itself directly or indirectly when a functio
n calls another function which calls the original function.
Return : The first word in a function definition/declaration is the return data
type. The keyword return should be followed by the object to be returned(unless
its a void) followed by a semicolon to return something from a fuction.
Return value : THe value of the returned data type
Scope : A region in program text.
Technicalities : The grammar of language such as the syntax etc
Undeclared identifier - Using a name before it is declared
using : Refer to this name of this namespace when I refer to the name unqualifie
d
Unless the name is locally present.
using namespace : When I use an unqualified name refer the name in this namespac
e unless that name is already locally present.

You might also like