-
Declarations, Prototypes, Definitions, & Implementations–C++ Notes (C Plus Plus Notes)
Declarations–a declaration introduces a name into a scope. Generally speaking, a scope is either an entire ‘.cpp’ file (source file) or anything in code delimited by {} (braces), be it a function, a loop within a function, or even an arbitrarily placed block of {} within a function. A name introduced, is visible within the scope from the point at which it is declared to the end of that scope. A declaration merely tells the compiler how to use something, it does not actually create anything. Prototypes–a prototype is just another name for a declaration of a function. Definitions–a definition fully specifies an entity. Definitions are where the actual creation…
-
Header Files, Source Files, & Extension Names–C++ Notes (C Plus Plus Notes)
What’s the difference between Header files & Source files? Basically, header files are #included and not compiled, whereas source files are compiled and not #included. So do not compile ‘.h‘ files, and do not #include ‘.cpp‘ Source files. Also, do not #include the same .h file twice. This will lead to an error. Extensions All files are fundamentally the same in that they’re all text file, however different kinds of files should have different extensions: Header files should use a .h extension (.h/.hpp/.hxx). Which particular one of these you use doesn’t matter. C source files should use .c (.c only). (But that’s for ‘C’ language.)
-
Class Methods & Separating Interface From Implementation–C++ Notes (C Plus Plus Notes)
Class Methods Methods, or member functions, are functions that belong to the class. There are two ways to define functions that belong to a class, or member functions, or methods. Inside the class definition Outside the class definition (including from a different file like a source file) To define a member function outside the class definition, you have to declare it inside the class (with a function prototype), and then define it outside of the class. This is done by specifying the name of the class, followed by the scope resolution operator ( :: ), followed by the name of the function. Separating Interface from Implementation *Note: It’s better software…
-
Classes & Objects–C++ Notes (C Plus Plus Notes)
C++ Classes & Objects Classes and Objects are the two main aspects of OOP. Ex: Class Objects Apple Fruit Banana Mango or: Class Object Volvo Car Audi Toyota A class is a template for objects, and an object is an instance of a class. When the individual objects are created they inherit all the variables and functions from the class. Everything in C++ is associated with classes & objects, along with its attributes (data members–such as “weight” & “color”), and methods (member functions–such as “drive” & “brake” for a “car”). Attributes & methods are basically variables & functions that belong to the class. These are often referred to as “class…
-
Computer Organization–Notes
Computer Organization Input Unit–the “receiving” section. It obtains info from input devices & places it at the disposal of the other units for processing. Output Unit–the “shipping” section takes information that the computer has processed & places it on various output devices to make it available for use outside the computer. (i.e.–displayed on screens, printed on paper, played on audio devices, or used to control other devices. Can also be output to networks, such as the Internet. Memory Unit–this rapid-access, relatively low-capacity “warehouse” section retains info that has been entered through the input unit, making it immediately available for processing when needed. Also retains processed info until it can be…
-
Functions, & O.O.P.–C++ Notes (C Plus Plus Notes)
Functions Performing a task in a program requires a function! The function hides from its user the complex tasks that it performs. C++ Functions–A function is a block of code which only runs when it is called. Data, known as parameters, can be passed into a function. Functions are used to perform certain tasks, or actions, and they are important for reusing code: Define the code once, and use it many times. C++ provides some pre-defined functions, such as ‘main()‘ which is used to execute code. But you can also create your own functions to perform certain actions. C++ Functions consist of two parts: Declaration–the functions name, return type, and…
-
What is a “Function” in Programming?, & What is “Object Oriented Programming” (OOP)–Notes
Functions Function–a block of code packaged together with a name. Functions are a core feature of all programming languages. aka–sub-routines, methods, or some other name. a way to break up your code. a key benefit of functions is that they help us avoid writing the same lines of code again & again. Once you create a function, you can call it by using its name followed by a set of parenthesis( ). Functions can change their behavior depending on the parameters and arguments given. To have a function return a value, use the “return” statement. Ex: ‘return my_value’ Being able to return values from functions is a cornerstone of programming.…
-
Some Quick Notes On Python Syntax…
Some Quick Notes On Python Syntax: Python was designed for readability, and has some similarities to the English language with influence from mathematics. Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses. Python relies on indentation (using whitespace), to define scope; such as the scope of loops, functions, & classes. Other programming languages often use curly-brackets for this purpose. Python uses the colon symbol (:) and indentation for showing where blocks of code begin and end. That is, blocks in Python, such as functions, loops, ‘if’ clauses and other constructs, have no ending identifiers (other than the start of…
-
A Comment on Comments In Programming Languages…
A Comment on Comments: One of the most important of programming tools is comments! Comments are just lines in the programs which describe what’s going on. Comments can tell the programmer what’s going on and more importantly why! Good comments are important if the programmer reading the code isn’t the one who wrote it, or, it’s been a long time since they wrote it. Another way of thinking about comments is that, “comments are Code!“, and rather than comments explaining code to other programmers, CODE explains the comments to the computer! Either way comments are useful and important and every language has a way of indicating comments. Python uses a…
-
Arithmetic Operators Notes
Arithmetic Operators Notes Operator Example Description M + N Addition of M and N M – N Subtraction of N from M M * N Multiplication of M and N M / N Division of M by N (The result will be a real number.) M // N Integer division of M by N (The result will be an integer.) M % N Modulo: find the remainder of M divided by N M ** N Exponentiation: M to the power of N (e.g., 2 ** 4 results in 16. 2*2*2*2=16 Arithmetic Operators Note: Python also has the math module that contains common math functions (such as sin, cos, etc.) Shortcut…