C++ - Category Archive


Aug 22
Friday

Advanced Control Flow - Switch Statements

Filed under Programming & Development/C++

A switch statement allows you to control the flow of your program similar to if and else statements, but can be easier for the user to understand.

The Switch Statement

The structure of a switch statement is the following:

switch(expression) {
    case <constant_expression>  :
    statements
    break;

    case <constant_expression> :
    statements
    break;

    //More cases…

    default :
    statements
}

Continue…

All entries filed under C++


  • Command Line Arguments
    no responses - Posted 08.02.08

    Command Line Arguments allow the user to run the program thruogh the terminal as well as pass in arguments into your program in one line. Most common use of command line arguments, are to pass in “strings” that represent file names from which you are going to read data from.
    Format of Command Line Arguments
    This is [...]

    continue
  • Advanced Control Flow - The Do While Loop
    no responses - Posted 08.02.08

    The Do While Loop is a loop that guarantees execution of the statements within the loop at least once.
    The structure of the Do While Loop
    Below is the structure:
    do {
    //statements
    } while ( condition(s) ) ;
    What is this useful for? In order to execute a set of commands at least once.

    continue
  • Introduction to Functions
    no responses - Posted 07.25.08

    Functions allow you to perform the same operation on many inputs with one simple call.
    Why a function anyways?
    First of all, let’s see how we’d perform a certain task without one. How would we print out the entire contents of a vector each time we modified it? Let’s show how we would do it once. [...]

    continue
  • Simple Data Structure - The Vector
    no responses - Posted 07.18.08

    The vector is a simple data structure that allows you to store values with the same data type in one container.
    Introduction
    Without the use of a data structure, how would you store multiple variables? Let’s say we wanted to store 5 names into strings. How would this be done?

    string name1,name2,name3,name4,name5;
    cin >> name1 >> name2 >> name3 [...]

    continue
  • Advanced Control Flow - While Loop
    no responses - Posted 07.11.08

    Introducing the while loop with an example and several exercises. Meant for beginners.

    continue
  • Advanced Control Flow - For Loop
    no responses - Posted 07.09.08

    Introducing a basic for loop with a detailed break down of every line of code that makes this loop. Practice problems are also provided.

    continue