-
Defining a Member Function With a Parameter-–C++ Notes (C Plus Plus Notes)
Defining a Member Function With a Parameter A member function can require one or more parameters that represent additional data it needs to perform its task. A function call will supply arguments for each parameter. A member function is called by following the object name with a dot operator (.), the function name, and a set of parenthesis containing the function’s arguments. A parameter list may contain any number of parameters, including none at all (represented by empty parentheses) to indicate that a function does not require any parameters. The number and types of arguments in a function call must match the number & types of the parameter list.
-
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…
-
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…
-
Computer Science (CompSci) Notes
Step 1–Define the problem to solve Step 2–Define a solution Step 3-Write a program that implements the solution Step 4-Compile the program Step 5-Link object files Step 6-Test program Step 7-Debug C++ (C plus plus) files should end in a “.cpp” extension to indicate a C++ source file. (ex: name.cpp) Use a C++ compiler to compile a C++ (.cpp) program. The C++ compiler sequentially goes through each source code (.cpp) file in your program and does 2 important tasks: FIRST, it checks the code to make sure it follows the rules of the C++ language. If it does not, the compiler will give you an error to help pinpoint what…