User Tools

Site Tools


opus:spring2012:sswimle1:cprogpart3

cprog Keywords

cprog Keyword 17

I/O Streams (cin, cout, cerr, stream operators) [C++]

Definition

I/O Streams in C++ is an standard included library, the library consists of (basic class templates, class template instantiations, standard objects, types, and manipulators).

cin - is an object of the class of istream that notates the standard input stream, corresponding to cstdio stream. cin like most systems defaults its standard input from the keyboard.

cout - is an object of the class of ostream that notates the standard output stream, corresponding to cstdio stream.

cerr - is the standard output stream for errors.

cprog Keyword 18

Namespaces [C++]

Definition

Namespaces give groups like classes and functions a more global scope, for instance if you had two int's in your program but you wanted each to have its own global scope you could name one namespace first and the other namespace second like in the example shown below.

Demonstration

Demonstration of the chosen keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

// using
#include <iostream>
using namespace std;
 
namespace first
{
  int x = 5;
  int y = 10;
}
 
namespace second
{
  double x = 3.1416;
  double y = 2.7183;
}
 
int main () {
  using first::x;
  using second::y;
  cout << x << endl;
  cout << y << endl;
  cout << first::y << endl;
  cout << second::x << endl;
  return 0;
}

cprog Keyword 19

Type Casting Operators, Const-Volatility Specifiers (const, volatile) [C++]

Definition

casting operators remove c syntax inherent for the purpose of making the types more compatible with c++, there are several casting operators.

dynamic_cast - conversion of polymorphic types.

static_cast - conversion of non polymorphic types.

const_cast - removes the const, volatile, and _unaligned attributes

reinterpret_cast - simple reinterpretation of bits.

safe_cast - produce verifiable MSIL.

cprog Keyword 20

Classes (Objects, Constructor, Destructor, Access Control, Public, Protected, Private, Friend, “this” pointer) [C++]

Definition

A class allows you to put functions inside of a data structure for the purpose of organization and ease of use.

A constructor is a function that can be included within a class that can be automatically called whenever a new object is created within that class for the reason of avoiding returning unexpected values.

Destructors are called automatically when an object is destroyed with the purpose of releasing previously allocated memory.

Access Control breaks down into the Public, Protected, and Private data type sub class definitions.

Public variables and data types are accessible to the program outside of the class

Protected are accessible but may not be changed

Private variables and data types are only available inside that specific class they are defined in and may not be acted upon by the outside program.

this pointer can only be used as a nonstatic member function of a class, struct, or union.

Demonstration

Demonstration of the chosen keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

class example{
    public:
        int a;
        int b;
        int c;
        int d;
    private:
        int e;
        int f;
    protected:
        int g;
};
 

cprog Keyword 21

Inheritance (single, multiple Inheritance), Polymorphism/Virtual Functions, Abstract Base Class [C++]

Definition

Inheritance in object oriented programming is used to create a relationship between two or more classes.

when using single class inheritance it means pretty much what it sounds like a sub class can only inherit from one super class or parent class.

and obviously multiple inheritance means that you can inherit information in your subclasses from more than one parent class.

Polymorphism with pointers using the ability that a pointer to a derived class is then compatible with a pointer to it's base class also.

Virtual members or functions are members of a class that can be changed in a derived class.

An abstract class is designed to be a base class that contains a pure virtual function.

Demonstration

class A 
{ public:
   void DoSomethingALike() const {}
};
 
class B : public A 
{ public:
   void DoSomethingBLike() const {}
};
 
void UseAnA(A const& some_A)
{
   some_A.DoSomethingALike();
}
 
void SomeFunc()
{
   B b;
   UseAnA(b); // b can be substituted for an A.
}

cprog Keyword 22

Overloading (Functions, Operators) [C++]

Definition

Overloading means that you are assigning more than one name for the same function or operator in the same scope.

Demonstration

Example I found showing Function Overloading.

#include <iostream>
using namespace std;
 
void print(int i) {
  cout << " Here is int " << i << endl;
}
void print(double  f) {
  cout << " Here is float " << f << endl;
}
 
void print(char* c) {
  cout << " Here is char* " << c << endl;
}
 
int main() {
  print(10);
  print(10.10);
  print("ten");
}

Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:

 Here is int 10
 Here is float 10.1
 Here is char* ten

cprog Keyword 23

Exception Handing (throw, try, catch) [C++]

Definition

An exception in programming is when a program has a situation that has an unexpected circumstance that happens in that section of the programs code. To handle these exceptions their are programming keywords in place like (throw, try, and catch).

catch is used as a preemptive guard against exceptions.

throw is used as a handler after and exception has occurred and tells the program to get rid of or throw the bad segment or unexpected circumstance for the section of code.

try is used as a handler for after an exception is realized as well and instead just telling the program to toss the bad line or code out it gives an instance of instead to try.

cprog Keyword 24

Templates, STL (Standard Template Library) [C++]

Definition

The Standard Template Library is made of predefined class for C++ and provides components called algorithms, containers, functional, and iterators.

cprog Objective

I already filled this out twice

opus/spring2012/sswimle1/cprogpart3.txt · Last modified: 2012/05/07 13:35 by sswimle1