User Tools

Site Tools


opus:spring2012:brobbin4:cprogpart3

cprog Keywords

Compiler, Preprocessor, Flags, Assembler, Linker, Milti-file Programs

Definition

Compiler - A compiler is a program that can assemble a human readable source code into machine code that a system can execute.

PreProcessor - A preprocessor is a program that performs some sort of preliminary processing on an input before being processed by the main program.

Flags - A flag is a variable or memory location that stores a true-or-false value, normally either recording the fact that an event had occured or a request for a certain action to take place.

Assembler - An assembler is a program that is used to convert instructions written in a low level code into maching code.

Linker - A computer program that adjusts two or more machine language program segiments so they can be loaded simultaneously and executed as one unit.

Multi-file Programs - Multi-file programs are programs that have been broken up into easier to manage blocks of code. Normally functions have there own file and each function has its own header file. This is done to keep code modular and organized. Keeping code modular like this allows for code to be reused elsewhere.

Demonstration

Below is a link to a Mulit-file program I have created. Once you click on the link simply scroll down to the code section of the page. Note how all the functions have there own seperate file.

http://www/user/brobbin4/portfolio/cprogproject3

I/O Streams

Definition

I/O streams are channels in which data can flow to or from any I/O device. I/O device is a device such as a keyboard, mouse, disk drive, basically anything that can either send input to a system or recieve output from a system.

In C++ an I/O stream can be refered to any data stream that sends data into a program or recieves data from a program.

C++ does not have I/O streams built into the language and instead use the iostream library to provide the necessary information to handel I/O streams. C++ has some basic I/O streams available to it which are cin, cout, cerr.

cin - the C++ standard input cout - the C++ standard output cerr - the C++ standard error handler. This is used when a program ancounters an error and needs a place to send that error information.

Stream operators can be defined as an operator that has an influence on how the data from I/O Streams are handeled.

Type Casting Operators, Const-Volatility Specifiers

Definition

Type casting operators are operators that are used to change one data type to another data type. The most general cast operator supported by most C++ compilers is “(type) expression” where type is the desired data type.

Const short for constant means something is not modifiable, so data objects that are declared with const as a part their type specifications must not be assigned to in any way during execution of a program. Most of the time the definitions of the objects will contain an initializer because you cannot assign it and if they didn't contain an initializer you would never get a value.

Volatile means something can me modified and we have this type specifier mainly for problems that are encountered in real-time or embedded systems programming using C++. For example you are creating code that will control a hardware device by placing values in hardware registers at known absolute addresses. Because this is happening in real time we need a way to change these values on the fly but most C compilers have not been able to handle this in the past. To correct this issue and other issues that have to do with when to write to where a pointer points the volatile keyword was introduced. This tells a compiler that an object is subject to sudden change for reasons which cannot be predicted from a study of the program itself and this forces every reference to such objects to be a genuine references.

Classes

Definition

A class is an expanded concept of a data structure. A class is the definition of an object and thus a class can hold not only data but it can hold functions too. Classes resemble structs with one difference, all struct members are public by default where all class members are all private by default.

Objects - objects are components of a program that know how to perform certain actions. Objects also know how to interact with others pieces of a program.

Constructor - A constructor is a member function with the same name as its class. Constructors are called as such because they construct the values of data members of the class. A constructor resembles an instants method but differs from a method because a constructor never has an explicit return type.

Destructor - A destructor is like a constructor is the fact that it is a member function with the same name as its class and that it resembles ans instants method but never has an explicit return value. A destructor is used to deallocate memory and do other cleanup tasks for a class object and its class members when an object is destroyed.

Access Control - C++ employs access control to limit access to certain data within a class. below are the ways that this is accomplished.

Public - members specified within the public section of a class are accessible from any function.

Protected - members specified within the protected section of a class are accessible only by the functions of the class that original declared the members, friends of the class that originally declared the members, classes derived with public or protected access from the class that originally declared the members, and direct privately derived classes that also have private access to protected members.

Private - members specified within the private section of a class are accessible only from member functions and friends of the class.

Friend - A friend allows a function or class to gain access to to the private and protected members of a class in which they are not a member of.

“This” Pointer - “this” pointer is a pointer that is accessible only within the non-static member functions of a class, struct, or union. It points to the member function for which the member function is called.

Inheritance

Definition

Inheritance is the mechanism of reusing and extending existing classes without modifying them. Inheritance is kinda like embedding an object into a class. For example, you declare object c of class M in the class definition of R. The result is class R will have access to the public data members and member functions of class M, however in class R you will have to access the data members and member functions of class M through object c. In single inheritance classes have only one base class while in multiple inheritance classes may have multiple base classes.

Polymorphism/Virtual Functions - A key feature of derived classes is that a pointer to a derived class is type-compatible with a pointer to its base class. Polymorphism means that a call to a member function will cause a different function to be executed dependent on the type of object that invokes the function. A virtual function is a function in a base class that is declared using the keyword virtual.

Abstract Base Class - An abstract base class is a base class that contains at least one pure virtual function. A pure virtual function is declared by using a pure specifier in the declaration of a virtual member function in the class declaration.

Overloading

Definition

Overloading is the practice of supplying two or more definitions for a given function name in the same scope. The compiler is left to pick the appropriate version of the function or operator based on the arguments with which it is called.

Functions - Function overloading is the act of declaring more then one function with the same function name in the same scope. The declarations of each function must differ from each other by the types and/or the number of arguments in the argument list. When an overloaded function is called the the correct function is selected through comparison of the argument list of the of the function call with the parameter list of each of the overloaded candidate functions with the same name.

Operators - The operator keyword declares a function specifying what operator-symbol means when applied to instances of a class. This gives the operator more than one meaning, or “overloads” it. The compiler distinguishes between the different meanings of an operator by examining the types of its operands.

Exception Handing

Definition

Exceptions are run-time anomalies, such as divide by zero, that require immediate handling when encountered. The C++ language provides built-in support for raising and handling exceptions. With C++ exception handling, a program can communicate unexpected events to a higher execution context that is better able to recover from such abnormal events. These exceptions are handled by code that is outside the normal flow of control.

Throw, Try, Catch - these three keyword are the basis of error handling in the C++ language and are defined below.

Throw - A program throws an exception when a problem shows up. This is done using a throw keyword.

Try - A try block identifies a block of code for which particular exceptions will be activated. It's followed by one or more catch blocks.

Catch - A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.

Templates, STL

Definition

Templates are mechanisms for generating functions and classes based on type parameters. Through the use of templates, you can design a single class or function that operates on data of many types, instead of having to create a separate class for each type.

STL - The STL or Standard Template Library is a collection of C++ libraries that allow the use of several well known kinds of data structures without having to program them. The templates are designed to efficiently run code. The compiler does most of the work of generating the efficient implementations of the templates.

cprog Objective

opus/spring2012/brobbin4/cprogpart3.txt · Last modified: 2012/05/10 01:03 by brobbin4