MonthJanuary 2010

Software Engineering Principles

Software Engineering Principles

Topics

Software Life Cycle

Modules and Modular Design

Functional Design

Program Testing

  • A Bank Account Example
  • Object-Oriented Design

  • A Bank Account Example

  • 1.1 Software Engineering and Software Life Cycle

    • Large software requires a team.
    • Teamwork needs : an overall plan, organization, communication.
    • Important phases in the software life cycle:
    • The goal is to create a solution that minimize the cost incurring over all the cycle phases
    • A good solution should be
      • easy to use
      • algorithmic efficient
      • well structured
      • well tested
      • easy to modify
    • Careful design is required in order to achieve all of these properties.
    • This course is mainly concerned with
      • object-oriented design
      • data structures
      • and

      • algorithms

      which are the techniques used in C++ programs to build good programs.

    • There are a number of pieces used to describe a program, each with a different language to describe some aspect of how a program is produced from the descriptions.
      • header files are high-level descriptions of module interfaces and have names that end with .h.
      • source files are high-level descriptions of modules and have names that end with .cpp.
      • template files are higher-level descriptions for parts of modules and have names that end with .template.
      • object files are low-level descriptions for modules have names end with .o.
      • library files or archive files are collections of object files and have names that end with .a.
      • executable files have the data and machine instructions for a program and have names that are either a.out or whatever is specified using options on the command line.
      • build scripts describe the steps in the translation process from high-level descriptions to executable files and are in files whose names are usually makefile or Makefile.
    • These pieces are used in the various phases of program translation required to produce an executable program from the high-level descriptions in the various pieces. The following steps are usually involved in producing large programs.
      • compilation translates source files into object files using information in header files and template files.
      • linking and loading gather a number of object files and library files into a single executable file.

    We will see each of these steps later in the course, where more complete explanations will be given.

    Further reading and references

    • The software engineering life cycle from an object-oriented perspective.
      http://www.site.uottawa.ca:4321/oose/index.html
      Use the index in the left frame to look up each of the terms in the software engineering life cycle, including validation and verification, which are defined in the same way they are used in our course notes, which is somewhat different than often appears in other references.

    1.2 Modules and Modular Design

    • Fundamental concepts in Program design:
      • structuring and modularization
        • decomposing programs into small modules
      • abstraction
        • separation of the interface from the implementation
      • Efficient data structures.
      • efficient algorithms.
    • A module is a collection of related
      • data
      • operations

      packaged into one (compilation) unit.

    • A module has two parts:
      • public : visible by the client
      • private : invisible outside the module
    • A module exports its public parts.
    • A client imports the public parts of a module.
    • A module interface diagram shows the module’s exported items:

    • Modules provide the means for:
      • encapsulation or information hiding
      • Locality of information and design
      • off-the-shelf components
        • saves money
        • produces more reliable and efficient software
    • Modules should be:
      • highly cohesive ( components are highly related)
      • loosely coupled
      • general enough
    • In C++, a module is represented by a pair of files:
      • a header or specification file
        with declarations of public components
      • a source or implementation file
        with definitions of private and public components
    • A client needs only to include the header file.
    • Examples:
      • Each C++ library is a module.
      • The bank module in the next section

    1.3 Functional Design

    • Also known as Top-Down design and Stepwise Refinement
    • Problem decomposition is based on the operations (tasks) involved
    • Problem is repeatedly decomposed into smaller tasks until the fimal tasks are simple functions
      • with well defined interface
      • hiding local decisions
    • Focuses on functional abstraction
      • End result: a set of tasks
      • used for the design of the module operations

    1.3.1 A Bank-Account Example

    Problem Description

    • The bank wants a program that can handle the accounts of its customers. The program should allow the customers to open an account, deposit and withdraw money and get their balance.

    Requirements

    • A customer can open an account, deposit and withdraw money and get their balance
    • Each account belongs to a single customer
    • A customer may have many accounts
    • Each account has a unique id set by the bank
    • A customer has to supply the account id to use their account
    • If a customer attempts to withdraw more money than in the account, the operation is canceled.
    • The balance of any account should always be >= 0.
      . . .

    Functional Design

    • We may split the tasks into:
      • Customer Operations
      • Bank Operations
    • Customer Operations may include:
      • deposit into an account
      • withdraw from an account
      • get the balance of an account
    • Bank Operations may include
      • open a new account
      • close an account
      • etc.
    • May decide to keep  three modules:
      • customer- operations module
      • bank-operations module
      • bank-driver the main driver of the program

    1.4 Object-Oriented Design

    • problem decomposition is based on data and their operations
    • a problem is decomposed into a collection of interacting objects
    • end product: a set of classes of objects (modules)
    • focuses on data abstraction
    • provides means for a natural program modularization
      • Classes / instantiation
      • inheritance
      • polymorphism

    1.4.1 OO Design for the Bank-Account Example

    • Three modules:
      • Account class handling a single account
      • Bank (or AccountDB)class maintaining the collection of all accounts
      • bank-driver the main driver for the system
    • To complete the design, for each class we should define
      • Its public data
      • Its public operations
      • its invariants.

    Sample design for class: Account

    Data

    • none

    Operations

    • Account ( accountID :integer or string , customerName: string, initialBalance: real) creates a new account
    • deposit ( amount: real ) returns nothing
    • withdraw ( amount: real ) returns nothing
    • getBalance ( no arguments) returns account balance
    • getID ( no arguments) returns account id
    • getName( no arguments) returns account name

    Class Invariants

    • assigned(account id, customer name, balance) and account balance >= 0

    Sample design for class: AccountDB

    Data

    • none

    Operations:

    • AccountDB (max-size: integer) creates a new collection with 0 accounts in it.
    • openAccount ( customer_name: string, initial_balance:real )
    • closeAccount ( accountID: string or integer )
    • deposit ( accountID: string or integer , amount:real ) returns real
    • withdraw ( accountID: string or integer , amount:real ) returns real
    • getBalance ( accountID: string or integer) returns real

    Class Invariants:

    • at most max-size number of accounts are valid at any time
    • the id of a new account is different from the id of any old account
    • an account does not exist unless it is opened
    • an opened account is valid until it is closed

    Implementation

    The account class and account's test driver are implemented in account.C and account-dr.C.


    1.5 Program Testing

    • Module Testing Plan
      • Is specified when the module is designed
      • contains the test cases for the module
    • Each test case shows
      • Input values
      • expected results
    • To determine the test cases
      • Partition the input into equivqlent partitions
      • for each partition pick
        • representative values
        • boundary values exceptional values
    • Example: Suppose a module has two positive integer inputs x and y. The test cases are:
      • x>0, y>0
      • x=0, y>0
      • x>0, y=0
      • x=0, y=0

    Example: Testing Plan for Account

    CASE 1: Typical account

    • Create an account with typical components and display the result.
    • Apply all public op’s and display the results.
    • Create an account with balance 0 and  null string for name and display the result.
    • Apply all public op’s and display the results.

    CASE 2: Negative balance

    • Attempt to create an account with balance – 50. It should set balance to 0.

    CASE 3: Overdraft

    • Attempt to withdraw from the typical account an amount greater than its balance. Withdrawal should be aborted and an error message should be printed.

    CASE 4: Negative amount

    • Attempt to deposit or withdraw a negative amount. Operation should be aborted and an error message should be printed.

    Copyright (C) 2000-2005, The University of British Columbia

    Description of C++ Keywords

    Source: The University of British Columbia

    asm (seldom used)

    • Used to insert assembly language commands directly into the code. This function is very tricky to use even for professional programmers and can cause portability issues.

      asm(“instruction”);


    auto

    • Used to declare local variables but is purely optional.

      auto int i = 5;

      The previous declaration thus has identical meaning to the following declaration.

      int i = 5;


    bool (C++ only)

    • Used to declare a Boolean logic variable; a variable that can have the value true or false. This variable type is normally 8 bits (1 byte) long.

      bool t = true;


    break

    • Used to break out of a loop independant of the loop condition. Also, used to finish a switch statement, keeping the program from “falling through” to the next case in the code.
      while(x < 100)
      {
      	if(x < 0)
      	     break;
      	cout << x << endl;
      	x++;
      }
      

    case

    • Used as a label to declare a single test in a switch statement.
      case 1: command1;
              command2;
              break;
      

    catch (C++ only)

    • Used to handle exceptions generated by a throw statement.
      catch(const char* e)
      {
      	//handle exception
      }
      

    char

    • Used to declare character variables. This variable type is normally 8 bits (1 byte) long.

      char c = ‘h’;


    class (C++ only)

    • Used to define a new class. Members of the class are private by default unless listed under the protected or public labels.
      class class-name : inheritance-list
      {
      	public:
      		public-members-list;
      	protected:
      		protected-members-list;
      	private:
      		private-members-list;
      } object-list;
      
      • class-name is the name of the class that is being created.
      • inheritance-list is the optional list of classes inherited by the new class.
      • public-members-list is the list of public members of the class.
      • protected-members-list is the list of protected members of the class.
      • private-members-list is the list of private members of the class.
      • object-list is an optional list used to immediately instantiate 1 or more instances of the class.
      class Date
      {
      public:
      	void display();
      
      private:
      	int day;
      	int month;
      	int year;
      }
      

    const (C++ only)

    • Used to tell the compiler that a certain object should not be modified once it has been initialized.

      const int i = 5;

    • Used to declare a pointer so that the value of the pointer (the memory location to which it points) can be modified, but the data in the memory location cannot be changed.

      const int* j = new int(3);

    • Used to declare a pointer so the that value of the pointer (the memory location to which it points) cannot be modified, but the data in that memory location can be changed.

      int* const j = new int(3);

    • Used to declare a member function that does not modify the object’s state, meaning that it should be used for methods like print so that data in the object cannot be changed accidentally. If and attempt is made to modify the object in any way, a compilation error will be triggered.

      void print(bool verbose) const;


    const_cast (C++ only, seldom used)

    • Used to remove the const protection on a variable as long as the original variable was not declared as a const. The target type must be the same as the original type.

      const_cast (object);


    continue

    • Used to jump to the next iteration of a loop. The following example will print out all of the numbers from 1 to 20 except for 10.
      for(int i = 0; i < 21; i++)
      {
      	if(i == 10)
      	    continue;
      	cout << i << endl;
      }
      

    default

    • Used as a label to declare the default case of a switch statement.
      case 1:  command1;
               command2;
               break;
      
      default: command1;
               command2;
               break;
      

    delete (C++ only)

    • Used to free memory allocated for a pointer back to the heap. The argument should have been allocated through a call to new. To delete an array, use the following form of delete: delete[]
      delete p;
      delete[] pArray;

    do

    • Used to create a loop that is executed at least once. The terminating condition is tested at the end of the loop.
      do
      {
      	cout << "hello worldn";
      	i++;
      } while(i < 5)
      

    double

    • Used to declare a double-precision floating-point type variable. This variable type is normally 64 bits (8 bytes) long.

      double d = 12.55;


    dynamic_cast (C++ only, seldom used)

    • Used to cast from one type to another with a check performed at runtime. If the cast types are incompatible, NULL is returned.

      dynamic_cast (object);


    else

    • Used for an alternative condition in an if statement.
      if(i == 1)
      {
      	// do something
      }
      else
      {
      	// do something else
      }
      

    enum

    • Used to define an enumerated type. Each of the names in the name-list are given a distinct value. This should be used in place of defining variables using “magic numbers” (eg. int Monday = 0, int Tuesday = 1, etc).
      enum name {name-list};
      • name is the name of the enumerated type that was created
      • name-list is the list of names of the elements
      enum weekdays {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};

    explicit (C++ only)

    • Used to make sure that a constructoor is only used for the creation of new values and not used for the implicit conversion between two different types. It will only be be used if the initialization exactly matches the call to that constructor. This keyword is only needed with one-argument constructors.
      class vector
      {
      	...
      	explicit vector(int v);
      	...
      }
      

      Using this keyword, some mysterious errors can be caught by the compiler like the following:

      vector v(10);
      v = 5; // error, meant to write v[0] = 5
      

      The problem in this code if the explicit keyword was not specified is that the v = 5 statement would invoke the constructor, creating a new vector of size 5 and destroying the old one.


    export (C++ only, seldom used)

    • Used to export a template to other modules. Most compilers require template definitions to be explicitly specified in the header file since the Comeau C++ compiler seems to be the only compiler that supports this keyword.
      // In MyTemplateFunction.h
      template
      void myTemplateFunction(const T &t1);
      
      // In MyTemplateFunction.cpp
      export template
      void myTemplateFunction(const T &t1)
      {
      	...
      }
      

    extern

    • Used to inform the compiler of variables and functions that are defined outside of the current scope or module. Variables defined as extern will not have space allocated for them since they are defined elsewhere.

      extern char* message;


    false (C++ only)

    • Used to represent the Boolean value false.

      bool b = false;


    float

    • Used to declare a single-precision floating-point type variable. This variable
      type is normally 32 bits (4 bytes) long.

      float f = 3.5;


    for

    • Used to create a loop that is meant to initialize, test and update a variable.
      for(int i = 0; i < 10; i++)
      {
      	cout << "i is " << i << endl;
      }
      

    friend (C++ only)

    • Used to allow another class or function to have access to the private features of that class.
      friend void print(bool verbose);
      friend class Vector;

    goto (seldom used)

    • Used to jump to another location in a function specified by a label. This is generally considered harmful and should not be used unless necessary.
      goto labelA;
      ...
      labelA:

    if

    • Used to create a conditional branch statement so that different code can be executed under different conditions. The conditions are evaluated in the order that they appear in the code.
      if (i < 0)
      {
      	cout << "i is negative";
      }
      else if(i == 0)
      {
      	cout << "i is 0n";
      }
      else
      {
      	cout << "i is posativen";
      }
      

    inline (C++ only)

    • Used to tell the compiler that the function an its body are inserted into the calling code meaning that it has to expand the function in-place instead of just insert a call to the function. Functions that have static data, loops, switches or recursive calls cannot be inlined.
      inline int test(int A)
      {
      	...
      }
      

    int

    • Used to declare an integer type variable. This variable type is normally 32 bits (4 bytes) long.

      int i = 3;


    long

    • Used as a data type modifier for the int and double types to indicate that they may have more bytes then the type has available. This variable type is normally 32 or 64 bits (4 or 8 bytes) long.

      long int i = 100000;


    mutable (C++ only)

    • Used to specify that it is a data field that can be modified even if another part of the data is declared const.

    namespace (C++ only)

    • Used to create a new scope. Once created, the namespace must be refered to either directly or with the using keyword.
      	namespace CartoonNameSpace
      	{
      		int HomersAge;
      
      		void incrementHomersAge()
      	  	{
      			HomersAge++;
      		}
      	}
      	int main() {
      		...
      		CartoonNameSpace::HomersAge = 39;
      		CartoonNameSpace::incrementHomersAge();
      		cout << CartoonNameSpace::HomersAge << endl;
      		...
      	}
      

    new (C++ only)

    • Used to allocate a new block of memory for the given type from the heap, and return a pointer to that block of memory. Allocating arrays can be done by providing the size of the array in square brackets.
      pointer = new type;
      pointer = new type( initializer );
      pointer = new type[size];
      • pointer is a pointer to the type that you want to allocate the memory for
      • type is the type of the item that is to be stored in the memory that is allocated
      • initializer is the optional information for the constructor
      • size is the size of the array to create

    operator (C++ only)

    • Used to specify that you are overloading an operator.
      	return-type class-name::operator#(parameter-list)
      	{
      		...
      	}
      
      • return-type is the return type for the function
      • class-name is the name of the class that the operator is a part of. If it is not part of a class, this can be left out along with the ‘::.
      • # is the operator that is to be overloaded, such as ‘++’. You cannot overload the #, ##, ., :, .*, or ? tokens.
      • parameter-list is the list of parameters that the operator will take. For unary operators, parameter-list should be empty, and for binary operators, parameter-list should contain the operand on the right side of the operator (the operand on the left side is passed as this).
    • There are special conventions for some operators, such as the unary ++ and — operators.
      • The unary ++ operator has both prefix (++object and postfix (object++) versions.
      • 	return-type class-name::operator++()
        	{
        		...
        	}
        

        overloads the prefix version (the value returned is the value of the object after it is incremented, so this is also known as the pre-increment version because the increment takes place before the value is returned). There is no parameter specified because ++ is a unary operator.

      • 	return-type class-name::operator++( int )
        	{
        		...
        	}
        

        overloads the postfix version (the value returned is the value of the object before it is incremented, so this is also known as the post-increment version because the increment takes place after the value is returned). The parameter int is not really a parameter (++ is still a unary operator) but is there soley to differentiate the prefix and postfix versions.


    private (C++ only)

    • Used within a class declaration to specify features of that class that can only be accessed by itself and its friends.
      class Date
      {
      public:
      	void display();
      
      private:
      	int day;
      	int month;
      	int year;
      }
    • Used to inherit a base class privately, which causes all public and protected members of the base class to become private members of the derived class.
      class AlarmClock : private Clock
      {
      public:
      	void display();
      
      }

    protected (C++ only)

    • Used within a class declaration to specify features of that class that are private to its own class, but can be inherited by a derived class.
      class Date
      {
      public:
      	void display();
      protected:
      	int day;
      	int month;
      	int year;
      }
    • Used to inherit a base class, which causes all public and protected members of the base class to become protected members of the derived class.
      class AlarmClock : protected Clock
      {
      public:
      	void display()
      }

    public (C++ only)

    • Used within a class declaration to specify features of that class that are accessable to everyone.
      class Date
      {
      public:
      	void display();
      protected:
      	int day;
      	int month;
      	int year;
      }
    • Used to inherit a base class publically, which causes all public and protected members of the base class to become public and protected members of the derived class.
      class AlarmClock : public Clock
      {
      public:
      	void display()
      }

    register

    • Used to reccommend that a varibale be placed into a processor register so that it is optimized for speed but the compiler is not obliged to do so. This keyword is rarely used anymore since compilers have become better than programmers at optimizing code.

    reinterpret_cast (C++ only), seldom used

    • Used to change one data type in a non-portable way. It is normally used to cast between incompatible pointer types.

      reinterpret_cast (object);


    return

    • Used to cause the execution to jump from the current function back to the one that called it. An optional value can be returned but the function must specify the type that it will return.
      return;
      return 5;

    short

    • Used as a data type modifier for the int type to indicate that there may be less bytes then the type has available. This variable type is normally 16or 32bits (2 or 4bytes) long.

      short int i = 5;


    signed

    • Used to specify that the number type provided could potentially be negative, so it must be stored in a different format. This is the default representation that is chosen by most compilers if either signed or unsigned is not specified.

      signed int i = -12;


    sizeof

    • Used to return the size of the object (in bytes) that is passed to it.
      int i = 5;
      int size = sizeof( i );

    static

    • Used outside any function or class as a qualifier to a variable declaration makes the scope of the variable the file in which the variable is declared, and the extent is permanent (i.e., it is in the static segment).

      static int i;

    • Used inside a function as a qualifier to a variable declaration makes the scope of the variable the function in which the variable is declared, and the extent is permanent (i.e., it is in the static segment).
      void foo()
      {
      	static int i;
      }
    • Used inside a class as a qualifier to a variable declaration makes the scope of the variable the class in which the variable is declared, and the extent is permanent (i.e., it is in the static segment).
      class bar
      {
      	static int i;
      }
    • Used outside any class as a qualifier to a function declaration makes the scope of the function the file in which the function is declared. As with all functions, the instructions for the function are in the code segment.
      static void foo()
      {
      }
    • Used inside a class as a qualifier to a function (method) declaration makes the scope of the function the class in which the function is declared (as with all methods), and the instructions for the method are in the code segment (as for all functions). What is different is that a static method is invoked without requiring an object, using the qualifier syntax class::staticMethod( parameters ), although it can also be invoked on an object in the class in the usual way. Because no object is associated with a static method, only static member variables and other static member functions can be invoked by a static method.
      class bar
      {
      	static void foo();
      }

      Note: A method in a class cannot be both “static” and “virtual”. The reason for this is that virtual functions have to know the object to which they apply (because of polymorphism) but static methods are not applied to an object.


    static_cast (C++ only, seldom used)

    • Used for a normal conversion between types. No runtime checking is performed.

      static_cast (object);


    struct

    • Used to create a structure like a class, but the members are public by default instead of private. In C, structs can only contain data, cannot have inheritance and cannot have data with different visibilities.
      struct struct-name : inheritance-list
      {
      		public-members-list;
      	protected:
      		protected-members-list;
      	private:
      		private-members-list;
      } object-list;
      • struct-name is the name of the struct that is being created.
      • inheritance-list is the optional list of structs inherited by the new struct.
      • public-members-list is the list of public members of the struct.
      • protected-members-list is the list of protected members of the struct.
      • private-members-list is the list of private members of the struct.
      • object-list is an optional list used to immediately instantiate 1 or more instances of the struct.
      struct Date
      {
      	int day;
      	int month;
      	int year;
      }

    switch

    • Used to test an expression of an integer value against many constant integer values and is commonly used to replace large if()…else if()… statements. Break statements are required between each case statement, otherwise execution will “fall-through” to the next case statement. The default case is optional. If provided, it will match any case not explicitly covered by the preceding cases in the switch statement.
      char keystroke = getch();
      switch( keystroke )
      {
      	case 'a':
      	case 'b':
      	case 'c':
      	case 'd':
      		KeyABCDPressed();
      		break;
      	case 'e':
      		KeyEPressed();
      		break;
      	default:
      		UnknownKeyPressed();
      		break;
      }
      

    template (C++ only)

    • Used to create generic functions and can operate on data without knowing the nature of that data. They accomplish this by using a placeholder data-type for which many other data types can be substituted.
      template void genericSwap( X &a, X &b )
      {
      	X tmp;
      
      	tmp = a;
      	a = b;
      	b = tmp;
      }
      

    this (C++ only)

    • Used as a pointer to the current object. All member functions of a class have this pointer.

      this.print();


    throw (C++ only)

    • Used together with try and catch statements to create an exception handling system. Throw is used to generate an exception.
      try
      {
      	cout << "Before throwing exception"<< endl;
      	throw 42;
      	cout << "Shouldn't ever see this"<< endl;
      }
      catch( int error )
      {
      	cout << "Error: caught exception " << error << endl;
      }
      

    true (C++ only)

    • Used to represent the Boolean value true.

      bool b = true;


    try (C++ only)

    • Used to attempt to execute exception-generating code.
      try
      {
      	cout << "Before throwing exception" << endl;
      	throw 42;
      	cout << "Shouldn't ever see this" << endl;
      }
      catch( int error )
      {
      	cout << "Error: caught exception " << error << endl;
      }

    typedef

    • Used to create a new type from an existing type.

      typedef int seconds;


    typeid (C++ only, seldom used)

    • Used to get a reference to a type_info object that describes the object it was passed.

      typeid(object);


    typename (C++ only)

    • Used to describe an undefined type or in place of the class keyword in a template declaration.

    union

    Used to create multiple data fields that will occupy the same memory location.

    union Data
    {
    	int i;
    	char c;
    };
    

    unsigned

    • Used to specify that the int or char provided can only be posative and can therefore contain a larger number since there is no need to worry about representation of negative numbers.

      signed int i = -12;


    using (C++ only)

    • Used to import a namespace into the current scope.

      using namespace std;


    virtual (C++ only)

    • Used to create virtual functions that can be overridden by derived functions.
      • A virtual function indicates that a function can be overridden in a subclass, and that the overridden function will actually be used.
      • When a base object pointer points to a derived object that contains a virual function, the decision about which version of that function to call is based on the type of object pointed to by the pointer, and this process happens at runtime.
      • A base object can point to different derived objects and have different versions of the virual function run.

      virtual void print();

    • Used to create a pure virtual function which is a virtual function that must be overriden by some derived class.

      virtual void print() = 0;

    • Note: A method in a class cannot be both “virtual” and “static”.

    void

    • Used to denote functions that return no value.
      void print()
      {
      	cout << "printn";
      }
      
    • Used to create generic variables which can point to any type of data.
      void *p = 5;
      
    • Used to declare an empty parameter list.
      void print( void )
      {
      	cout << "printn";
      }

    volatile

    • Used to inform the compiler that the variables value can change in unexpected ways (i.e. through an interrupt), which could conflict with optimizations that the compiler might perform, so therefore the compiler will not optimize these variables.

      volatile Date d;


    wchar_t

    • Used to declare a wide character variable. This variable type is normally 16 bits (2 bytes) long.

      wchar_t c = ‘c’;


    while

    • Used as a looping construct that will evaluate a list of statements as long as the condition is true. Note: if the condition starts off as false, the list of statements will never be executed. (You can use a do loop to guarantee that the list of statements will be executed at least once.)
      bool done = false;
      while( !done )
      {
      	ProcessData();
      	if( StopLooping() )
      	{
      		done = true;
      	}
      }

    Copyright (C) 2000-2005, The University of British Columbia

    List of C++ Keywords and Operators

    Keywords
    asm do if return typedef
    auto double inline short typeid
    bool dynamic_cast int signed typename
    break else long sizeof union
    case enum mutable static unsigned
    catch explicit namespace static_cast using
    char export new struct virtual
    class extern operator switch void
    const false private template volatile
    const_cast float protected this wchar_t
    continue for public throw while
    default friend register true
    delete goto reinterpret_cast try


    Operators
    + ++
    * / %
    & && ||
    < <= ,
    > >= ;
    = !=
    ? : ::
    >> << #
    () [] {}
    ! ^ ˜
    . -> ->*

    C++ Vocabulary

    Comment – text written in the source code that compiler ignores and is mainly meant for humans to read for showing how the program works

    Conditional – decides which set of actions that the program will perform depending on a programmer specified condition

    Constant – a special kind of variable whose value cannot change during program execution

    Control structure – refers to the order in which the individual statements, instructions, or function calls of an imperative or a declarative program are executed or evaluated

    Data structure – ways that data can be organized within a program

    Data type – different varieties that data can be represented within a program

    Directive – used to describe how the parts of a program are to be used to built a complete program

    Identifier – programmer-specified name; a sequence of characters associated with and used to access a variable, particular object, class or struct, or function. Every identifier has a scope

    Iteration – a single execution of a set of instructions that are to be repeated; “the solution took hundreds of iterations”

    Keyword – a word that has particular meaning to the programming language and describes how a program is to work

    Literal – a notation for representing a fixed value in source code. For example, the literal 12 represents the integer value “twelve”, “Morning” represents the character string value “Morning” and true represents the Boolean value true. They describe the type of value data has

    Naming structure – rules for how data values, variables, operators, and other language constructs are referred to within the language

    Operator – special symbols that specify how data is to be manipulated. For example, a ++ is an operator

    Pragma – data embedded in source code by programmers to indicate some intention to the compiler

    Sequential execution – execution by a computer if instructions in a program, performed in the sequence established by a programmer

    Subprogram – a part of the code that is reused in various parts of the program

    Variable – remembers data values for use within a program

    Variable declaration – defining a variable’s type and name (identifier)

    Cancelling Stuck Print Jobs

    Sometimes when you try to cancel print jobs that are in progress, Windows will try to cancel it, but it will get stuck. Here is how to delete the print job.

    1. Start > Run > services.msc or alternatively, type services.msc in the find box in the start menu
    2. Look for the Print Spooler and stop the service
    3. Once you stop the service, open the folder “C:WindowsSystem32SpoolPrinters”
    4. Find the files with the date and time stamp of your print job and delete the files
      • if you are trying to delete a print job on a printer that is not directly connected to your computer, but on a network, the host computer may have to turn off their print spooler in order to delete the files
    5. Retry printing

    Usually for me, restarting the Print Spooler works well enough, but if need be, deleting the print job files works too.

    Portrait of an ISTJ

    I just read a personality profile of an ISTJ, which happens to be my personality type, and that article basically pointed out so many things about me.  I’m going to quote a lot of things from the article I just read in a bit.

    Full article here (http://www.personalitypage.com/ISTJ.html)

    This is what the letters stand for:

    I – Introvert
    S – Sensing
    T – Thinking
    J – Judgment

    Quote #1

    As an ISTJ, your primary mode of living is focused internally, where you take things in via your five senses in a literal, concrete fashion. Your secondary mode is external, where you deal with things rationally and logically.

    That’s exactly what I do.  I have huge troubles with metaphors and anything abstract.
    Quote #2

    ISTJs tend to believe in laws and traditions, and expect the same from others. They’re not comfortable with breaking laws or going against the rules. If they are able to see a good reason for stepping outside of the established mode of doing things, the ISTJ will support that effort. However, ISTJs more often tend to believe that things should be done according to procedures and plans. If an ISTJ has not developed their Intuitive side sufficiently, they may become overly obsessed with structure, and insist on doing everything “by the book”.

    I do not like breaking tradition because there was always a reason why they are set.  If I’m able to identify this reason and agree with it, I would be very comfortable living with those traditions.  It’s also true I like doing this by the book, but at the same time, I see a lot of things as situational, meaning that my actions are based on whats happening around me.

    Quote #3

    The ISTJ is extremely dependable on following through with things which he or she has promised. For this reason, they sometimes get more and more work piled on them. Because the ISTJ has such a strong sense of duty, they may have a difficult time saying “no” when they are given more work than they can reasonably handle. For this reason, the ISTJ often works long hours, and may be unwittingly taken advantage of.

    Total truth.  I remember always agreeing to take on more work at my Co-op job if it was needed of me.  I also totally remember working on homework or other work for 15 hours straight.

    Quote #4

    Under stress, ISTJs may fall into “catastrophe mode”, where they see nothing but all of the possibilities of what could go wrong. They will berate themselves for things which they should have done differently, or duties which they failed to perform. They will lose their ability to see things calmly and reasonably, and will depress themselves with their visions of doom.

    Totally, and that makes me a pessimist

    avast! Antivirus Settings for Scanning MSN File Transfers

    In Windows Live Messenger, “ashQuick.exe” is the virus scan program for file transfers.  It is located in the avast! installation directory.

    Infinite Loop

    Apparently this gives an infinite loop:

    [code]#include
    using namespace std;

    int main() {
    int i = 0;
    for ( ; ; ) {
    cout << i++;
    cout << "n";
    }
    return 0;
    }[/code]

    Ideal Diodes and Circuit Analysis

    So today I started the problem set for my course on electronic circuits and the first item in the curriculum was ideal diodes.  Prior to the lesson I had already known that diodes only allowed the flow of current in one direction and blocked current flow in the other.  What I didn’t know were the analysis techniques used for these non-linear components.  While I was doing this problem set, it was surprising how much I had forgotten over the past eight months.

    Concept

    I was given the circuit shown below (from Microelectronic Circuits 6th Edition by Sedra and Smith):

    I was asked for the voltage of the output terminal and the current flowing through the diode.  Finding the current was easy, but I didn’t quite get the voltage.  I thought to myself, “from what two points do I measure the potential difference?”, because after all, voltage measurements are always taken relative to two points.  It took me the longest time before I could just use ANY two points and the measure the voltage.

    What I figured is that, for part a, since the diode is in forward bias, the diode will act as a short circuit.  I then can say that V – (-5) = 0, since the voltage difference along a short is 0.  From there, I can easily determine that V = -5.  I can apply that same logic to the other three.

    Nodal Analysis

    I was given the circuit shown below (from Microelectronic Circuits 6th Edition by Sedra and Smith):

    From class, I remember the professor saying that since we cannot tell right away which diodes are on and off, we can only make an assumption about the states of the diodes and then apply the usual analytical techniques.  In the event that the result is unreasonable, we know that our assumption wrong.  I made my assumptions, but afterward, I didn’t know where to go next.  I had forgotten how to analyze these circuits.

    Later, I realized that I could use nodal analysis.  Since I assumed the two diodes in part a were both on, I replaced them with short circuits.  I used the intersection right before the current splits as my node.  For part a, the current into the node was 3 V/5 kΩ = 0.6 mA.  The current leaving was some unknown current for diode 1, and a current for diode 2.  I could determine the current of diode 2 by taking the potential difference between the node and the -3 V output and dividing that by the resistance in the path.  The result was (0 – (-3))/ 10 kΩ = 0.3 mA.  From the nodal analysis equation 0.6 mA = current from diode 1 + 0.3 mA, the current from diode 1 is 0.3 mA.  And as for the voltage V, the potential difference between V and the -3 V output is equal to the voltage across the resistor, (0.3 mA)(10 kΩ) = V – (-3).  Therefore, V = 0.  Alternatively, I can use the potential difference between the node and the output, which equals zero, thus yielding the same result.

    Boolean Logic

    The next issue I had was determining the Boolean outputs of a diode logic circuit.  Again, the picture below is from Electronic Circuits 6th Edition by Sedra and Smith.

    The issue I had here is that I did not know current sources have no voltage if there is no current running through them.  Looking back that sounded pretty intuitive.  Finding all possible combinations of inputs A and B for this logic circuit, we get the truth table below:

    A B X Y
    0 0 0 0
    1 0 0 1
    0 1 0 1
    1 1 1 1

    The outputs of X reveal an AND gate.  Setting A or B to a logic 0 in (a) will cause current to flow through that path.  The potential difference X – A or X – B (depending which one was set to 0), will yield 0, thus the output X will be zero as well.  When A and B are both set to logic 1, it causes the diodes to go into reverse bias, and node X will be powered by the current source.

    The outputs of Y reveal an OR gate.  Setting A or B in (b) to have different inputs, either 1,0 or 0,1, will cause the diode to be in forward bias for the input that has the logic 1.  For the input with logic 0, the diode will in reverse bias.  Since one of the diodes is on, current will flow and output Y will yield a logic 1.  In the case of both diodes being off, no current will flow, thus causing output Y to yield logic 0.

    Other Notes

    In the case of multiple parallel diodes in the same direction, if one of them is on, chances are they are all on (provided that the voltage across them is positive).  However, there may be a case where one parallel diode will want to flow into the other because of a greater voltage difference.  For example, if there were two parallel diodes, one with a 3V input and the other with a 2 V input both going to the same node, current from the 3 V input will want to flow into the diode connected to the 2 V input.  This will cause a reverse bias in the diode connected to the 2 V input, thus turning it off.

    There is also another case where there are parallel diodes with different output voltages.  If current is flowing toward it, they will all be on, so they will all be a short circuit.  Which path will the current go to?  The path with the larger current.

    Windows 7 GodMode

    Windows 7 has this cool feature called the “GodMode” that allows you to perform many maintenance tasks such as defragging the hard drive, looking at the windows event logs, folder options, etc.  From what I can tell, you can change most if not all of the Windows settings from this one place.  You can even add hardware with it.  Scroll down to see how to do it.

    Here’s a pic

    To get the GodMode, create a folder somewhere and name it:

    GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}

    I have no idea how people found out about this, but we can still enjoy it.  Now you can open it up and see what kind of stuff you can do on it!

    © 2017 Henry Poon's Blog

    Theme by Anders NorénUp ↑