# MySQL-Front Dump 2.2 # # Host: localhost Database: CFX #-------------------------------------------------------- # Server version 3.23.52-nt # # Table structure for table 'cat' # CREATE TABLE `cat` ( `CatId` int(11) NOT NULL default '0', `Name` varchar(50) NOT NULL default '', `Description` varchar(255) default NULL, `DiffLevel` int(11) NOT NULL default '0', `ParentCatId` int(11) NOT NULL default '0', `LangId` int(11) NOT NULL default '0', `Moderated` tinyint(1) NOT NULL default '0', `Question` varchar(255) default NULL, `Level` int(10) default '0', PRIMARY KEY (`CatId`), KEY `CatId` (`CatId`) ) TYPE=MyISAM; # # Dumping data for table 'cat' # INSERT INTO cat VALUES("1","The C++ Language","An OOP Language","2","0","1","1","What is annother OOP Language?","0"); INSERT INTO cat VALUES("2","Java","Another OOP Language","2","0","2","1","What is another OOP language?","0"); INSERT INTO cat VALUES("8","Linked Lists","Storing structures in a consecutive list.","2","4","1","1","How do I store structures into a list?","2"); INSERT INTO cat VALUES("4","Dynamic Memory","Creating new data at runtime.","3","1","1","1","How do I create new data at runtime?","1"); INSERT INTO cat VALUES("9","Dynamic Arrays","Creating new arrays at runtime","2","4","1","1","How do I create new array objects while my program is running?","2"); INSERT INTO cat VALUES("10","Old String Examples","Storing consecutive chars into an object.","2","41","1","1","How do I store words?","3"); INSERT INTO cat VALUES("11","AverageGrades Examples","?","1","37","1","1","?","3"); INSERT INTO cat VALUES("15","Store Words","?","1","4","1","1","?","2"); INSERT INTO cat VALUES("13","Maze Examples","?","1","37","1","1","?","3"); INSERT INTO cat VALUES("14","breakContinueSwitch","Uses of break continue switch","1","51","1","1","How can I control the flow of a program?","3"); INSERT INTO cat VALUES("41","Strings","A string in C++ is an arrray of characters. Ther is no sepaate string data type in C++, although one can build a custom string data type, or use a string datatype from a library like STL. More on this later.","1","35","1","1","","2"); INSERT INTO cat VALUES("51","Selection","Undefined","1","50","1","1","","2"); INSERT INTO cat VALUES("52","Loops","Undefined","1","50","1","1","","2"); INSERT INTO cat VALUES("36","Datatypes & Variables","A datatype ( eg : integer, float ) is types built into the language, that the programmer can use. For eg, to add to numbers, you use two variables of the integer datatype.","1","35","1","1","","2"); INSERT INTO cat VALUES("50","Control Structures","Undefined","1","1","1","1","if, switch, do, while, break, continue","1"); INSERT INTO cat VALUES("49","Operators","Trying to add 2 numbers? making a complex calculation? comparing results? Operators can do that!","1","1","1","1","+ - * / % < > == ...","1"); INSERT INTO cat VALUES("32","Sams C++ Examples","undefined","1","0","7","0","Some examples","0"); INSERT INTO cat VALUES("33","Introduction"," This is an example by example base for the C++ programming language. All the code in these examples will run on Unix svr4. Report any probems to Sam at sam@muffin.ai.uic.edu . Compiling on unix: at the command prompt($), type: g++ -c ","1","1","1","1","What does a basic program look like?","1"); INSERT INTO cat VALUES("35","Datatypes, Variables, & Arrays","Undefined","1","1","1","1","undefined","1"); INSERT INTO cat VALUES("37","Arrays","Imagine wanting to store 10 phone numbers. You could use 10 pieces of paper to write them each in, or you could a book with papers to write them in.","1","35","1","1","","2"); INSERT INTO cat VALUES("38","Pointers. aha!","Imagine travelling in London. Youre on your way across farm lands, trying toreach this castle. You come across a sign that says, Castle ->that-a-way. And you move in that direction, eventually reaching the castle. The sign that you saw along the way was","2","35","1","1","","2"); INSERT INTO cat VALUES("53","Jumps","Undefined","1","50","1","1","","2"); INSERT INTO cat VALUES("54","Functions","Undefined","1","1","1","1","","1"); INSERT INTO cat VALUES("57","Classes","Undefined","1","1","1","1","","1"); INSERT INTO cat VALUES("66","testing","undefined","2","60","8","0","undefined","2"); INSERT INTO cat VALUES("76","temp","undefined","1","0","9","0","undefined","0"); INSERT INTO cat VALUES("77","templates","generic classes","1","57","1","0","","2"); INSERT INTO cat VALUES("85","Miscellaneous","Miscellaneous examples","2","1","1","0","undefined","1"); # # Table structure for table 'ex' # CREATE TABLE `ex` ( `ExId` int(11) NOT NULL default '0', `DiffLevel` int(11) NOT NULL default '0', `Moderated` tinyint(1) NOT NULL default '0', `LangId` int(11) NOT NULL default '0', PRIMARY KEY (`ExId`), KEY `ExId` (`ExId`) ) TYPE=MyISAM; # # Dumping data for table 'ex' # # # Table structure for table 'excatmapping' # CREATE TABLE `excatmapping` ( `ExId` int(11) NOT NULL default '0', `CatId` int(11) NOT NULL default '0' ) TYPE=MyISAM; # # Dumping data for table 'excatmapping' # INSERT INTO excatmapping VALUES("11","10"); INSERT INTO excatmapping VALUES("9","13"); INSERT INTO excatmapping VALUES("10","13"); INSERT INTO excatmapping VALUES("8","13"); INSERT INTO excatmapping VALUES("13","10"); INSERT INTO excatmapping VALUES("12","10"); INSERT INTO excatmapping VALUES("3","11"); INSERT INTO excatmapping VALUES("14","10"); INSERT INTO excatmapping VALUES("7","13"); INSERT INTO excatmapping VALUES("1","11"); INSERT INTO excatmapping VALUES("2","11"); INSERT INTO excatmapping VALUES("4","11"); INSERT INTO excatmapping VALUES("5","11"); INSERT INTO excatmapping VALUES("6","11"); INSERT INTO excatmapping VALUES("15","10"); INSERT INTO excatmapping VALUES("16","10"); INSERT INTO excatmapping VALUES("17","10"); INSERT INTO excatmapping VALUES("18","10"); INSERT INTO excatmapping VALUES("19","14"); INSERT INTO excatmapping VALUES("20","14"); INSERT INTO excatmapping VALUES("21","9"); INSERT INTO excatmapping VALUES("22","9"); INSERT INTO excatmapping VALUES("23","9"); INSERT INTO excatmapping VALUES("24","9"); INSERT INTO excatmapping VALUES("25","9"); INSERT INTO excatmapping VALUES("26","8"); INSERT INTO excatmapping VALUES("27","8"); INSERT INTO excatmapping VALUES("28","8"); INSERT INTO excatmapping VALUES("29","8"); INSERT INTO excatmapping VALUES("30","8"); INSERT INTO excatmapping VALUES("31","8"); INSERT INTO excatmapping VALUES("32","8"); INSERT INTO excatmapping VALUES("33","15"); INSERT INTO excatmapping VALUES("34","15"); INSERT INTO excatmapping VALUES("35","15"); INSERT INTO excatmapping VALUES("36","15"); INSERT INTO excatmapping VALUES("40","33"); INSERT INTO excatmapping VALUES("113","85"); INSERT INTO excatmapping VALUES("41","33"); INSERT INTO excatmapping VALUES("71","49"); INSERT INTO excatmapping VALUES("43","33"); INSERT INTO excatmapping VALUES("44","33"); INSERT INTO excatmapping VALUES("45","33"); INSERT INTO excatmapping VALUES("46","36"); INSERT INTO excatmapping VALUES("47","36"); INSERT INTO excatmapping VALUES("48","36"); INSERT INTO excatmapping VALUES("49","36"); INSERT INTO excatmapping VALUES("50","36"); INSERT INTO excatmapping VALUES("51","36"); INSERT INTO excatmapping VALUES("52","36"); INSERT INTO excatmapping VALUES("53","36"); INSERT INTO excatmapping VALUES("54","37"); INSERT INTO excatmapping VALUES("55","37"); INSERT INTO excatmapping VALUES("56","37"); INSERT INTO excatmapping VALUES("57","37"); INSERT INTO excatmapping VALUES("58","37"); INSERT INTO excatmapping VALUES("59","38"); INSERT INTO excatmapping VALUES("60","38"); INSERT INTO excatmapping VALUES("61","38"); INSERT INTO excatmapping VALUES("62","38"); INSERT INTO excatmapping VALUES("63","38"); INSERT INTO excatmapping VALUES("64","38"); INSERT INTO excatmapping VALUES("65","38"); INSERT INTO excatmapping VALUES("66","38"); INSERT INTO excatmapping VALUES("67","41"); INSERT INTO excatmapping VALUES("68","41"); INSERT INTO excatmapping VALUES("72","49"); INSERT INTO excatmapping VALUES("73","49"); INSERT INTO excatmapping VALUES("74","49"); INSERT INTO excatmapping VALUES("75","49"); INSERT INTO excatmapping VALUES("76","49"); INSERT INTO excatmapping VALUES("77","49"); INSERT INTO excatmapping VALUES("78","49"); INSERT INTO excatmapping VALUES("79","49"); INSERT INTO excatmapping VALUES("80","51"); INSERT INTO excatmapping VALUES("81","51"); INSERT INTO excatmapping VALUES("82","51"); INSERT INTO excatmapping VALUES("83","51"); INSERT INTO excatmapping VALUES("84","51"); INSERT INTO excatmapping VALUES("85","52"); INSERT INTO excatmapping VALUES("86","52"); INSERT INTO excatmapping VALUES("87","52"); INSERT INTO excatmapping VALUES("88","52"); INSERT INTO excatmapping VALUES("89","53"); INSERT INTO excatmapping VALUES("90","53"); INSERT INTO excatmapping VALUES("91","53"); INSERT INTO excatmapping VALUES("92","54"); INSERT INTO excatmapping VALUES("93","54"); INSERT INTO excatmapping VALUES("94","54"); INSERT INTO excatmapping VALUES("95","54"); INSERT INTO excatmapping VALUES("96","57"); INSERT INTO excatmapping VALUES("100","52"); INSERT INTO excatmapping VALUES("109","57"); # # Table structure for table 'exdata' # CREATE TABLE `exdata` ( `ExId` int(11) NOT NULL default '0', `LangId` int(11) default NULL, `ExType` tinyint(4) unsigned default NULL, `Code` mediumblob, `Explanation` mediumblob, `ShortDescription` varchar(255) default NULL, `Author` varchar(60) default NULL, `CreationDate` varchar(20) NOT NULL default '', `Hits` int(11) NOT NULL default '0', `Moderated` tinyint(1) NOT NULL default '0', `DiffLevel` int(11) NOT NULL default '0', `MaxLines` int(11) default NULL, `Url` varchar(60) NOT NULL default '', PRIMARY KEY (`ExId`), KEY `ExId` (`ExId`) ) TYPE=MyISAM; # # Dumping data for table 'exdata' # INSERT INTO exdata VALUES("33","1","1","\r\n\r\n\r\n\r\n\r\n


































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
\r\n

#include <iostream.h>

#define ARRAYSIZE 5

typedef struct node NodeStruct;
struct node {
   char word[15];
   NodeStruct *nextPtr;  /* Not needed in this version */
};

main()
{
        /*Following line creates an array \'wordsArray\' of Struct node.
   Each element of the wordsArray has a word[15] array and *nextPtr. */
 NodeStruct wordsArray[ ARRAYSIZE];
 int i;

 cout<<\"Please enter \"<<ARRAYSIZE<<\" words: \";
 for (i=0; i< ARRAYSIZE; i++)  {
   cin>>wordsArray[i].word;    // Read in and store the words
   // scanf(\"%s\", wordsArray[i].word);  // IN C
 }

 cout<<\"The stored words are: \";
 for (i=0; i< ARRAYSIZE; i++)  {
   cout<<wordsArray[i].word <<\" \";          // Print out the words
   // printf(\"%s \", wordsArray[i].word);   // IN C
 }
 
 cout<<endl;
}

","","Store words 1","Dale Reed","Tue Aug 27 23:46:14","5","0","1","35",""); INSERT INTO exdata VALUES("34","1","1","\r\n\r\n\r\n\r\n\r\n

















































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
\r\n

#include <iostream.h>
#include <string.h> // Require to use predefined String Functions

#define ARRAYSIZE 5
#define MAXSIZE 80

typedef struct node NodeStruct;
struct node {
   char *wordPtr;
   NodeStruct *nextPtr;  /* Not needed in this version */
};

main()
{
        /*Following line creates an array \'wordsArray\' of Struct node.
          Each element of the wordsArray has a *wordPtr and *nextPtr. */
 NodeStruct wordsArray[ ARRAYSIZE];

 char tempWord[ MAXSIZE]; /* store read-in word */
 int  wordLength;
 int i;

 cout<<\"Please enter \"<<ARRAYSIZE<<\" words: \";
 for (i=0; i< ARRAYSIZE; i++)  {  
   cin>>tempWord;
   wordLength = strlen(tempWord);  /* returns length of string */

   /* Allocate memory for *wordPtr after getting the size of the word.
      Need an extra char to store the NULL end-of-string character */
   wordsArray[i].wordPtr = new char[wordLength+1];

   /* IN C */
      //  wordsArray[i].wordPtr = (char *) malloc( sizeof( char) * (wordLength + 1) );


   strcpy( wordsArray[i].wordPtr, tempWord);  /* copy 2nd parm. into 1st parm. */
 }

 cout<<\"The stored words are: \";
 for (i=0; i< ARRAYSIZE; i++)  {
   cout<<wordsArray[i].wordPtr <<\" \";          // Print out the words
          // printf(\"%s \", wordsArray[i].wordPtr);   // IN C

 }
 cout<<endl;
}

","","Store words 2","Dale Reed","Tue Aug 27 23:47:19","1","0","1","50",""); INSERT INTO exdata VALUES("35","1","1","\r\n\r\n\r\n\r\n\r\n































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
\r\n

#include <iostream.h>
#include <string.h>

#define ARRAYSIZE 5
#define MAXSIZE 80

typedef struct node NodeStruct;
struct node {
   char *wordPtr;
   NodeStruct *nextPtr;  
};

main()
{
  /* create pointers of type NodeStruct */
 NodeStruct *headPtr = NULL;
 NodeStruct *tempPtr = NULL;
 NodeStruct *currentPtr = NULL;
 char tempWord[ MAXSIZE]; /* store read-in word */
 int  wordLength;
 int i;

 cout<<\"Please enter \"<<ARRAYSIZE<<\" words: \";
 for (i=0; i< ARRAYSIZE; i++)  {  

   /* Dynamically allocate memory to get a node */
   tempPtr = new (NodeStruct);
        file://tempPtr = (NodeStruct *) malloc( sizeof( NodeStruct)); // IN C
   tempPtr->nextPtr = NULL; 
  
   /* if its the first one, set the head pointer */
   if (headPtr == NULL)  {
     headPtr = tempPtr;   /* set the head ptr */
     currentPtr = tempPtr; /* set the current list ptr */
   }
  
   currentPtr->nextPtr = tempPtr; /* link the list */

   currentPtr = currentPtr->nextPtr; /* advance currentPtr */
  
   cin>>tempWord;
   wordLength = strlen( tempWord);  /* returns length of string */
   /* Dynamically allocate memory needed to store a word
    Need an extra char to store the NULL end-of-string character */
   tempPtr->wordPtr = new char[wordLength+1];

   // IN C
   // tempPtr->wordPtr = (char *) malloc( sizeof( char) * (wordLength + 1) );

   strcpy( tempPtr->wordPtr, tempWord);  /* copy 2nd parm. into 1st parm. */
 }
 
 cout<<\"The stored words are: \";
 while (headPtr) {
   cout<<headPtr->wordPtr<<\" \";
   headPtr = headPtr->nextPtr;
 }
 
 cout<<endl;
}

","","Store words 3","Dale Reed","Tue Aug 27 23:48:18","0","0","1","64",""); INSERT INTO exdata VALUES("36","1","1","\r\n\r\n\r\n\r\n\r\n









































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
\r\n

#include <iostream.h>
#include <string.h>
#include <stdlib.h>

#define ARRAYSIZE 5
#define MAXSIZE 80

typedef struct node NodeStruct;
struct node {
   char *wordPtr;
   NodeStruct *nextPtr;  /* Not needed in this version */
};

NodeStruct * enterWords( NodeStruct * headPtr)
{
 int i;
 NodeStruct *tempPtr;
 NodeStruct *currentPtr;
 char tempWord[ MAXSIZE]; /* store read-in word */
 int  wordLength;

 cout<<\" Please enter \"<<ARRAYSIZE<<\" words: \";                      ;
 for (i=0; i< ARRAYSIZE; i++)  {  

  /* first get a node */
  tempPtr = (NodeStruct *) malloc( sizeof( NodeStruct));
  tempPtr->nextPtr = NULL; 

  /* if its the first one, set the head pointer */
  if (headPtr == NULL)  {
   headPtr = tempPtr;   /* set the head ptr */
   currentPtr = tempPtr; /* set the current list ptr */
  }

  currentPtr->nextPtr = tempPtr; /* link the list */
   /* The above causes a problem if there is only 1 node in list */
  currentPtr = currentPtr->nextPtr; /* advance currentPtr */

  cin>>tempWord;
  wordLength = strlen( tempWord);  /* returns length of string */

  /* Need an extra char to store the NULL end-of-string character */
  tempPtr->wordPtr = new char[wordLength + 1];

  // IN C
  // tempPtr->wordPtr = (char *) malloc( sizeof( char) * (wordLength + 1) );
   
  strcpy( tempPtr->wordPtr, tempWord);  /* copy 2nd parm. into 1st parm. */
 }

 // Now return the list to the main program
 return headPtr;

}

main()
{
 int i;
 NodeStruct * head = NULL;

 head = enterWords( head);
 
 cout<< \"The stored words are: \" ;
 while (head) {  // same as \"while (head != NULL)\"
  cout<<head->wordPtr<<\" \";
  head = head->nextPtr;
 }
 
 cout<<endl;
}

","","Store words 4","Dale Reed","Tue Aug 27 23:49:06","0","0","1","74",""); INSERT INTO exdata VALUES("100","1","1","\r\n\r\n\r\n\r\n\r\n

















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
\r\n



int main()
{
      for ( int i=0; i<10; i++) {
            cout << i << \" \";
      }

      for ( int i=9; i>=0; i--) {
            cout << i << \" \";
      }

      return 0;
}

","

5 Note that the counting variable i is declared inside the loop.  It is no longer in scope outside the loop.

\r\n

9 Must declare i again, since it is not in scope of above loop

\r\n

 

","Variables declared in for loop","Dale Reed","Mon Feb 17 15:42:12","3","0","1","18",""); INSERT INTO exdata VALUES("40","7","1","\r\n\r\n\r\n\r\n\r\n
















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
\r\n

   #include <iostream>
   using namespace std;

   int main()
   {
      int i = 10;
      cout << \"Value of \'i\' in the outer block is \" << i << endl;
      {
         int i = 20;
         cout << \"Value of the other \'i\' in the inner block is \" << i << endl;
      }
      cout << \"Value of \'i\' in the outer block still is \" << i << endl;

      return 0;
   }

","

This program explains the concept of a block of code in C++.  A block of code is a few lines of code within a pair of curly braces. All variables declared within a block will be alive until the last line of the block.

\r\n

There are two blocks in the example:
Lines 6 through 14 form one block of code. This is the main block of code for the program.
Lines 9 to 10 form another block of code. Notice that the value of the variable i within and without this block, is different. This is because the variable i within the smaller block is totally different from the variable i within the larger block. This is called Scoping

","Block of Code","Sam","Thu Dec 05 12:06:43","26","1","1","17",""); INSERT INTO exdata VALUES("41","7","1","\r\n\r\n\r\n\r\n\r\n









1
2
3
4
5
6
7
8
9
\r\n

 #include <iostream>
 using namespace std;

 int main()
 {
    cout << \"Hello World!\" << endl;
    return 0;
 }

","

This demonstrates a simple C++ program. The code when executed, prints \"Hello World\" on the display.

\r\n

Line 1 shows how to include a library header file required for the code to run. Different libraries contain different items of interest. This iostream library contains the most common functions used in a C++ program.

\r\n

Line 2 shows the use of the standard C++ namespace. This is required by the new g++ compiler for Unix.

Line 4 shows the main function. A function is a named block of code which can be reused. The main funcion is a special function that is called by the operating system when the program starts executing. Put all the stuff you want to execute within this function. Lines 6 to 7 form the body of the main function.

Line 6 shows the use of the cout object, which is used to print stuff to the screen. In this example, cout is used to print \"Hello World!\" on the screen. The endl keyword adds a line break to the cout statement.

","Hello World","Sam","Thu Jan 16 13:59:31","18","1","1","10",""); INSERT INTO exdata VALUES("43","7","1","\r\n\r\n\r\n\r\n\r\n












1
2
3
4
5
6
7
8
9
10
11
12
\r\n

#include <iostream>
using namespace std;

int main()
{
    int i = 10;  // variable \'i\'
    int I = 20;  // variable \'I\' is different from variable \'i\'
    // Int a;     // incorrect. There is no datatype by name \'Int\'

    cout << \"Value of variable i = \" << i << endl;
    cout << \"Value of variable I = \" << I << endl;
    return 0;
}

","

A few things are case sensitive in C++. These include variables, function names and datatypes.

\r\n

The two variables (i and I) in lines 6 and  7 are different because one is lower-case and one is upper-case.

\r\n

Line 8 will cause a compiler error if uncommented, because the datatype for an integer is called \'int\' and not \'Int\' in C++. 

","Case Sensitivity","Sam","Thu Jan 16 14:13:48","9","1","1","13",""); INSERT INTO exdata VALUES("44","7","1","\r\n\r\n\r\n\r\n\r\n



























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
\r\n

#include <iostream>
using namespace std;

int main()
{
    int i;
    cout << \"Type a number:\";
    cin >> i;

    char a;
    cout << \"Type an alphabetic character:\";
    cin >> a;

    cout << \"The number you typed is \" << i << \", and the character you typed is \" << a << endl;

    // cin with more than one input
    char b;
    cout << \"Type two alphabetical characters:\";
    cin >> a >> b;
    cout << \"The two characters you typed are \" << a << b <<endl;

    return 0;
}

","

 The cout object 7 is used to display text on the screen. A cout statement is always followed by the symbol \'<<\' followed by the text or object that needs to be printed out. You can combine many outputs with the same cout statement as shown in line 14 .

\r\n

The cin object 8 is used to get data from the user. A cin statement is always followed by the symbol \'>>\' followed by the variables that will receive the value that the user typed.

\r\n

It is helpful to remember that the information flows in the direction of the \"arrows.\"

","Standard I/O","Sam","Thu Jan 16 14:16:09","11","1","1","28",""); INSERT INTO exdata VALUES("45","7","1","\r\n\r\n\r\n\r\n\r\n













1
2
3
4
5
6
7
8
9
10
11
12
13
\r\n

#include <iostream>
using namespace std;

int main()
{
   cout << \"This is a tab between the colons:\\t:\" << endl;
   cout << \"This is a string in two lines starting here.\\n This is the next line\" << endl;

   // cout << \"The path is c:\\projects\\cs101\" << endl;        // incorrect - will not compile
   cout << \"The path is c:\\\\projects\\\\cs101\" << endl;         // correct

   // cout << \"Marty said \"Hi Sarah!\".\" << endl;                 // incorrect - will not compile
   cout << \"Marty said \\\"Hi Sarah!\\\".\" << endl;                  // correct

   return 0;

","

Some characters cannot be displayed as is, because they have special meanings. eg: tab, newline, the backslash, and quotes. To display such characters we need to escape them from the normal display mechanism. The \'\\\' char is the escape initiator character, which we place immediately preceding the character we wish to use.

\r\n

line 6 demonstrates how to place a tab on the screen

\r\n

line 7 demonstrates how to make a newline

\r\n

lines 9, 10 show how to escape the backslash character.

\r\n

lines 12, 13 show how to print the double quote character from within a string.

","Escape Sequences","Sam","Thu Jan 16 14:20:47","12","1","1","14",""); INSERT INTO exdata VALUES("46","7","1","\r\n\r\n\r\n\r\n\r\n












1
2
3
4
5
6
7
8
9
10
11
12
\r\n

#include <iostream>
using namespace std;

int main()
{
    int i , nCount;            // valid identifier names
    char sum;               // valid
    bool Is21Odd;         // valid
    // int 21j;                 // invalid. Will generate a compiler error
    // char $sum;          // invalid

    return 0;
}

","

Variables( also called identifiers) follow some rules with regard to their names.Variable names cannot start with a number or a special character, other than the underscore character. But there can be numbers in the name except as the starting character.

","Identifier Names","Sam","Thu Dec 05 23:27:03","5","1","1","13",""); INSERT INTO exdata VALUES("47","7","1","\r\n\r\n\r\n\r\n\r\n

















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
\r\n

#include <iostream>
using namespace std;

int main()
{
    int i;           // declaration
    int j = 0;     // declaration & initialization
    i = 34;        // assignment

    i = i + 1;     // can add/subtract other integers to this integer
    j = -45 * 2;  // can multipy/divide other integers by this integer

    j = 67.5;     // invalid value , C++ will truncate the value to a integer value
    cout << j;

    return 0;
}

","

Integers are represented in C++ by the keyword int. Line 6 shows how to declare an integer. A variable i is declared to be an integer variable (i.e), the variable i can hold integer values. Line 7 shows how to both declare and initialize an integer. Lines 10 and 11 show that one can do basic operations ( add, subtract, multiply, divide ) with integers. There are other operations that can be done with integers too.

Line 14 is interesting. It shows an integer variable ( by which we mean a variable that is allowed to hold only integer values ), being assigned a real number. This is incorrect. What the compiler will do is truncate the real number and assign the truncated integer value to the variable j. The compiler will also generate a warning during compilation.

","Integer","Sam","Thu Dec 05 22:30:28","2","1","1","18",""); INSERT INTO exdata VALUES("48","7","1","\r\n\r\n\r\n\r\n\r\n




















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
\r\n

#include <iostream>
using namespace std;

int main()
{
   char c;        // declaration
   c = \'f\';         //  initialization
   cout << c;

   c = 65;       // Invalid character. C++ will use the ascii character that corresponds to
                    // the number \'65\' in the ascii sequence.
   cout << c;

   // to print a single quote char
   // c = \'\'\';     // invalid
   c = \'\\\'\';       // valid. The \'/\' character escapes the single quote.
   cout << c;
 
   return 0;
}

","

Characters are represented in C++ by the keyword char. Line 6 shows how to declare a character. A variable c is declared to be a character variable (i.e), the variable c can hold single characters. Line 7 shows how to initialize a character variable.
Lines 10 assigns a number to a character variable. This is invalid. What the compiler does in this case is, it retrieces the ascii character corresponding to the number, and stores it in the variable c.

Lines 14 - 17 demonstrate printing of the single quote character. Since the single quote is used as a delimiter for characters, to pring the single quote itself, we need to escape it first.

","Character","Sam","Thu Dec 05 23:26:56","9","1","1","21",""); INSERT INTO exdata VALUES("49","7","1","\r\n\r\n\r\n\r\n\r\n



















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
\r\n

#include <iostream>
using namespace std;

int main()
{
   bool isOk;                      // declaration
   bool working = false;       // declaration & initialization

   isOk = true;                   // assigning a value
   cout << isOk;

   cout << \"Is it working?\";
   cin >> working;
   if( working == true )       // check the value of a boolean variable
      cout << \"Its working fine!\" << endl;
   else
      cout << \"Its not working!\" << endl;

   return 0;
}

","

Boolean values ( true and false ) are represented in C++ by the keyword bool. Line 6 shows how to declare a boolean variable. A variable isOk is declared to be a boolean variable (i.e), the variable isOk can hold boolean values. Line 7 shows how to both declare and initialize a bool. Boolean values can be input and output to the screen using the cin and cout objects. They can also be compared, as shown in line 14.

","Boolean","Sam","Thu Dec 05 22:41:45","1","1","1","20",""); INSERT INTO exdata VALUES("50","7","1","\r\n\r\n\r\n\r\n\r\n



















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
\r\n

#include <iostream>
using namespace std;

int main()
{
    float f;                     // declaration
    float g = 34.23;        // declaration & initialization

    cout << \"Type a float value:\";
    cin >> f;

    float h = f + g;
    cout << \"The sum of \" << f << \" and 34.23 is \" << h << endl;

    f = f * 19.7+ 12.0;
    g = f / g;
    cout << f << g;

    return 0;
}

","

Real numbers are represented in C++ by two storage types - floats, and doubles. They differ in the degree of precision, A float is defined by the keyword float. Line 6 shows how to declare a float. A variable f is declared to be a float variable (i.e), the variable f can hold floating point values. Line 7 shows how to both declare and initialize a float. The remainign lines show that floats can be read and written to screen using the cin and cout objects. Also, arithmetic operations can be done on floats.

","Float","Sam","Thu Dec 05 22:48:11","2","1","1","20",""); INSERT INTO exdata VALUES("51","7","1","\r\n\r\n\r\n\r\n\r\n















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\r\n

#include <iostream>
using namespace std;

int main()
{
   char c;                // allocating a character in memory ( at compile time )
   c = 10;
   cout << c;

   char* pc;            // declaring a pointer to a character
   pc = new char;   // allocating space for pc ( at run time )
   *pc = 10;           // asigning a value to it
   cout << *pc;

   return 0;
}

","


Variables can be allocated statically, or on the fly as the program executes.

Line 6 shows how to allocate a variable statically. This is the way you would use most normally to create variables. Variables created like this have their memory allocated at compile time. This becomes partof the executable code.

Line 10 shows how to declare a pointer to a character. There is more about this in other examples. Line 11 shows how to allocate space for the variable dynamically. It is dynamic in the sense that, you allocate memory for the variable when the program is actually running.

Dynamic memory comes into play when you have to create memory structures whose size you dont know while writing the program. For example, a program that stores a list of phone numbers that a user types in does not have any clue how many phone numbers the user is going to type-in. One solution would be to allocate an arbitrary large memory. The slimer solution is to allocate memory for the phone numbers as and when the user adds a phone number - dynamically.

","Static & Dynamic Allocation","Sam","Fri Dec 06 00:07:08","5","1","1","16",""); INSERT INTO exdata VALUES("52","7","1","\r\n\r\n\r\n\r\n\r\n


















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
\r\n

  #include <iostream>
  using namespace std;

   int main()
   {
      int i = 10;
      cout << \"Value of \'i\' in the outer block is \" << i << endl;
      {
         int i = 20;
         cout << \"Value of the other \'i\' in the inner block is \" << i << endl;
      }
      cout << \"Value of \'i\' in the outer block still is \" << i << endl;

      return 0;
   }

","The variable i declared in line 6 is totally different from the variable i declared in line 9. This is made possible by scoping. The scope of a variable is the defining block of code in which it can exist. The scope of the variable i declared in line 9 is the block of code in lines 8 to 11. The scope of the variable i declared in line 6 is the block of code in lines 5 to 15 (i.e) the main block of the program.
","Scope","Sam","Thu Dec 05 23:25:35","2","1","1","19",""); INSERT INTO exdata VALUES("53","7","1","\r\n\r\n\r\n\r\n\r\n
















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
\r\n

#include <iostream>
using namespace std;

int main()
{
   int i = 70;

   char c;
   c = ( char ) i;
   cout << i << c;

   double d = 56.5;
   i = ( int ) d;
   cout << d << i;

   return 0;
}

","

You can change the type of a variable, to use it for different purposes.
In line 9 an integer value is cast to a char value. In line 13, a double value is cast to an integer. This is called a downcast, because it loses decimal data with the casting to integer.

","Type Cast","Sam","Fri Dec 06 00:06:32","5","1","1","17",""); INSERT INTO exdata VALUES("54","7","1","\r\n\r\n\r\n\r\n\r\n

































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
\r\n

#include <iostream>
using namespace std;

int main()
{
   // Conventional way:
   int ph1, ph2 , ph3 , ph4 , ph5 , ph6;
   int nPhoneNumbers;

   cout << \"Type 6 phone numbers to store: \" << endl;
   cin >> ph1 >> ph2 >> ph3 >> ph4 >> ph5 >> ph6;

   // Or, you could use an array:

\r\n

   int phoneNumbers[6];
   cout << \"Type 6 phone numbers to store: \" << endl;
   for( int i = 0; i < 6; i++ )
       cin >> phoneNumbers[ i ];

\r\n

   for(int i=0;i<6;i++)
      cout << phoneNumbers[ i ] << \"  \";
   cout << endl;

   return 0;
}

","

Imagine wanting to store 10 phone numbers. You could use 10 pieces of paper to write them each in, or you could a book with papers to write them all in.  An aray is something like the book. It is a set of similar type of information.

The first 12 lines of code depict how to store 6 phone numbers in 6 variables. The next 12 lines show how to do the same with an array. Line 15 declares an array phoneNumbers to be of size 6. The array is declared to store integers.
Lines 17, 18 show how to get input for the 6 array indexes. Note that the array ranges from 0..5.
Lines 20, 21 show how to print values from the array.

","Why arrays","Sam","Fri Dec 06 00:31:34","3","1","1","34",""); INSERT INTO exdata VALUES("29","1","1","\r\n\r\n\r\n\r\n\r\n

















































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
\r\n

#include <iostream.h>
#include <stdlib.h>

typedef struct node *nodeStruct;
struct node {
   int data;
   nodeStruct nextPtr;
};


void displayList( nodeStruct head)
{
   nodeStruct tempPtr= head;  /* Used to traverse list without destroying head*/
   cout<<\"\\nJust entered Fcn. displayList...\";
   while( tempPtr != NULL) {
     cout<<tempPtr->data <<\" \";
      tempPtr = tempPtr->nextPtr;
   }
   cout<<endl<<endl;
}

long processNumbers( nodeStruct head, int operation)
{
   nodeStruct tempPtr = head;
   long result = 0;

   if (operation == 2)  /* Multiply chosen */
      result = 1;
   while (tempPtr != NULL) {
      if (operation == 1)  /* Add chosen */
       result += tempPtr->data;
      else if (operation == 2) /* Multiply chosen */
       result *= tempPtr->data;
      tempPtr = tempPtr->nextPtr;  /* Advance to next list member */
   }

   return result;
}

main()
{
   int number = 0;          /* Used to store numbers read in */
   nodeStruct head = NULL;     /* head of linked list */
   nodeStruct tempPtr;
   int menuChoice;     /* Menu choice */
   long answer;      /* Answer of chosen operation */

   cout<<\"This program finds sum or product of a variable number \\n\";
   cout<<\" of integers. Enter as many integers > 0 as you would like \\n\";
   cout<<\" followed by the value -1.\\n\\n\";
   cout<<\" The numbers are: \";

   while ( number != -1) {
     cin>>number;
     if (number != -1) {
       tempPtr = new struct node;
       /* Insert at head of list */
       tempPtr->data = number;
       tempPtr->nextPtr = head;
       head = tempPtr;
     }
   }

   displayList( head);
  
   cout<<\"Please select the number of one of these options: \\n\";
   cout<<\"   1. Sum the numbers in the list\\n\";
   cout<<\"   2. Multiply the numbers in the list \\n\";
   cout<<\"   3. Exit the program.\\n\";
   cout<<\"Your choice: \";
   cin>>menuChoice;
   cout<<endl;

   if (menuChoice == 3)
      exit( 0);
   answer = processNumbers( head, menuChoice);
   cout<<\"Answer is: \"<<answer <<\".\"<<endl<<endl;
}

","","List Prog 1","Dale Reed","Thu Mar 06 03:18:53","3","0","1","82",""); INSERT INTO exdata VALUES("30","1","1","\r\n\r\n\r\n\r\n\r\n













































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
\r\n

#include <iostream.h>
#include <stdlib.h>

typedef struct node * nodeStruct;
struct node {
   int data;
   nodeStruct nextPtr;
};

// Function prototypes
void displayList( nodeStruct);
long processNumbers( nodeStruct, int);

/*  This is what we THINK we need:
  void addToList( nodeStruct head, int number)
  {
   nodeStruct tempPtr;
  
   tempPtr = (nodeStruct) malloc( sizeof( struct node));
   // Insert at head of list
   tempPtr->data = number;
   tempPtr->nextPtr = head;
   head = tempPtr;
  }
*/

// This is what we REALLY need (compare to the one above)
void addToList( nodeStruct &head, int number)
{
   nodeStruct tempPtr;

 tempPtr = (nodeStruct) malloc( sizeof( struct node));
 // Insert at head of list
 tempPtr->data = number;
 tempPtr->nextPtr = head;
 head = tempPtr;
}


main()
{
   int number = 0;           /* Used to store numbers read in */
   nodeStruct head = NULL;    /* head of linked list */
   int menuChoice;       /* Menu choice */
   long answer;        /* Answer of chosen operation */


 cout<<\"This program finds sum or product of a variable number \\n\";
   cout<<\" of integers. Enter as many integers > 0 as you would like \\n\";
   cout<<\" followed by the value -1.\\n\\n\";
   cout<<\" The numbers are: \";
 
   while ( number != -1) {
     cin>>number;
 if (number != -1) {
   addToList( head, number);
 }
   }
   cout<<\"The list looks like: \";
   displayList( head);
  
   cout<<\"Please select the number of one of these options: \\n\";
   cout<<\"   1. Sum the numbers in the list\\n\";
   cout<<\"   2. Multiply the numbers in the list \\n\";
   cout<<\"   3. Exit the program.\\n\";
   cout<<\"Your choice: \";
   cin>>menuChoice;
   cout<<endl;

   if (menuChoice == 3)
      exit( 0);
   answer = processNumbers( head, menuChoice);
   cout<<\"Answer is: \"<< answer;

}


void displayList( nodeStruct head)
{
   nodeStruct tempPtr= head;  /* Used to traverse list without destroying head*/
   while( tempPtr != NULL) {
     cout<<tempPtr->data<<\" \";
      tempPtr = tempPtr->nextPtr;
   }
   cout<<endl<<endl;

}


long processNumbers( nodeStruct head, int operation)
{
   nodeStruct tempPtr = head;
   long result = 0;

   if (operation == 2)     /* Multiply chosen */
      result = 1;
   while (tempPtr != NULL) {
      if (operation == 1)     /* Add chosen */
       result += tempPtr->data;
      else if (operation == 2)  /* Multiply chosen */
       result *= tempPtr->data;
      tempPtr = tempPtr->nextPtr;  /* Advance to next list member */
   }

   return result;
}

","","List Prog 2","Dale Reed","Tue Aug 27 23:32:19","1","0","1","110",""); INSERT INTO exdata VALUES("31","1","1","\r\n\r\n\r\n\r\n\r\n





















































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
\r\n

#include <iostream.h>
#include <stdlib.h>

typedef struct node * nodeStruct;
struct node {
   int data;
   nodeStruct nextPtr;
};

// Function prototypes
nodeStruct reverseList( nodeStruct);
nodeStruct reversing( nodeStruct);
void displayList( nodeStruct);
long processNumbers( nodeStruct, int);


main()
{
   int number = 0;          /* Used to store numbers read in */
   nodeStruct head = NULL;     /* head of linked list */
   nodeStruct tempPtr;
   int menuChoice;     /* Menu choice */
   long answer;      /* Answer of chosen operation */

   cout<<\"This program finds sum or product of a variable number \\n\";
   cout<<\"  of integers. Enter as many integers > 0 as you would like \\n\";
   cout<<\"  followed by the value -1.\\n\\n\";
   cout<<\"The numbers are: \";

   while ( number != -1) {
     cin>>number;
     if (number != -1) {
       tempPtr = new struct node;
       /* Insert at head of list */
       tempPtr->data = number;
       tempPtr->nextPtr = head;
       head = tempPtr;
     }
   }

   cout<<\"Before reversing, the list looks like: \";
   displayList( head);
 
   head = reverseList(head);
   cout<<\"AFTER reversing, the list looks like: \";
   displayList( head);

   cout<<\"Please select the number of one of these options: \\n\";
   cout<<\"   1. Sum the numbers in the list\\n\";
   cout<<\"   2. Multiply the numbers in the list \\n\";
   cout<<\"   3. Exit the program.\\n\";
   cout<<\"Your choice: \";
   cin>>menuChoice;

   if (menuChoice == 3)
      exit( 0);
   answer = processNumbers( head, menuChoice);
   cout<<\"Answer is: \"<<answer<<endl;

}

nodeStruct reverseList( nodeStruct head)

 nodeStruct tempPtr, returnValue;

 tempPtr = head;
 returnValue = reversing(head);
 tempPtr->nextPtr = NULL;
 return returnValue;
}


nodeStruct reversing( nodeStruct head)
{
  nodeStruct tempPtr;
  if (head->nextPtr == NULL)  {
    return head;
  }
 else {     /* head->nextPtr != NULL */  
   tempPtr = reversing( head->nextPtr);
   head->nextPtr->nextPtr = head; /* reverse link */
   return tempPtr;
 }   
}


void displayList( nodeStruct head)
{
   nodeStruct tempPtr= head;  /* Used to traverse list without destroying head*/
   while( tempPtr != NULL) {
     cout<<tempPtr->data;
     tempPtr = tempPtr->nextPtr;
   }
   cout<<endl<<endl;
}


long processNumbers( nodeStruct head, int operation)
{
   nodeStruct tempPtr = head;
   long result = 0;

   if (operation == 2)  /* Multiply chosen */
      result = 1;
   while (tempPtr != NULL) {
     if (operation == 1)  /* Add chosen */
       result += tempPtr->data;
     else if (operation == 2) /* Multiply chosen */
       result *= tempPtr->data;
     tempPtr = tempPtr->nextPtr;  /* Advance to next list member */
   }
  
   return result;
}

","","List Prog 3","Dale Reed","Tue Aug 27 23:33:05","2","0","1","118",""); INSERT INTO exdata VALUES("32","1","1","\r\n\r\n\r\n\r\n\r\n


































































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
\r\n

#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>  /* Needed for malloc */

#define LIMIT 100
#define TRUE 1
#define FALSE 0

/* Create instance of a square */
typedef struct aSquare squareStruct;
struct aSquare {
   char contents;
   int timesVisited; /* not really needed for anything */
};

/* create an array of squares */
squareStruct maze[LIMIT];

/* create a separate structure for a linked list */
typedef struct node *nodePtr;
struct node {
   int data;
   nodePtr nextPtr;
};

/* Keep track of \"open\" squares to initialize maze */
int openSquares[]={ 11,12,13,22,32,42,52,43,44,45,
     46,36,26,27,54,64,74,84,83,82,
     65,66,76,86,87,88};
const int start = 11;
const int finish = 88;
int solutionFound = FALSE;


void initialize( int theMove, nodePtr &head)
{
 int i,j,theSquare;
 nodePtr tempPtr;

    for (i=0; i<LIMIT; i++)  {
  maze[ i].contents = \'1\';
  maze[ i].timesVisited = 0;
 }
 
 /* Set contents of \"open\" squares */
 for (i=0; i<26; i++)  {
  theSquare = openSquares[ i];
  maze[ theSquare].contents = \'0\';
 }

 /* Create linked list entry for initial node */

 file://tempPtr = (nodePtr) malloc( sizeof( struct node));  in C
 tempPtr = new struct node; // in C++

 /* Insert at head of list */
 tempPtr->data = theMove;
 tempPtr->nextPtr = head;
 head = tempPtr;

}


void displayMaze(int currentSquare)
{
   int i;

   /* Display maze */
   cout<<\"\\n\\nMaze Traversal program for the maze:\\n\";
   cout<<\"    \";                        /*Display top labels*/
   for (i=0; i< 10; i++) cout<<\" \"<<i;
   cout<<\"\\n\";
   cout<<\"    \" ;                        /*Display ruler line*/
  
   for (i=0; i< 10; i++) cout<<\"--\";
   cout<<\"\\n\" ;

   for (i=0; i< LIMIT; i++)  {
     if ( i%10 == 0){
       if(i==0) cout<<\"  \"<<i <<\"|\";
       else cout<<\" \"<<i <<\"|\";
     //       printf(\"%2d|\", i);  /*Left hand labels  IN C*/
     }

     //     printf(\"%2c\", maze[i].contents);  /* IN C*/
     cout<<\" \"<<maze[i].contents;
     if ( (i+1)%10 == 0) cout<<endl;   /*End of line*/
   }
   cout<<\"Currently at: \"<< currentSquare;
  
}

/* void makeMove(int *from, nodePrt *head)    IN C */
void makeMove( int &from, nodePtr &head)
{
 int i, nextMove;
 nodePtr tempPtr;
 char direction;
 int moveIncrement = 0;
 
 displayMaze(from); /* use displayMaze (*from) IN C) */
 cout<<\"Enter l, r, u, d, or q for left, right, up, down, or quit: \";
 cin>>direction;

 switch (direction) {
         case \'l\': moveIncrement = -1; break;
  case \'r\': moveIncrement = 1; break;
  case \'u\': moveIncrement = -10; break;
  case \'d\': moveIncrement = 10; break;
         case \'q\': cout<<\"Exiting program...\\n\"; exit( 0); break;
         default : cout<<\"Invalid option, please retry\\n\"; return; break;
 }
 nextMove = from + moveIncrement;

 /* Ensure it is an open square */
 if ( maze[ nextMove].contents == \'1\')  {
   cout<<\"Invalid move, please retry.\\n\";
 return;
 }
 
   /* Add code here to ensure move is adjacent to \"from\" */

 /* Increment times visited.  This isn\'t needed for anything */
 maze[ nextMove].timesVisited++;

 /* Add to linked list */
        /*tempPtr = (nodePtr) malloc( sizeof( struct node));  IN C */

        tempPtr = new struct node;
  
 /* Insert at head of list */
 tempPtr->data = nextMove;
 tempPtr->nextPtr = head;
 head = tempPtr;

 /* Update display and current move variable */
 maze[ from].contents = \'0\';
 maze[ nextMove].contents = \'X\';
 from = nextMove;

 if (nextMove == finish) {
       solutionFound = TRUE; /*Set flag to indicate we\'re done */
 displayMaze( from); 
 }
}


void displaySolution( nodePtr head)
{
        cout<<\" Solution in reverse is: \";

 nodePtr tempPtr= head;  /* Used to traverse list without destroying head*/
 while( tempPtr != NULL) {
   cout<<tempPtr->data<<\" \";
   tempPtr = tempPtr->nextPtr;
 }
 cout<<endl<<endl;

}

void forwardsSolution( nodePtr head)
{
 nodePtr tempPtr= head;  /* Used to traverse list without destroying head*/
 if ( tempPtr != NULL) {
  forwardsSolution( tempPtr->nextPtr);
 }
 else  {
  return;
 }
 cout<<tempPtr->data<<\" \";
 tempPtr = tempPtr->nextPtr;
}


int main()
{
 int currentMove = 11;
 nodePtr head = NULL;     /* head of linked list */
 initialize( currentMove, head);
 maze[ currentMove].contents = \'X\';

 while ( solutionFound == FALSE) {
  makeMove( currentMove, head);
 }

 displaySolution( head);
 
 cout<<\"Forwards solution is: \";
 forwardsSolution( head);
 cout<<endl;
}

","","Maze List","Dale Reed","Tue Aug 27 23:42:19","7","0","1","195",""); INSERT INTO exdata VALUES("24","1","1","\r\n\r\n\r\n\r\n\r\n



































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
\r\n

#include <iostream>
#include <stdlib.h>
#include <assert.h>

#define INCREMENT 5
#define TRUE 1
#define FALSE 0


int retrieve( int *pArray, // the array
       int topIndex, // index of top item in array
       int index)  // index of item to be retrieved
{
 // valid index goes from 0 to arraySize - 1
 if ( ( index > topIndex) || (index < 0))  {
  // Sanity check for valid index value
  cout<< \"There is data in the array, but that index is invalid.\\n\";
                cout<< \"Index must be between 0 and \"<<topIndex<<endl;
                cout<< \"Please try again.\\n\" ;
                return -1;
 }
 
 // Index must be valid to get here
 return *(pArray + index);
}


void displayArray(    
     int *pArray,  // the array
     int topIndex) // top array entry index
{

        int i;
 cout<<endl<<\"topIndex: \"<<topIndex<<endl;
        cout<<\"Contents of array is: \" ;
        cout<< \"\\nIndex: \" ;
        for (i=0; i <= topIndex; i++)  {
          cout<<\" \"<<i;
        }
        cout<< \"\\nValues: \" ;
        for (i=0; i <= topIndex; i++)  {
          cout<<*(pArray+i) <<\" \";
        }
                       
        cout<<endl;
}



void store(   
   int * &pArray,  // the Array\'s address
     int & arraySize,  // size of the Array
     int & topIndex, // current top indexed element
     int value,    // value to be stored in array
     int index)   // position at which to store the value
{
 
 int *pTemp = NULL;  // temporary array pointer
 int i;      // loop counter

 if ( index >= arraySize)  {
  // Allocate space for new, bigger array
            pTemp = new int[arraySize + INCREMENT];
  file://pTemp = (int *) malloc( (arraySize + INCREMENT) * (sizeof( int)));
//  assert( pTemp != NULL);  // sanity check on memory allocation

  // copy old array into new array

  for (i=0; i<arraySize; i++)  {
   *(pTemp+i) = *(pArray+i);
  }

  // initialize new space in array to 0
  for (i=0; i<INCREMENT; i++)  {
   *(pTemp+topIndex+i) = 0;
  }
  

  // free space from old array if there was any
  if ( pArray != NULL) { 
    free(pArray); 
  }
  // make old pointer point to new array
                pArray = pTemp;

  // Update new size of array
  arraySize += INCREMENT;
 }

 // We know there is space for the element to be added at this point,
 //  so store the value in place in the array & update top pointer.
 if ( !( index < arraySize))  {
  // Sanity check for valid index value
  cout<< \"\\n***\\n\";
  cout<< \"There is room in the array, but that index is invalid.\\n\";
  cout<< \"Index must be between 0 and \"<<topIndex<<endl;
  cout<< \"Please try again.\\n\" ;
  return;
 }
 // Increment topIndex if we are storing a new value
 if (index > topIndex)  {
  // do this instead of just topIndex++ since the index can
  //  \"jump\" a value since we\'re allocating in chunks
  topIndex = index+1;
 }
 // Store the value in the appropriate spot
 *(pArray + index) = value;

}




int main( void )
{
 int *pArray = NULL; // Pointer to the array
 int arraySize = 0;
 int topIndex = 0;  // Points to the next open array spot
 int notDone = TRUE; // main loop flag
 int value = 0;    // value to be stored in array
 int index= 0;    // position in which to store or retrieve value
 char menuChoice;  // stores menu choice
 
 do  {
  
         cout<< \"    \\n\\n\";
                cout<< \" Choose an option: \\n\";
                cout<< \" s. Store a value into the array.\\n\";
                cout<< \" r. Retrieve a value from the array. \\n\";
                cout<< \" d. Display contents of array.\\n\";
                cout<< \" x. Exit program.\\n\";
                cout<<endl;
                cout<< \"Your choice --> \";
                cin>>menuChoice;
                                        
  switch( menuChoice)  {
   case \'s\': // Store value into array
     cout<< \"Enter value & index: \" ; 
     cin>>value>>index;
     store( pArray, arraySize, topIndex, value, index);
     break;

   case \'r\': // Retrieve value from array

                   cout<< \"Enter index of value to retrieve: \";
                                        cin>>index;
                                        cout<< \"Value is: \"<<retrieve(pArray, topIndex, index)<<endl;
                                        break;
   case \'d\': // display array contents
     displayArray( pArray, topIndex);
     break;
   case \'x\': // Exit program
     notDone = FALSE;
     break;
  }
  
 } while ( notDone);
 
 return 0;
}

","","dynamicArray 2","Dale Reed","Tue Aug 27 23:19:42","0","0","1","164",""); INSERT INTO exdata VALUES("25","1","1","\r\n\r\n\r\n\r\n\r\n


























































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
\r\n

#include <iostream>
#include <assert.h>

using namespace std;  // introduces namespace std

#define INCREMENT 5
#define TRUE 1
#define FALSE 0


int retrieve( int *pArray, // the array
    int topIndex, // index of top item in array
    int index)  // index of item to be retrieved
{
 // valid index goes from 0 to arraySize - 1
 if ( (index > topIndex) || (index < 0) ) {

  // Sanity check for valid index value
  cout<<\"There is data in the array, but that index is invalid.\"<<endl;
  cout<<\"Index must be between 0 and \"<<topIndex<<endl;
  cout<<\"Please try again.\"<<endl;
  return -1;
 }
 
 // Index must be valid to get here
 return *(pArray + index);
}


void store( int * &pArray,   // the Array\'s address
     int & arraySize,  // size of the Array
     int & topIndex,  // current top indexed element
     int value,    // value to be stored in array
     int index)   // position at which to store the value
{
 int *pTemp = NULL;   // temporary array pointer
 int i;      // loop counter
 
 if ( index >= arraySize)  {
  // Allocate space for new, bigger array

  pTemp = new int[arraySize + INCREMENT];

  assert( pTemp != NULL);  // sanity check on memory allocation
  // copy old array into new array
  for (i=0; i<arraySize; i++)  {
   *(pTemp+i) = *(pArray+i);
  }
  
  // initialize new space in array to 0
  for (i=0; i<INCREMENT; i++)  {
   *(pTemp+topIndex+i) = 0;
   
  }

  // free space from old array if there was any
  if ( pArray != NULL) { 
   delete(pArray); 
  }
  // make old pointer point to new array
  pArray = pTemp;
  // Update new size of array
  arraySize += INCREMENT;
 }
 
 // We know there is space for the element to be added at this point,
 //  so store the value in place in the array & update top pointer.
 if ( !( index < arraySize))  {
  // Sanity check for valid index value
  cout<<endl<<\"***\"<<endl;
  cout<<\"There is room in the array, but that index is invalid.\"<<endl;
  cout<<\"Index must be between 0 and \" <<topIndex<<endl;
  cout<<\"Please try again.\"<<endl;
  return;
 }
 // Increment topIndex if we are storing a new value
 if (index > topIndex)  {
  // do this instead of just topIndex++ since the index can
  //  \"jump\" a value since we\'re allocating in chunks
  topIndex = index+1; // add ONE to index to avoid rewriting on the last position.
 }
 // Store the value in the appropriate spot
 *(pArray + index) = value;
}


void displayArray( int *pArray, // the array
     int & topIndex) // top array entry index
{
 int i;
 
 cout<<\"Contents of array is: \";
 cout<<\"\\nIndex: \";
 for (i=0; i<= topIndex; i++)  {
  cout<<\" \"<<i;
 }
 cout<<endl<<\"Values: \";
 for (i=0; i<= topIndex; i++)  {
  cout<<\" \"<<*(pArray + i);
 }
 cout<<endl; 
}


int main( void )
{
 int *pArray = NULL; // Pointer to the array
 int arraySize = 0;
 int topIndex = 0; // Points to the next open array spot
 int notDone = TRUE; // main loop flag
 int value;   // value to be stored in array
 int index;   // position in which to store or retrieve value
 char menuChoice; // stores menu choice
 
 do  {

  cout<< \"    \\n\\n\";
                cout<< \" Choose an option: \\n\";
                cout<< \" s. Store a value into the array.\\n\";
                cout<< \" r. Retrieve a value from the array. \\n\";
                cout<< \" d. Display contents of array.\\n\";
                cout<< \" x. Exit program.\\n\";
                cout<<endl;
                cout<< \"Your choice --> \";
                cin>>menuChoice;
  
  switch( menuChoice)  {
   case \'s\': // Store value into array
                                        cout<< \"Enter value & index: \" ;
                                        cin>>value>>index;
     store( pArray, arraySize, topIndex, value, index);
     break;
   case \'r\': // Retrieve value from array

     cout<< \"Enter index of value to retrieve: \";
     cin>>index;
     cout<<\"Value is: \"<< retrieve(pArray, topIndex, index) <<endl;

     break;
   case \'d\': // display array contents
     displayArray( pArray, topIndex);
     break;
   case \'x\': // Exit program
     notDone = FALSE;
     break;
  }
  
 } while ( notDone);
 
 return 0;
}

","","dynamicArray 3","Dale Reed","Tue Aug 27 23:22:06","0","0","1","155",""); INSERT INTO exdata VALUES("26","1","1","\r\n\r\n\r\n\r\n\r\n






















































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
\r\n

#include <stdio.h>
#include <stdlib.h>
#define EXIT_SUCCESS 0

/* declare a self-referential structure */
typedef  struct elephant {
     char             name[ 10 ];
     struct elephant  *next;
} ELEPHANT;

void      print_elephants( const ELEPHANT *ptr );
ELEPHANT  *get_elephants( void ), *start;

main()
{
     start = get_elephants();
     print_elephants( start );

     return EXIT_SUCCESS;
}

/*   get_elephants allocates run-time storage for nodes. It builds
     the linked list and stores user-supplied names in the name
     fields of the nodes. It returns a pointer to the first such
     node.                                                         */

ELEPHANT *get_elephants( void )
{
     ELEPHANT  *current, *first;
     int response;

     /* allocate first node */
     current = first = (ELEPHANT *) malloc( sizeof ( ELEPHANT ) );

     /* store name of first elephant */
     printf( \"\\n\\n\\tNAME:\\t\" );
     scanf( \"%s\", current -> name );

     /* prompt user about another elephant */
     printf( \"\\n\\n\\n\\tAdd another? (1 == yes, 0 == no)\\t\" );
     scanf( \"%d\", &response );

     /* Add elephants to list until user signals halt. */
     while ( response ) {
          /* try to allocate another elephant node */
          if ( ( current -> next =
               (ELEPHANT *) malloc( sizeof ( ELEPHANT ) ) ) ==
               NULL ) {
               printf( \"Out of memory\\nCan\'t add more elephants\\n\" );
               return first;
          }
          current = current -> next;

          /* store name of next elephant */
          printf( \"\\n\\n\\tNAME:\\t\" );
          scanf( \"%s\", current -> name );

          /* prompt user about another elephant */
          printf( \"\\n\\n\\n\\tAdd another? (1 == yes, 0 == no)\\t\" );
          scanf( \"%d\", &response );
     }

     /* set link field in last node to NULL */
     current -> next = NULL;

     return first;
}

/*   print_elephants steps through the linked list pointed to by ptr
     and prints the name field in each node as well as the position
     of the node in the list                                       */

void  print_elephants( const ELEPHANT *ptr )
{
     int count = 1;

     printf( \"\\n\\n\\n\" );
     while ( ptr !=  NULL ) {
          printf( \"\\nElephant number %d is %s.\",
               count++, ptr -> name );
          ptr = ptr -> next;
     }
}

","","elephant2","Dale Reed","Thu Jan 16 02:49:10","19","1","1","87",""); INSERT INTO exdata VALUES("27","1","1","\r\n\r\n\r\n\r\n\r\n




















































































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
\r\n

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define TRUE 1
#define FALSE 0

typedef struct node * pNodeStruct;
typedef struct node {
 int data; 
 pNodeStruct pNext;
} NodeStruct;


// findNthNode - find nth node in list that starts at ptr. Return it\'s address.

pNodeStruct findNthNode( pNodeStruct ptr, // list to search
   int n)   // index of element
{
   if ( n<1)
      return NULL;
   while ( --n && ptr != NULL)
      ptr = ptr->pNext;  // advance to next node
   return ptr;   // return address of found node (or NULL)
}


// addAtNthNode - Add node \"new\" into list \"ptr\" at position \"n\", returning
//                the address of the head of the list.  Note that the first
//            node on the list is node \"1\" according to the interface.
//

pNodeStruct addAtNthNode( pNodeStruct ptr,  // Existing list
            pNodeStruct newNode,  // Node to be inserted
     int n)  // Position at which to add new node
{
   pNodeStruct pred;
  
   // See if we\'re inserting at the beginning of the list
   if (n == 1) {
      newNode->pNext = ptr;
      return newNode;  // we have a new list head
   }
  
   // Find the node _before_ the node where we insert.
   pred = findNthNode( ptr, n-1);
  
   if ( pred == NULL) {
     cout<<\"*** Invalid operation, there is no node \"<<n<<endl;
   }

   else { 
    // The predecessor to position \"n\" was found
 // Place the \"newNode\" node _after_ the node pointed to by \"pred\"
 newNode->pNext = pred->pNext;
 pred->pNext = newNode;
   }
  
   return ptr;    // the head of the list is unchanged
}

// deleteNthNode - Delete node at position \"n\" from list, returning an
//    indicator of success or failure.
//    Illustrates passing the list head as a reference parameter, using
//    C++ conventions.  Note that this could also be declared as
//    \"struct node * & head\", but not as \"struct node & * head\".
//
void deleteNthNode( pNodeStruct  & head,  // the list containing the node
      int n,    // index of node to be deleted
      int &successFlag)  // returns TRUE or FALSE
{
   pNodeStruct pred, old;
  
   // first check for the case when we delete 1st list element
   if( n==1) {
      if ( head== NULL) {
         successFlag = FALSE; // Deletion failed, list is empty
         return;  // list head is unchanged
      }
      else {
  // list is non-empty, so delete first element
  old = head;
  head = head->pNext; // head of list is changed
      }
   }
   else {
      // deleted an element that is not the first element
      pred = findNthNode( head, n-1); // find predecessor of node to delete
      if ( (pred == NULL) || (pred->pNext == NULL) )  {
        // couldn\'t find predecessor, or \"predecessor\" is last node in list
          successFlag = FALSE;  // Deletion failed, desired node not in list
          return;       // Return, list is unchanged
      }
      // Desired node is in the list, so delete it
      old = pred->pNext;
      pred->pNext = old->pNext;
   }
  
   // deallocate the memory for the node that has been removed from the list
   free( old);
   successFlag = TRUE;  // Deletion succeeded
}

// displayList - Traverse the list, displaying the elements
//
void displayList( pNodeStruct head)
{
   pNodeStruct pTemp = head;  // Used to traverse list without destroying head
  

   cout<<endl<<\"List contains: \";
   while( pTemp != NULL) {
     cout<<\" \"<<pTemp->data;
      pTemp = pTemp->pNext;
   }
   cout<<endl<<endl;
}

// main - main part of program
//
void main()
{
   int position;       // position at which to place value in list
   pNodeStruct head = NULL;   // head of linked list
   pNodeStruct pTemp;       // temporary node pointer used in malloc
   char menuChoice;           // Menu choice
   int result;        // Result of delete node operation

   cout<<\"This program manipulates a linked list.\"<<endl<<endl;

   do {
    cout<<endl<<\"Please select the letter for one of these options: \";
    cout<<endl<<\"   I Insert a number into the list. \";
    cout<<endl<<\"   D Delete a number from the list. \";
    cout<<endl<<\"   P Print the list contents to the screen.\";
    cout<<endl<<\"   X Exit the program. \";
    cout<<endl<<\" \\n\";
    cout<<endl<<\"Your choice: \";
    cin>>menuChoice;
    menuChoice = tolower( menuChoice); // convert to lower case
   
    // Infinite loop
    switch (menuChoice) {
       case \'i\':   // Insert into list
                  cout<<\"Enter value to be placed in list and position: \";
            pTemp = new NodeStruct;
     // (pNodeStruct) malloc ( sizeof(struct node));
     cin>>pTemp->data>>position;   
            head = addAtNthNode( head, pTemp, position);
     break;
             
       case \'d\':   // Delete from list
                   cout<<\"Enter the position of node to be deleted: \";
     cin>>position;

                   deleteNthNode( head, position, result);
                   if (result == FALSE) {
                      printf(\"*** Delete operation failed for node %d. \\n\", position);
                   }
           break;
             
       case \'p\':   // Print the list to the screen
                   displayList( head);
           break;
             
       case \'x\':   // Exit program
                   cout<<\"Exiting program... \"<<endl;
                   exit( 0);
           break;
             
       default:    cout<<\"*** Invalid menu option, please retry.\"<<endl;
           break;
    }
   } while ( TRUE);

}

","","linkedList","Dale Reed","Thu Jan 16 02:48:54","16","1","1","181",""); INSERT INTO exdata VALUES("28","1","1","\r\n\r\n\r\n\r\n\r\n































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
\r\n

#include <iostream.h>
#include <stdlib.h>

typedef struct node * pNode;
struct node {
 int data;
 pNode next; 
};

// function prototypes
void insert( pNode &, int);
void printList( pNode);


void main( void )
{
 pNode head = NULL;
 int number = 0;
      
        cout<<\"This program stores numbers in ascending order in a list.\"<<endl;
 cout<<\"Enter integers one at a time followd by EOF (^d on UNIX, ^z on PC).\"<<endl;

// while ( scanf(\"%d\", &number) != EOF) {
 while (!cin.eof()){
   cin>>number;
   insert( head, number);
   printList( head);
   cout<<\"Enter a number or EOF: \"<<endl;
}
        cout<<\" Done. Exiting...\"<<endl;

}


// Display the current contents of the list
void printList( pNode head)
{
 printf(\"   The list is: \");
 while ( head != NULL)  {
  printf(\"%2d\", head->data);
  head = head->next;  
 }
 printf(\"\\n\");
}


// Insert a number in ascending order into the list. 
void insert( pNode & head,  // pointer to front of list
    int number)  // number to be inserted
{
 pNode newNode;  // stores new node for malloc
 pNode temp = head; // iterator to move down list
 
 // get new node
 newNode = new struct node;

 // Initialize values
 newNode->data = number;
 newNode->next = NULL;
 
 // Check to see if list is empty
 if (head == NULL)  { 
  // list is empty, so make this the first node
  head = newNode;
 }
 else  {
  // list is not empty
  temp = head;
  
  // Iterate through list to find insertion location
  // What happens if the \'>\' is changed to \'<\' below? E.g. 3 1 5 -1
  while ( (temp->next != NULL) && (number > temp->next->data) )  {
   temp = temp->next;  // advance to next node
  }
  
  // See if number goes at front of list
  if ( number < head->data)  {
   // insert at front of list
   newNode->next = head;
   head = newNode;
  }
  else {
   // Node goes in the middle or at the end of list
   // Insert after node pointed to by temp
   newNode->next = temp->next; // redundant assignment of NULL
          // if appending to end of list
   temp->next = newNode;
  }
  
 } // end else
 
}

","","List Insert","Dale Reed","Thu Jan 16 02:50:41","1","0","1","96",""); INSERT INTO exdata VALUES("19","1","1","\r\n\r\n\r\n\r\n\r\n























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
\r\n

#include <iostream.h>

main()
{
 char menuChoice;

    for ( ; ; )  {    // Begin infinite loop
  cout << \"Enter menu choice between 1 & 5: \";
  cin >> menuChoice;
  
  if ( (menuChoice >= \'1\') && (menuChoice <= \'5\') )
     break;    // Exit this infinite loop
 
  cout << \"That\'s dumb. DUMB. You chose \" << menuChoice << \"???  GET A CLUE!!!.\\n\";  
  cout << \"  (Oops - I forgot where I was.) Actually I meant \\n\";
  cout << \"Sorry, that was invalid. \";  
 }
 
 cout << \"Good job.  You selected a valid option. You get an A.\\n\";
}

","

The program is an infinite loop requesting for input between 1-5 to exit, otherwise it will ask for the input again indefinitely.

\r\n

12 If input is between 1-5, the program \"jumps\" out of the loop and executes statements outside the for-loop.

\r\n

17 If the program executes up to here, that means the choice was not between 1-5.  Therefore execution will go back up to line 7

\r\n

 

","break","Dale Reed","Mon Sep 09 15:40:25","18","1","1","24",""); INSERT INTO exdata VALUES("20","1","1","\r\n\r\n\r\n\r\n\r\n























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
\r\n

#include <iostream.h>

main()
{
 int firstNumber, secondNumber;

    for ( ; ; )  {    // Begin infinite loop
  cout << \"Enter two integers, where we will divide the first by the second: \";
  cin >> firstNumber >> secondNumber;
  
  if ( secondNumber == 0 ) {
   cout << \"Divide by 0? Redefining mathematics, are we?\\n\";
     continue;    // Try again
  }
 
  cout << firstNumber << \" / \" << secondNumber << \" = \" << firstNumber/secondNumber << \"\\n\";
 }
 
 cout << \"You will never see this secret message. My locker combination is: 22-46-19.\";
}

","

7 : We begin an infinite loop.
13 : if 0 was entered as the second number, the continue statement goes back to the top of the loop and starts again
without executing any statements below it.

","Continue","Dale Reed","Tue Sep 10 16:28:57","17","1","1","24",""); INSERT INTO exdata VALUES("21","1","1","\r\n\r\n\r\n\r\n\r\n

















































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
\r\n

#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#include <string.h>

#define NUMRECS 5
#define RECSIZE 10

char *array=NULL;

void displayArray( char *array)
{
   int i;

   cout<<\"Just entered fcn displayArray()...\\n\";

   for (i=0; i<NUMRECS; i++) {
     cout<<&array[i*(RECSIZE+1)] <<\" \";
   }
}

void initArray( )
{
   int i;

   cout<< \"Just entered fcn initArray()...\\n\" ;
   array = new char[(RECSIZE+1) * NUMRECS];
   // IN C
   //   array = (char *) malloc (sizeof(char) * (RECSIZE+1) * NUMRECS );

   for (i=0; i<NUMRECS; i++)  {
     strcpy( &array[ i*(RECSIZE+1)], \"test\");
   }
}

void main()
{
   char c;

   cout<< \"\\nStarting program...\\n\";
   initArray( );
   displayArray( array);

   cout<< \"\\nPress return to continue...\\n\\n\";
   scanf(\"%c\", &c);
}

","","2d array","Dale Reed","Tue Aug 27 23:12:59","4","0","1","50",""); INSERT INTO exdata VALUES("22","1","1","\r\n\r\n\r\n\r\n\r\n



























































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
\r\n

#include <iostream.h>
#include <stdlib.h>

#define STACK_BLOCK_SIZE 3
#define EMPTY (-1)
     
char * growStack( char *elements, int &size);  
void push( char *elements, int &top, char ch); 
char pop( char *elements, int &top);    
int isEmpty( int top);   
int isFull( int top, int size);   

// Initialize the stack size
char * growStack( char* oldElements, int &size)
{
 char *newElements; // pointer to new stack
 int index;   // index into stack, used for copying

 cout<<\"Stack is growing to size \"<< (size + STACK_BLOCK_SIZE) <<endl;

 // Allocate new memory in chunks so we don\'t have to do it each time
 newElements = new char[((size) + STACK_BLOCK_SIZE)];
 // IN C
        // newElements = (char *) malloc( (sizeof( char) * ((*size) + STACK_BLOCK_SIZE)) );

 // Copy old array into new if old stack already exists
 if (oldElements) {  
  // not the first time, a stack already exists
  for ( index = 0; index < size; index++)  {
   newElements[ index] = oldElements[ index];
  }
 }

 size += STACK_BLOCK_SIZE; // set new stack size

        delete(oldElements);
       file://free( oldElements);   // Release old stack space
       
 return newElements;
}

// Insert character ch on the top of the stack
void push( char *elements, int &top, char ch)
{
 elements[ ++top] = ch;
}

// remove and return the top character on the stack
char pop( char *elements, int &top)
{
 return elements[ top--];
}

// return whether or not the stack is empty
int isEmpty( int top)
{
 return top == EMPTY;
}

// return whether or not the stack is full
int isFull( int top, int size)
{
 return top == size - 1;
}


int main()
{
 char *elements = NULL; // The stack
 int size = 0;   // size of the stack
 int top = EMPTY;  // index into stack
 int menuChoice;   // Stores menu choice
 char theCharacter;  // Used to store characters read in
 int i;     // loop counter

 cout<<\"Welcome to the stack program.\\n\";
 elements = growStack( elements, size); 

 do {
  cout<<endl;
  cout<< \" 1. Add a character to the stack.\\n\";
  cout<< \" 2. Remove a character from the stack.\\n\";
  cout<< \" 3. Display stack contents\\n\";
  cout<< \" 4. Exit this program.\\n\\n\";

  cout<< \" Please enter your choice-> \";
  cin>>menuChoice;      

  switch ( menuChoice) {
   case 1: // Add to stack if space available
     if ( isFull( top, size) ) { 
      elements = growStack(elements, size); 
     }
     cout<< \"\\n Enter a single character: \" ;
     cin>>theCharacter;
     push( elements, top, theCharacter); // push on the stack
     break;
   case 2: // retrieve from stack if not empty
     if ( !isEmpty( top) ) { 
      // retrieve from stack
      cout<< \"\\n Retrieved \"<<pop( elements, top)<<endl; 
     }
     else {
      cout<< \"*** Sorry, stack is empty.\\n\";
     }
     break;
   case 3: cout<< \"\\nThe stack contents is:\\n\";
     for (i=top; i>=0; i--)  {
      cout<<\"\\t \"<<elements[ i]<<endl ;
     }
     break;
   case 4: cout<< \"Exiting...\\n\";
     break;
   default:
     cout<< \"*** Invalid option, please retry.\\n\";
     break;
  }

 } while ( menuChoice != 4);
}

","","CharStack 2","Dale Reed","Tue Aug 27 23:17:21","0","0","1","124",""); INSERT INTO exdata VALUES("23","1","1","\r\n\r\n\r\n\r\n\r\n










































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
\r\n

#include <iostream>
#include <stdlib.h>
#include <assert.h>


#define INCREMENT 5
#define TRUE 1
#define FALSE 0

/*
 * Global variables
 *
 */
int *pArray = NULL; // Pointer to the array
int arraySize = 0; // Current size of the array
int topIndex = 0;  // Points to the next open array spot


int retrieve( int index)  
{
 // Return array item at position \"index\"
 
 // valid index goes from 0 to arraySize - 1
 if ( ( index > (arraySize-1)) || (index < 0))  {
  // Sanity check for valid index value
  cout<< \"There is data in the array, but that index is invalid.\\n\";
  cout<< \"Index must be between 0 and \"<<(arraySize-1)<<endl;
  cout<< \"Please try again.\\n\" ;
  return -1;
 }
 
 // Index must be valid to get here
 return pArray[ index];   file://same as: return *(pArray + index); 
}


void store( int value,    // value to be stored in array
            int index)   // position at which to store the value
{
 int *pTemp = NULL;   // temporary array pointer
 int i;                     // loop counter
 
 if ( index >= arraySize)  {
  // Allocate space for new, bigger array
  cout<<\" Growing array size from \"<<arraySize<<\" to \"<<(index + INCREMENT);

  pTemp = new int[index+INCREMENT];
  //  pTemp = (int *) malloc( (index + INCREMENT) * (sizeof( int)));
  assert( pTemp != NULL);  // sanity check on memory allocation
  // copy old array into new array
  for (i=0; i<arraySize; i++)  {
   pTemp[ i] = pArray[ i];  // same as *(pTemp+i) = *(pArray+i) 
  }
  // initialize new space in array to 0.  Indices of new space
  // starts at \"arraySize\" and goes to \"index + INCREMENT\"
  for (i=arraySize; i< (index + INCREMENT); i++)  {
   pTemp[ i] = 0;   // same as  *(pTemp + i) = 0
  }
  
  // free space from old array if there was any
  if ( pArray != NULL) { 
   free( pArray); 
  }
  // make old pointer point to new array
  pArray = pTemp;
  // Update new size of array
  arraySize = index + INCREMENT;
 }
 
 // We know there is space for the element to be added at this point,
 // Store the value in the appropriate spot
 pArray[ index] = value;    // same as:  *(pArray + index) = value;
}


void displayArray() 
{
 int i;
 
 cout<<\"Contents of array is: \" ;
 cout<< \"\\nIndex: \" ;
 for (i=0; i < arraySize; i++)  {
   cout<<\" \"<<i;
   //  printf( \"%2d \", i );
 }
 cout<< \"\\nValues: \" ;
 for (i=0; i < arraySize; i++)  {
   cout<<*(pArray+i) <<\" \";
 }

 cout<<endl;
}


int main( void )
{
 int notDone = TRUE; // main loop flag
 int value;  // value to be stored in array
 int index;  // position in which to store or retrieve value
 char menuChoice; // stores menu choice
 
 do  {
  cout<< \"    \\n\\n\";
  cout<< \" Choose an option: \\n\";
  cout<< \" s. Store a value into the array.\\n\";
  cout<< \" r. Retrieve a value from the array. \\n\";
  cout<< \" d. Display contents of array.\\n\";
  cout<< \" x. Exit program.\\n\";
  cout<<endl;
  cout<< \"Your choice --> \";
  cin>>menuChoice;
  
  switch( menuChoice)  {
   case \'s\': // Store value into array
     cout<< \"Enter value & index: \"; 
         cin>>value>>index;
     store( value, index);
     break;
   case \'r\': // Retrieve value from array
     cout<< \"Enter index of value to retrieve: \";
     cin>>index;
     cout<< \"Value is: \"<<retrieve(index)<<endl; 
     break;
   case \'d\': // display array contents
     displayArray();
     break;
   case \'x\': // Exit program
     notDone = FALSE;
     break;
  }
  
 } while ( notDone);
 
 return 0;
}

","","dynamicArray","Dale Reed","Tue Aug 27 23:18:47","5","0","1","139",""); INSERT INTO exdata VALUES("15","1","1","\r\n\r\n\r\n\r\n\r\n


























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
\r\n

#include <iostream.h>
#include <string.h>

void main()
{
 char aString[] = {\"First second third words \\n next line\"};
 char *pWord;    // Pointer to part of a string
 
 cout<<\"The string to use is: \"<<endl<<aString<<endl;
 
 // pWord will point to the first word in aString, and strtok will
 // replace the first space with \'\\0\'
 pWord = strtok( aString, \" \");          // search for a space
 while (pWord != NULL)  {
        cout<<\" TOKEN: \"<< pWord<<endl;  // display token
        // On subsequent calls strtok will advance pWord to the
        // beginning of the next word within aString, again replacing
        // the next space with \'\\0\'    
        pWord = strtok( NULL, \" \");             // get text token
 }
 
 cout<<\"Done.\"<<endl;
}

","

Illustrate parsing input using strtok.
13: replace the first space (whitespace) with the aString string.
14: while (not at the end of the word)
15: print out the first \'token\' up until the new null point
19: replace the next space with null and loop again

","Parse","Dale Reed","Tue Sep 10 17:41:12","8","1","1","27",""); INSERT INTO exdata VALUES("16","1","1","\r\n\r\n\r\n\r\n\r\n




































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
\r\n

#include <iostream.h>
#include <string.h>

void permute( char lettersSoFar[], char remainingLetters[])
{
   int i;
   // Now store the beginning address of the letters to be printed
   // Making this static is as if it is global, but local in scope.
   static char *originalString = lettersSoFar;
  
   for (i=0; i< strlen(remainingLetters); i++)  {
      // Store next char. into lettersSoFar
      lettersSoFar[ 0] = remainingLetters[ i];
     
      // Store Null so we can print
      lettersSoFar[ 1] = \'\\0\';
      cout<< originalString<<endl;
     
      // Add other characters onto this by recursing
      permute( &lettersSoFar[ 1], &remainingLetters[ i+1]);
   }
}


void main()
{
 char word[]=\"abc\";
 char answer[]=\"   \";
 
 // Hold your breath ...
 permute( answer, word);
 
}

","

Generate the permutations of a string.

\r\n

25: Start at main()
31: start the functions with the initialized arrays as parameters

4: permute (..) function
11: ass the boundary of the loop, strlen(remainingLetters) returns the length of the remainingLetters array
13: the first spot in remainingLetters is copied to lettersSoFar
16: null is copied to the second spot in lettersSoFar so we can print this as a string
17: the static variable originalString is printed.
20: We recursively call the permute(..) function with 1 added to the current spot we are in in the loop, thus going to the next letter in the remainingLetters array.

","String Permutations","Dale Reed","Tue Sep 10 17:58:35","14","1","2","37",""); INSERT INTO exdata VALUES("17","1","1","\r\n\r\n\r\n\r\n\r\n



























































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
\r\n

#include <iostream.h>
#include <fstream.h>
#include <string.h>

// Depending on the computer, if the values below are too large,
//   your program will cause a \"segmentation fault.\"  I suggest
//   you make the value of MAXLENGTH something smaller in this case.
#define MAXLENGTH 30
#define ROWS 26000


void readDictionary(
 ifstream &fin,
 char fileName[],  // input file name
 char words[][ MAXLENGTH],  // array of dictionary words
 int &currentRow)   // number of words in dictionary
{
 char tempString[MAXLENGTH]; // stores a single string
 int  size;   // string size
  
 cout<<\"\\n Reading dictionary file from \"<<fileName<<endl;
 currentRow = 0;

 while ( !(fin.eof()) ) {

  fin>>tempString;
  size = strlen( tempString);

  /* Only store words that aren\'t too long */
  if ( size < MAXLENGTH )
   strcpy( words[ (currentRow)++], tempString);

  /* Verify that we still have room in array*/
  if ( currentRow >= ROWS)  {
   /* Bomb out of program */
   cout<<\"Exceeded row limit where currentRow = \"<<currentRow<<endl;
   cout<<\"  Exiting program...\"<<endl;
   exit( -1);
  }
 }

}


void displayWords(
 char theWords[][ MAXLENGTH],  // array of dictionary words
 int limit,   // number of words in dictionary
 int min,   // min size of word to display 
 int max)   // max size of word to display
{
 int size; // stores size of strings
 int i;  // loop counter   

 cout<<\"\\nWords stored in array are: \\n\";
 for (i=0; i<limit; i++) {
  size = strlen( theWords[ i]);
  if ( (size >= min) && (size <= max) )
   cout<<theWords[ i]<<endl;
 }
 cout<<endl;  // leave an extra line at the end
}


main()
{
 ifstream fin;
 char fileName[] = \"words.txt\"; // Input file name
 char words[ ROWS][MAXLENGTH];  // array of dictionary words
 int numberOfRows= 0;   // number of dictionary words
 int i;    // loop counter
 int displaySizeMax;  // Max size string to display
 int displaySizeMin;  // Min size string to display
 

 // Read words from input file into dictionary array
 fin.open(fileName);

 readDictionary( fin, fileName, words, numberOfRows);

 fin.close();

 // Selectively display words from dictionary array 
 cout<<\"Please enter min. and max. sizes of strings to display: \";
 cin>>displaySizeMin>>displaySizeMax;

 displayWords( words, numberOfRows, displaySizeMin, displaySizeMax);

}

","

Read in words from file words.txt and store in an array of
 predetermined size.  Prompt for max. size of words to be displayed
 and display those words from the array

\r\n

 Note how the array is declared, passed to functions, and used.
 Unless you are running this on the departmental machines, you will
 probably have to make the dictionary array smaller for it to work.

\r\n

8, 9: macros for defining MAXLENGTH and ROWS

\r\n

in main()
66: declare the file input pointer fin
76: open the file
78: call the readDictionary(...) function

in readDictionary(...)
24: while(not at the end of the file
27: get the size of the string and store it in the variable size
31: if the word is less than MAXLENGTH, copy the tempString variable into the words array at the currentRow, then increase it by one, ++, after it has been stored.

\r\n

in display words(...)
55: loop until limit has been reach
56: get the size of the word at the i\'th position in the theWords[] array
57: if the size is greater than or equal to min AND less than or equal to max, print out this word

","readWords","Dale Reed","Mon Jan 20 01:30:47","13","1","2","92",""); INSERT INTO exdata VALUES("18","1","1","\r\n\r\n\r\n\r\n\r\n














































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
\r\n

#include <iostream.h>
#include <strings.h>

void main()
{
 /* Word number:     1  2  3  4   5   6     7      */
 char fullText[] = {\"A man a plan a canal Panama\"};
 char word2[] = {\"man\\0\"};
 char word4[] = {\"plan\\0\"};
 char userword[ 81];
 int spacePosition;
 
 cout<<\"The stored words are: \\nfullText: \"<< fullText;
 cout<<                      \"\\n   word2: \"<< word2;
 cout<<                      \"\\n   word4: \"<< word4;
 cout<<endl<<endl;
 
 /* Illustrate strcat */
 cout<<\"strcat( word4, word2) is: \"<< strcat( word4, word2) ;
 cout<<                      \"\\n   word2: \"<< word2;
 cout<<                      \"\\n   word4: \"<< word4;
 cout<<endl<<endl;
 
 /* Illustrate strcmp, strcpy */
 cout<<\"strcmp( word2, word4) is \"<<strcmp( word2, word4) <<endl;

 cout<<\"Storing \\\"man\\\" into array \'userword\'\\n\";
 strcpy( userword, \"man\");
 cout<<\"strcmp( word2, userword) is \"<< strcmp( word2, userword) <<endl;
 cout<<\"strcmp( word2, \\\"man\\\") is \"<< strcmp( word2, \"man\") <<endl;

 cout<<endl;
 cout<<\"Enter a string to compare to \'\"<<word2<<\"\': \";
 cin>>userword; /* Note no & in front of userword */
 cout<< \"strcmp( word2, userword) is: \"<< strcmp( word2, userword) <<endl;

 /* Illustrate use of strlen */
 cout<<endl;
 cout<<\"Length of fullText array is: \"<< strlen( fullText)<<endl ;

 /* Illustrate use of strstr */
 cout<<endl;
 cout<<\"Printing fullText array starting from the text: \"<<word2<<endl;
 cout<<\"printf( strstr( fullText, word2)) gives: \\n\\t \"<<strstr( fullText, word2) <<endl;

 /* Illustrate how to pull out a substring */
 cout<<endl;
 cout<<\"The first space-delimited word in fullText is: \";
 /* find address of first space and do address arithmetic */
 spacePosition = strchr(fullText,\' \') - fullText;

 /* copy the word up until the space into \'userword\' */
 strncpy( userword, fullText, spacePosition);

 /* Now write a null string character after the word to terminate string*/
 userword[ spacePosition] = \'\\0\';
 cout<<userword<<endl;

 /* Now get the next one */
 cout<<\"Now getting the next word...\\n\";
  strcpy( userword, (strchr( fullText, \' \') + 1) );
 strcpy( fullText, userword);
 cout<<\"New version of fullText is: \"<< fullText<<endl;

 /* find address of first space and do address arithmetic */
 spacePosition = strchr(fullText,\' \') - fullText;

 /* copy the word up until the space into \'userword\' */
 strncpy( userword, fullText, spacePosition);

 /* Now write a null string character after the word to terminate string*/
 userword[ spacePosition] = \'\\0\';
 cout<< userword<<endl;
 

","

This example illistrates various string functions

19: Concatonate word2 to the end of word4 using strcat(...) , original contents of word2 are unchanged
25: The string compare, using strcmp, of word2 and word4 returns -3 since word2 is less than word4
29: Compare word2 to userword (has \"man\" stored) and it returns 0 indicating they are equal
30: The same thing is done here only \"man\" is explicitly used instead of the array username. The function sees only \"man\" in either case
39: the length of fullText is returned by the strlen( string ) function
44: the strstr function returns the string in fullText that starts at the point where word2 is found within the fullText array
50: The strchr returns the address of the first space in the fullText array. Then that address is subtracted by the address of the first position in fullText to get the first word that comes after a space in the fullText array. Then store the address into the spacePosition variable.
52: Use strncpy to copy the word up until the space into \'userword\'.
56: Print the word after the null character is placed on the end
61: Start this process again to get the next word.

","string functions","Dale Reed","Tue Sep 10 18:54:30","16","1","2","79",""); INSERT INTO exdata VALUES("13","1","1","\r\n\r\n\r\n\r\n\r\n








































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
\r\n

#include <iostream.h>
void main()
{
 /* variable name describes size */
 char junk[] = {\"*This is junk*\"};
 char name2[ 2];
 char name4[ 4];
   /* Note size: 12345678   (Extra character needed for \'\\0\') */
   /*            --------                                     */
 char name9[ ] = {\"original\"};   /* could be {\'o\',\'r\',\'i\', ...} */

 /* Initialize name2 explicitly within the program */ 
 name2[0] = \'z\';
 name2[1] = \'\\0\'; /* Last character in string must be \'\\0\' */
 
 /* Initialize name4 by prompting for the string. \\\\0 is added. */
 cout<<\"Please enter a 3 character string: \";
 cin>>name4; /* Note it is NOT \'&name4\'  */
 
 cout<<\"The original strings are: \"<<name2<<\"  \"<<name4<<\"  \"<<name9<<endl<<endl;
 
 /* Now start messing with them. */
 cout<<\"Watch what happens when we go past the end of name4..\\n\";
 cout<<\"First replace 4 characters starting at name4, \";
 cout<<\"  (\\\\0 goes away)    \\n\";
 name4[0]=\'m\'; name4[1]=\'n\'; name4[ 2] = \'o\'; name4[3] = \'p\';
 cout<<\"Now the strings are: \"<<name2<<\"  \"<<name4<<\"  \"<<name9<<endl<<endl;
 
 cout<<\"Now we replace the 5th & 6th characters starting at name4, \\n\";
 cout<<\"  which takes us into the next string. \\n\";
 name4[4]=\'1\'; name4[5]=\'2\'; name4[6]=\'3\'; name4[7]=\'4\';
 name4[8]=\'5\'; name4[9]=\'6\'; name4[10]=\'7\'; name4[11]=\'8\';
 name4[12]=\'9\'; name4[13]=\'0\'; name4[14]=\'1\'; name4[15]=\'2\';
 name4[16]=\'3\';
 cout<<\"Now the strings are: \"<<name2<<\"  \"<<name4<<\"  \"<<name9<<endl<<endl; 

}

","Demonstrate use of arrays to store strings.

Note that on this machine the arrays are stored as:
   name9
   name4
   name2
   junk
 So that overwriting \'name4\' takes us into \'name2\', and then into \'junk\'
 Note also what happens when you enter more than the 3 characters for
 which you are prompted! (messes up the other variables) ","arrayStringsEECS","Dale Reed","Tue Sep 10 16:55:37","5","1","1","41",""); INSERT INTO exdata VALUES("14","1","1","\r\n\r\n\r\n\r\n\r\n























































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
\r\n

#include <iostream.h>
#include <fstream.h>
#include <assert.h>
void main()
{
 char c;  // store an input character
 ifstream fin; // file pointer for input file
 ofstream fout; // file pointer for output file
 int key;  // key for transposition cipher
 char inFileName[ 10]; // stores file name
 char outFileName[ 10]; // stores file name
 char newChar;  // stores transposed character

 // Get file name information 
 cout<<\"Enter file name for input: \";
 cin>>inFileName;
 cout<<\"Enter file name for output: \";
 cin>>outFileName;

 cout<<\"Input filename is: \"<<inFileName<<endl;
 cout<<\"Output filename is: \"<<outFileName<<endl;
 
 fin.open(inFileName, fstream::in);
 fout.open(outFileName, fstream::out);

 if(fin==NULL) cout<<\"file not found\"<<endl;
 
 // check if files are properly opened or not.
 assert(fin);
 assert(fout);

 cout<<\"Files opened.\"<<endl;
 cout<<\"Please enter amount for transposition key: \";
 cin>>key;
 key = key % 128;
 // compensate for invalid mod functions w/ negative input
 if (key < 0)  {
  key = 128 + key; // subtract \'key\' amount
   }
 
 while( !(fin.eof()) ){
  fin>>c;
  newChar = (c+key)%128;
  fout<<newChar;
  cout<<newChar; 
 }

 cout<<endl;
 fin.close();
 fout.close();

}

","

23, 24: open both the input and output files using the fstream class
26  if fin.open(... ) at line 23 returned null, the file was either not found or could not be opened due to permissions
29: Use assert method to check if files were opened. Will abort program if they were not properly opened
35: Key cipher is key mod 128
41: while(not at the end of file)
42: input a character and then encode it
44: output the new character (newChar) to the opened output file

49, 50: close the input and output files.

","encode file contents","Dale Reed","Tue Sep 10 17:25:51","13","1","2","56",""); INSERT INTO exdata VALUES("10","1","1","\r\n\r\n\r\n\r\n\r\n



































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
\r\n

#include <iostream.h>
#include <iomanip.h>

#define LIMIT 100
#define TRUE 1
#define FALSE 0

/* Global data structures */
const int maze[ LIMIT]=
 {1,1,1,1,1,1,1,1,1,1,
  1,0,0,0,1,1,1,1,1,1,
  1,1,0,1,1,1,0,0,1,1,
  1,1,0,1,1,1,0,1,1,1,
  1,1,0,0,0,0,0,1,1,1,
  1,1,0,1,0,1,1,1,1,1,
  1,1,1,1,0,0,0,1,1,1,
  1,1,1,1,0,1,0,1,1,1,
  1,1,0,0,0,1,0,0,0,1,
  1,1,1,1,1,1,1,1,1,1};

const int start = 11;
const int finish = 88;
int cameFrom[ LIMIT];
int solutionFound = FALSE;


void makeMove( int current)
/* Now located at square \"current,\" where cameFrom[current] 
 * is the square number we came from.  Store that information.
 */
{
 static int moves[4]= {-1, -10, 1, 10};  // No diagonal moves
 int i, nextMove;
 
 cout<<\" \"<< current;   // Display square numbers as we go
 if (current == finish) {
    cout<<\" *** Reached finish! *** \";
    solutionFound = TRUE; // Set flag to prevent further moves
    return; //  Terminate the recursion at this level
 }
 for (i=0; i<4; i++) { // Try all four moves
 if (!solutionFound) {
  nextMove = current + moves[ i];
  if ((nextMove != cameFrom[ current]) && (maze[ nextMove] != 1)) {
    cameFrom[ nextMove] = current;
    makeMove( nextMove);
   }
  }
 }// end for (i=0...
}


void displaySolution( int current)
{
 if (current != start) {       // while I\'m not back at start
  displaySolution( cameFrom[ current]); // recurse
 }
 cout<<\" \"<<current;         // display square 
}
 
void initializeAndDisplayMaze()
{
        int i;
 
        /* Initialize \"cameFrom\" array to be all zeros */
        for (i=0; i<LIMIT; i++)
                cameFrom[ i] = 0;
 
        /* Display maze */
        cout<<\"\\n\\nMaze Traversal program for the maze:\\n\";
        cout<<\"   \";                        /*Display top labels*/
        for (i=0; i< 10; i++) cout<<setw(2)<<i;
        cout<<endl;
        cout<<\"   \";                        /*Display ruler line*/
        for (i=0; i< 10; i++) cout<<\"--\";
        cout<<endl;
        for (i=0; i< LIMIT; i++)  {
                if ( i%10 == 0) cout<<setw(2)<<i<<\"|\";  /*Left hand labels */
                        cout<<setw(2)<<maze[i];
                if ( (i+1)%10 == 0) cout<<endl;   /*End of line*/
                }
 
}


main()
{
 initializeAndDisplayMaze();
 cout<<\"Search Path Traversed:\\n\";
 
 makeMove( start);
 cout<<\"\\nSolution Path: \";
 displaySolution( finish);
 cout<<endl;

}

","","Maze 4","Dale Reed","Tue Aug 27 22:48:48","1","0","1","100",""); INSERT INTO exdata VALUES("11","1","1","\r\n\r\n\r\n\r\n\r\n





























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
\r\n

#include <iostream.h>

void main()
{
 /* Subscripts:   0  1  2  3  */
 /*              ------------ */
 int numbers[] = {2, 4, 6, 8};
 int *ptr;
 
 /* Show how array name is constant pointer */
 cout<<\"numbers is: \"<< numbers<<endl;
 cout<<\"numbers[0] is: \"<<numbers[0]<<endl;
 cout<<\"*numbers is: \"<< *numbers<<endl;
 cout<<\"*&numbers[0] is: \"<< *&numbers[0]<<endl<<endl;
 
 /* Show how a pointer can reference an array element */
 ptr = numbers;
 cout<<\"*ptr is: \"<< *ptr<<endl;
 cout<<\"ptr[1] is: \"<< ptr[1]<<endl;
 ptr = &numbers[ 2];
 cout<<\"After ptr = &numbers[ 2], *ptr is: \"<< *ptr<<endl<<endl;
 
 /* Show autoincrement */
 ptr++;   /* increment by one \"unit\" */
 cout<<\"After ptr++ , *ptr is: \"<< *ptr<<endl;
}

","

11 the variable used is the integer array \'numbers\'. This statement only prints out the address of the numbers array.
12: numbers[0] will print the first member of the array. Remember all arrays begin at 0 and not 1
13: *numbers dereferences the spot at numbers[0] and prints out the first member
14: *&numbers[0], first &numbers[0] grabs the address at spot zero (the beginning of the array and then dereferences it to
print out the first member. This is the same thing as using *numbers.

","Arrayptr 1","Dale Reed","Wed Sep 18 15:30:43","50","1","1","30",""); INSERT INTO exdata VALUES("12","1","1","\r\n\r\n\r\n\r\n\r\n







































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
\r\n

#include <iostream.h>
void main()
{
 /* variable name describes size */
 char junk[] = {\"*This is junk*\"};
 char name2[ 2];
 char name4[ 4];
   /* Note size: 12345678   (Extra character needed for \'\\0\') */
   /*            --------                                     */
 char name9[ ] = {\"original\"};   /* could be {\'o\',\'r\',\'i\', ...} */

 /* Initialize name2 explicitly within the program */ 
 name2[0] = \'z\';
 name2[1] = \'\\0\'; /* Last character in string must be \'\\0\' */
 
 /* Initialize name4 by prompting for the string. \\\\ 0 is added. */
 cout<<\"Please enter a 3 character string: \";
 cin>>name4; 
 cout<<\"The original strings are :\"<<name2<<\" \"<<name4<<\" \"<<name9<<\"\\n\\n\";
 
 /* Now start messing with them. */
 cout<<\"Watch what happens when we go past the end of name4..\\n\";
 cout<<\"First replace 4 characters starting at name4, \";
 cout<<\"  (\\\\0 goes away)    \\n\";
 name4[0]=\'m\'; name4[1]=\'n\'; name4[ 2] = \'o\'; name4[3] = \'p\';
 cout<<\"Now the strings are: \"<<name2<<\" \"<<name4<<\" \"<<name9<<\"\\n\\n\";

 cout<<\"Now we replace the 5th & 6th characters starting at name4, \\n\";
 cout<<\"  which takes us into the next string. \\n\";
 name4[4]=\'1\'; name4[5]=\'2\';

 /* Note: you must go all the way up to \'name4[16]=\'.\' on the  */
 /* CS system to see the problem there.  I think it has to */
 /*  do with the word size being larger on that machine.      */
 cout<<\"Now the strings are: \"<<name2 <<\" \"<< name4<<\" \"<< name9<<endl; 
}

","

Demonstrate use of arrays to store strings. Also see how one array
 overwrites the other when a larger string is entered.

\r\n

25 : We explicitly load the array with the values m,n,o,p into the consecutive spots

 Note that on this machine the arrays are stored as:
   name9
   name4
   name2
   junk
 So that overwriting \'name4\' takes us into \'name2\', and then into \'junk\'
 Note also what happens when you enter more than the 3 characters for
 which you are prompted! (messes up the other variables)

","arrayStrings","Dale Reed","Tue Sep 10 16:56:20","8","1","1","40",""); INSERT INTO exdata VALUES("1","1","1","\r\n\r\n\r\n\r\n\r\n




































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
\r\n

#include <iostream.h>

void main()
{
   int theScore;
   int sum=0;
   int count=0;
   int scores[ 10];  // indexed from 0 to 9
   int i;

   cout<<\"Enter scores, then -1 when done. \\n\\n\";

   for (i=0; i< 10; i++) {
      cout<<\"Enter score: \";
      cin>>theScore;

      // break out of loop if input was -1
      if (theScore == -1) {
         break;
      }
      scores[ i] = theScore;
   }

   count = i; // store i so we can reuse it
   cout<<\"\\nThe scores are: \";
   for (i=0; i<count; i++) {
      cout<<endl<< scores[ i];
      sum = sum + scores[ i];
   }
   cout<<endl;
   cout<<\"The average is: \"<<((float)sum/count)<<endl;

}

","

This program will input a maximum of 10 scores.
8 : We create an array of 10 elements.
13 : The variable \'i\' counts from 0 to 9 inputs from the user and exits the loop whenever -1 is entered.
26 : We loop through the array and add up the elements into the sum variable.
31 : Here we calculate the average and then cast it as a float to output in decimal form.

","Array 1","Dale Reed","Fri Sep 06 15:12:58","45","1","1","37",""); INSERT INTO exdata VALUES("2","1","1","\r\n\r\n\r\n\r\n\r\n




































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
\r\n

#include <iostream.h>
#include <iomanip.h>
#define LIMIT 10

void main()
{
   int sum=0;
   int count=0;
   int scores[ LIMIT];  // indexed from 0 to LIMIT-1
   int i;

   cout<<\"Enter scores, then -1 when done. \\n\\n\";

   for (i=0; i< LIMIT; i++) {
      cout<<\"Enter score: \";
      cin>>scores[ i];

      // break out of loop if input was -1
      if (scores[ i] == -1) {
         break;
      }
      sum+= scores[ i];
   }

   count = i; // store i so we can reuse it
   cout<<\"The scores are: \";
   for (i=0; i<count; i++) {
      cout<<endl<<scores[ i];
   }
 
   cout<<endl<<\"The average is: \"<< (float)sum/count<<endl;

}

","","Array 2","Dale Reed","Thu Mar 06 03:19:39","8","0","1","37",""); INSERT INTO exdata VALUES("3","1","1","\r\n\r\n\r\n\r\n\r\n
















































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
\r\n

#include <iostream.h>

#define LIMIT 10

// function that uses an array.
// Note that \"LIMIT\" inside the brackets could be omitted
void readIntoArray(int scores[ LIMIT], int &sum, int &count)
{
   int i;
  
   cout<<\"Enter scores, then -1 when done. \\n\\n\";

   for (i=0; i< LIMIT; i++) {
      cout<<\"Enter score: \";
      cin>>scores[ i];

      // break out of loop if input was -1
      if (scores[ i] == -1) {
         return;
      }

      sum+= scores[ i];
      count++;
   }
}

void main()
{
   int sum=0;
   int count=0;
   int scores[ LIMIT];  // indexed from 0 to LIMIT-1
   int i;

   // pass an array by using its name.  Changes to
   // the array are automatically reflected back.
   readIntoArray( scores, sum, count);
  
   cout<<\"The scores are: \";
   for (i=0; i<count; i++) {
      cout<<endl<<scores[ i];
   }

   cout<<endl<<\"The average is: \"<<(float)sum/count<<endl;

}

","","Array 3","Dale Reed","Tue Aug 27 22:36:45","3","0","1","49",""); INSERT INTO exdata VALUES("4","1","1","\r\n\r\n\r\n\r\n\r\n































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
\r\n

#include <iostream.h>

void main()
{
   int theScore;
   int sum=0;
   int count=0;

   cout<<\"Enter scores, then -1 when done. \\n\\n\";

   do {
      cout<<\"Enter score: \";
      cin>>theScore;

      // break out of loop if input was -1
      if (theScore == -1) {
         break;
      }
     
      // accumulate the sum and increment counter
      sum+= theScore;
      count++;
     
   } while (theScore != -1); // ending case is redundant

   cout<<endl<<\"The average is: \"<<((float)sum/count)<<endl;

}

","","doWhile","Dale Reed","Tue Aug 27 22:40:34","1","0","1","32",""); INSERT INTO exdata VALUES("5","1","1","\r\n\r\n\r\n\r\n\r\n
















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
\r\n

#include <iostream.h>

void main()
{
   int score1, score2, score3;
  
   cout<<\"Enter 3 scores: \";
   cin>>score1>>score2>>score3;
   cout<<endl;

   cout<<\"The scores are: \"<<endl<< score1<<endl<<score2<<endl<<score3<<endl;
   cout<<\"The average is: \"<< ( (float)(score1+score2+score3)/3 )<<endl;
}

","","Many Variables","Dale Reed","Tue Aug 27 22:41:26","1","0","1","17",""); INSERT INTO exdata VALUES("6","1","1","\r\n\r\n\r\n\r\n\r\n


















































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
\r\n

#include <stdio.h>

void main()
{
   int theScore;
   int sum=0;
   int count=0;
   char initial=\'R\';
   int scores[ 10];  // indexed from 0 to 9
   int i;

   printf(\"Enter scores, then -1 when done. \\n\\n\");

   for (i=0; i<10; i++) {
      printf(\"Enter score: \");
      scanf(\"%d\", &theScore);

      // break out of loop if input was -1
      if (theScore == -1) {
         break;
      }
      scores[ i] = theScore;
      sum+= theScore;
      count++;
   }
   printf(\"\\n\");

   // See what is stored in the variables
   printf(\"Before overwriting the array: \\n\");
   printf(\"My last name initial is: %c\\n\", initial);
   printf(\"count is : %d\\n\", count);
   printf(\"sum is: %d\\n\\n\", sum);

   // write the integer 65 to the array, and go past the end of the array
   for (i=0; i<20; i++) {
          // array is size 10, but we write 20 times!
      scores[ i] = 65;
   }

   // The values that used to be stored have been changed because
   // we wrote past the end of the array.
   printf(\"AFTER overwriting the array: \\n\");
   printf(\"My last name initial is: %c\\n\", initial);
   printf(\"count is : %d\\n\", count);
   printf(\"sum is: %d\\n\\n\", sum);

}

","","Overwrite","Dale Reed","Tue Aug 27 22:43:14","0","0","1","51",""); INSERT INTO exdata VALUES("7","1","1","\r\n\r\n\r\n\r\n\r\n




















































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
\r\n

#include<iostream.h>
#include<iomanip.h>

#define LIMIT 100

/* Global data structures */
const int maze[ LIMIT]=
        {1,1,1,1,1,1,1,1,1,1,
  1,0,0,0,1,1,1,1,1,1,
  1,1,0,1,1,1,0,0,1,1,
  1,1,0,1,1,1,0,1,1,1,
  1,1,0,0,0,0,0,1,1,1,
  1,1,0,1,0,1,1,1,1,1,
  1,1,1,1,0,0,0,1,1,1,
  1,1,1,1,0,1,0,1,1,1,
  1,1,0,0,0,1,0,0,0,1,
  1,1,1,1,1,1,1,1,1,1};

const int start = 11;
const int finish = 88;
int cameFrom[ LIMIT];

void makeMove( int current)
/* Now located at square \"current,\" where cameFrom[current] is the
 * square number we came from.  Store that information.
 */
{
   static int moves[4]= {-1, -10, 1, 10};  /* No diagonal moves */
   int i, nextMove;

   cout<<\" \"<<current;   /*Display square numbers as we go */
   if (current == finish) {
      cout<<\" *** Reached finish! *** \";
      return; /* Terminate the recursion at this level */
   }
   for (i=0; i<4; i++) { /*Try all four moves */
      nextMove = current + moves[ i];
      if ((nextMove != cameFrom[ current]) && (maze[ nextMove] != 1)) {
         cameFrom[ nextMove] = current;
         makeMove( nextMove);
      }
   }
}

void displaySolution()
{
}

void initializeAndDisplayMaze()
{
   int i;

   /* Initialize \"cameFrom\" array to be all zeros */
   for (i=0; i<LIMIT; i++)
      cameFrom[ i] = 0;

   /* Display maze */
   cout<<\"\\n\\nMaze Traversal program for the maze:\\n\";
   cout<<\"   \";                        /*Display top labels*/
   for (i=0; i< 10; i++) cout<<setw(2)<<i;
   cout<<endl;
   cout<<\"   \";                        /*Display ruler line*/
   for (i=0; i< 10; i++) cout<<\"--\";
   cout<<endl;
   for (i=0; i< LIMIT; i++)  {
      if ( i%10 == 0) cout<<setw(2)<<i<<\"|\";  /*Left hand labels */
       cout<<setw(2)<<maze[i];
      if ( (i+1)%10 == 0) cout<<endl;   /*End of line*/
   }
}

main()
{
   initializeAndDisplayMaze();
   cout<<\"Search Path Traversed:\\n\";

   makeMove( start);
   displaySolution();
   cout<<endl;

}

","","Maze 1","Dale Reed","Tue Aug 27 22:45:30","6","0","1","85",""); INSERT INTO exdata VALUES("8","1","1","\r\n\r\n\r\n\r\n\r\n



























































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
\r\n

#include<iostream.h>
#include<iomanip.h>

#define LIMIT 100

/* Global data structures */
const int maze[ LIMIT]=
        {1,1,1,1,1,1,1,1,1,1,
  1,0,0,0,1,1,1,1,1,1,
  1,1,0,1,1,1,0,0,1,1,
  1,1,0,1,1,1,0,1,1,1,
  1,1,0,0,0,0,0,1,1,1,
  1,1,0,1,0,1,1,1,1,1,
  1,1,1,1,0,0,0,1,1,1,
  1,1,1,1,0,1,0,1,1,1,
  1,1,0,0,0,1,0,0,0,1,
  1,1,1,1,1,1,1,1,1,1};

const int start = 11;
const int finish = 88;
int cameFrom[ LIMIT];

void makeMove( int current, int from)
/* Now located at square \"current,\" where cameFrom[current] is the
 * square number we came from.  Store that information.
 */
{
   static int moves[4]= {-1, -10, 1, 10};  /* No diagonal moves */
   int i, nextMove;

   cout<<\" \"<<current;   /*Display square numbers as we go */
   cameFrom[ current] = from;
   if (current == finish) {
      cout<<\" *** Reached finish! *** \";
      return; /* Terminate the recursion at this level */
   }
   for (i=0; i<4; i++) { /*Try all four moves */
      nextMove = current + moves[ i];
      if ((nextMove != cameFrom[ current]) && (maze[ nextMove] != 1)) {
         makeMove( nextMove, current);
      }
   }
}

void displaySolution()
{
 int i;
  cout<<\" \\n The solution (in reverse order) is: \";
  for ( i=finish; i!=0; i=cameFrom[i] ) {
     cout<<i <<\" \";
  }
  cout<<endl;

}

void initializeAndDisplayMaze()
{
   int i;

   /* Initialize \"cameFrom\" array to be all zeros */
   for (i=0; i<LIMIT; i++)
      cameFrom[ i] = 0;

   /* Display maze */
   cout<<\"\\n\\nMaze Traversal program for the maze:\\n\";
   cout<<\"   \";                        /*Display top labels*/
   for (i=0; i< 10; i++) cout<<setw(2)<<i;
   cout<<endl;
   cout<<\"   \";                        /*Display ruler line*/
   for (i=0; i< 10; i++) cout<<\"--\";
   cout<<endl;
   for (i=0; i< LIMIT; i++)  {
      if ( i%10 == 0) cout<<setw(2)<<i<<\"|\";  /*Left hand labels */
       cout<<setw(2)<<maze[i];
      if ( (i+1)%10 == 0) cout<<endl;   /*End of line*/
   }
}

main()
{
   initializeAndDisplayMaze();
   cout<<\"Search Path Traversed:\\n\";

   makeMove( start, 0);
   displaySolution();
   cout<<endl;

}

","","Maze 2","Dale Reed","Tue Aug 27 22:46:29","1","0","1","92",""); INSERT INTO exdata VALUES("9","1","1","\r\n\r\n\r\n\r\n\r\n





































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
\r\n

#include<iostream.h>
#include<iomanip.h>

#define LIMIT 100
#define TRUE 1
#define FALSE 0

/* Global data structures */
const int maze[ LIMIT]=
  {1,1,1,1,1,1,1,1,1,1,
   1,0,0,0,1,1,1,1,1,1,
   1,1,0,1,1,1,0,0,1,1,
   1,1,0,1,1,1,0,1,1,1,
   1,1,0,0,0,0,0,1,1,1,
   1,1,0,1,0,1,1,1,1,1,
   1,1,1,1,0,0,0,1,1,1,
   1,1,1,1,0,1,0,1,1,1,
   1,1,0,0,0,1,0,0,0,1,
   1,1,1,1,1,1,1,1,1,1};

const int start = 11;
const int finish = 88;
int cameFrom[ LIMIT];
int solutionFound = FALSE;


void makeMove( int current)
/* Now located at square \"current,\" where cameFrom[current] 
 * is the square number we came from.  Store that information.
 */
{
 static int moves[4]= {-1, -10, 1, 10};  // No diagonal moves
 int i, nextMove;
 
 cout<<\" \"<<current;   // Display square numbers as we go
 if (current == finish) {
    cout<<\" *** Reached finish! *** \";
    solutionFound = TRUE; // Set flag to prevent further moves
    return; //  Terminate the recursion at this level
 }
 for (i=0; i<4; i++) { // Try all four moves
  if (!solutionFound) {
   nextMove = current + moves[ i];
   if ((nextMove != cameFrom[ current]) && (maze[ nextMove] != 1)) {
    cameFrom[ nextMove] = current;
    makeMove( nextMove);
   }
  }
 }// end for (i=0...
}


void displaySolution()
{
 int position = finish;
 cout<<\"\\nSolution Path: \";
 while (position != 0) {        // while I\'m not back at start
    cout<<\" \"<<position;         // display square 
    position = cameFrom[ position];   // go back one square 
 }
 cout<<endl;
}


void initializeAndDisplayMaze()
{
 int i;
 
 /* Initialize \"cameFrom\" array to be all zeros */
 for (i=0; i<LIMIT; i++)
  cameFrom[ i] = 0;
 
 /* Display maze */
 cout<<\"\\n\\nMaze Traversal program for the maze:\\n\";
 cout<<\"   \";                        /*Display top labels*/
 for (i=0; i< 10; i++) cout<<setw(2)<<i;
 cout<<endl;
 cout<<\"   \";                        /*Display ruler line*/
 for (i=0; i< 10; i++) cout<<\"--\";
 cout<<endl;
 for (i=0; i< LIMIT; i++)  {
  if ( i%10 == 0) cout<<setw(2)<<i<<\"|\";  /*Left hand labels */
   cout<<setw(2)<<maze[i];
  if ( (i+1)%10 == 0) cout<<endl;   /*End of line*/
     }

}


main()
{
 initializeAndDisplayMaze();
 cout<<\"Search Path Traversed:\\n\";
 
 makeMove( start);
 displaySolution();
 
}

","","Maze 3","Dale Reed","Tue Aug 27 22:47:35","0","0","1","102",""); INSERT INTO exdata VALUES("55","7","1","\r\n\r\n\r\n\r\n\r\n















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\r\n

#include <iostream>
using namespace std;

int main()
{
   char a[ 20 ];     // an array \'a\' of 20 chars

   a[  0 ]   = \'f\';      // valid
   a[ 12 ] = \'g\';      // valid
   a[ -4 ]  = \'d\';      // invalid
   a[ 24 ] =\'d\';       // invalid
   a[ 20 ] = \'r\';       // invalid
   a[ 11 ] = 4;       // invalid, converted

   return 0;
}

","

Line 6 shows how to declare an array. The array, named \'a\', will hold 20 characters. The following lines show valid and invalid ways of setting values in the array. The invalid ways will NOT cause compiler error. But they might do damage to the program memory because of wrong assignments. Such errors are harder to debug. So it is recommended that you understand these concepts well.

Line 10 is invalid because -4 is an invalid index. Array indices always go from 0..n
Line 11 is invalid because 24 is out of bounds. the array is only 20 characters long
Line 12 is invalid because the array bounds run from 0..19. The array stores 20 characters but the index starts at zero.
Line 13 is invalid because 4 is not an accepted value for a character, but this will not cause damage. The compiler will cast the value to a character, and then assign it into the array

","Array Creation","Sam","Fri Dec 06 01:43:51","3","1","1","16",""); INSERT INTO exdata VALUES("56","7","1","\r\n\r\n\r\n\r\n\r\n















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\r\n

#include <iostream>
using namespace std;

int main()
{
   int arr[ 5 ] = { 1, 2, 45, -10, 5 };    // setting initial values to an integer array
   for( int i = 0 ; i < 5 ; i++ )
     cout << arr[ i ] << \"  \";

   int ids[ 10 ];
   for( int i = 0 ; i < 10 ; i++ )
       ids[ i ] = 0;
   
   cout<< endl;

   char name[ 40 ] = \"HelloWorld\";   // setting initial values to a char array.
   for( int j = 0 ; j < 40 ; j++ )
     cout << name[ j ] << \"  \";

   return 0;
}

","Line 6 shows how to declare and initialize an array all together in one statement.
Line 10 shows how to initialize an array that has been declared earlier. The array is named as ids.
Line 16 shows how to initialize a character array with a constant string. The characters of the string become the contents of the array. ","Array Initialization","Sam","Fri Dec 06 01:59:35","3","1","1","16",""); INSERT INTO exdata VALUES("57","7","1","\r\n\r\n\r\n\r\n\r\n









































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
\r\n

#include <iostream>
using namespace std;

int main()
{
   char table[ 6 ][ 10 ];
   int i , j;

   for( i = 0 ; i < 6 ; i++ )
   {
      for( j = 0 ; j < 10 ; j++ )
          table[ i ][ j ] = \' \';
   }

   table[ 1 ][ 2 ] = \'x\';
   table[ 1 ][ 6 ] = \'x\';
   table[ 3 ][ 3 ] = \'x\';
   table[ 3 ][ 9 ] = \'x\';
   table[ 5 ][ 0 ] = \'x\';

   cout << \"  \";
   for( j = 0 ; j < 10 ; j++ )
      cout << j << \" \";
   cout << endl;

   for( i = 0 ; i < 6 ; i++ )
   {
      cout << i << \" \";
      for( j = 0 ; j < 10 ; j++ )
          cout << table[ i ][ j ] << \" \";
      cout << endl;
   }

   return 0;
}


","

Suppose you want to make a table of all students in a class who have and have not taken a test. One way to do it would be to use a matrix.

\r\n

         0 1 2 3 4 5 6 7 8 9
   0
   1          x          x
   2
   3             x                 x
   4
   5    x

\r\n

\'x\' marks the id of students who did take the test. eg, student 12 took the test because cell 1,2 has an x on it. So did student 33, and so on.

\r\n

In lines 9 to 13 we initialize the 2-dimensional array with blank values. We use a loop within a loop to reach all the cells in the array.
Value assignment is done using array indices as shown in lines 15 to 19
Finally we can print out the array in whatever form we need , as in lines 21 to 32.

","Multi-Dimensional Arrays","Sam","Fri Dec 06 02:11:07","6","1","1","42",""); INSERT INTO exdata VALUES("58","7","1","\r\n\r\n\r\n\r\n\r\n


























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
\r\n

#include <iostream>
using namespace std;

int main()
{
   char a[ 20 ] = \"Hello\";
   int i , j , k = 0;

   cout << *( a + 1 ) << endl;     // prints \'e\'

   int m[ 5 ][ 10 ];
   for( i = 0 ; i < 5 ; i++ )
   {
      for( j = 0 ; j < 10 ; j++ )
         m[ i ][ j ] = k++;
   }
   
   // to print m[ 1 ][ 3 ] row-wise
   cout << ( m + ( 1 * 10 ) + 3 );

   //or column-wise
   cout << ( m + ( 3 * 5 ) + 1 );

   return 0;
 }

","

An array is a continuous list of memory locations. The array variable name can be used as a starting point to go thru the whole array.

\r\n

Single dimensional arrays: To access the ith position,use a+i
2-dimensional arrays      : To access the i,j th position, use a+nCols*i+j
                                             or a+nRows*j+i (if reading columnwise)

","Array Calculation","Sam","Fri Dec 06 02:54:02","1","0","1","27",""); INSERT INTO exdata VALUES("59","7","1","\r\n\r\n\r\n\r\n\r\n



















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
\r\n

#include <iostream>
using namespace std;

int main()
{
   int    i  = 30;
   int    *pi;
   pi  = &i;

   cout << \"Value of \'i\' is \" << i << endl;
   cout << \"Address of \'i\' is \" << pi << endl;
   cout << \"Value of \'i\' as computed from the pointer is \" << *pi <<endl;

   return 0;
}

","

C++ gives the power to manipulate memory directly. Every variable that is declared has a memory address. Think of the variable in the computer\'s memory as a box; a box that can hold something. An integer variable is a box that can hold an integer. A character variable is a box that can hold a single character. Every box has a memory address (i.e) the location of the box in the memory. C++ provides operators to manipulate those addresses. Manipulations are powerful, but can also lead to disastrous results to the program if mis-handled.

\r\n

Line 7 declares a pointer pi, that can point to an integer (i.e) that can hold the memory address which contains an integer
In line 8, the \'&\' operator retrieves the address of the variable i,  and places it in the pointer pi. We now say that pi points to i. Or, pi now has the address of the variable i. This is called Referencing.
Line 12 shows the \'*\' operator being used to retrieve the value pointed to by a pointer. The term *pi evaluates to retrieving the value stored at the address held by pi. This is called De-referencing.

","Introduction","Sam","Fri Dec 06 03:51:20","5","1","1","20",""); INSERT INTO exdata VALUES("60","7","1","\r\n\r\n\r\n\r\n\r\n
















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
\r\n

#include <iostream>
using namespace std;

int main()
{
   int i = 30;
   int* pi;
   pi = &i;

   cout << \"Value of \'i\' is \" << i << endl;

   // pi = 100; 
   *pi = -34;
   cout << \"Value of \'i\' is now \" << i << endl;
}


","Line 12 assigns the memory address 100 to the pointer pi. Generally not a good idea, because memory address 100 probably contains operating system startup code.
Line 13 assigns the memory address pointer to by pi, to take the value -34. Since pi points to i, the value of i now becomes -34. The value of pi does not change. pi still holds the address of i. ","Usage","Sam","Fri Dec 06 03:54:33","4","1","1","17",""); INSERT INTO exdata VALUES("61","7","1","\r\n\r\n\r\n\r\n\r\n

























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
\r\n

#include <iostream>
using namespace std;

int main()
{
   // character/string pointer
   char name[ 50 ] = \"Happy Birthday\";
   char *pc;
   pc = name;
   cout << *pc << endl;

   // Moving the pointer down the string
   pc = pc + 4;
   cout << *pc << endl;
  
   // Pointer to a character
   char* pEvent;
   pEvent = new char;
   *pEvent = \'g\';
   cout << *pEvent << endl;

   // Pointer to an array
   char* paEvents;
   paEvents = new char[ 40 ];
   strcpy(paEvents , \"HelloWorld\");
   cout << paEvents << endl;

   return 0;
}

","

Assigning a character/string pointer
Line 7 declares and initializes an array of characters, and line 9 copies the address of the array into a char pointer. Note that the name of an array is the sam as the memory address of its first element (i.e) line 9 could also be rewritten as :

                                                                                    pc = &name[ 0 ];

Moving the pointer down the string
Line 14 prints the 5th character of the name string. So it actually prints \"y\". The memor address stored in pc was incremented by 4. This means that if the value in pc was 100, it is now 104. Since 100 would be the address of the first character in the array, 104 will be the address of the 5th character , ie \'y\'.

Pointer to an array /  pointer to a character
Lines 16 to 20 talk about using a pointer to allocate a new character and use it. Lines 22 to 26 talk about using a similar pointer to allocate a new string and use it. Note that a pointer to an array and a pointer to a datatype ( eg . char) is the same thing. All pointers hold memory addresses... plain integers.
 

","Arrays As Pointers","Sam","Fri Dec 06 04:37:00","2","1","1","26",""); INSERT INTO exdata VALUES("62","7","1","\r\n\r\n\r\n\r\n\r\n






















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
\r\n

#include <iostream>
using namespace std;

typedef int ( *PFUNC )( int a , int b );

int func(int a , int b)
{
    return (a * 10 + b);
}

int main()
{
   PFUNC funcptr;
   int i = 40;
   int j = 34;
   funcptr = &func;

   int result = ( *funcptr )( i , j );
   cout << result << endl;

   return 0;
}

","

Function pointers are special pointers. Instead of pointing to the memory address of a variable, they point to the memory address of a function inside the binary compiled code. De-referencing a function pointer does the equivalent of calling the function with parameters. Function pointers are used to make-generic a process such as a parser. Function pointers are also used in building interfaces for reusable objects.

\r\n

Lines 4 to 7 define a  function. A function is a separate block of code. More about this in the section on functions. Line 9 defines a custom type FUNCPTR, which is a pointer to a function that takes 2 integers and returns an integer.

In the main function (Note that the main() is also a function. It is the first function called by the system when the program starts to execute ), line 16 assigns the pointer with the address of our function. And in line 18, the function is executed, just like de-referencing the value of a pointer.

","Function Pointers","Sam","Fri Dec 06 04:54:36","6","1","2","23",""); INSERT INTO exdata VALUES("63","7","1","\r\n\r\n\r\n\r\n\r\n

















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
\r\n

#include <iostream>
using namespace std;

int main()
{
   char name1[ 50 ] = \"Shark\";
   char name2[ 50 ] = \"Whale\";
   char name3[ 50 ] = \"Bull\";
   char name4[ 50 ] = \"Elephant\";

   char**  names;     // declare an array of pointers
   names = new char* [ 5 ];
   names[ 0 ] = name1;
   names[ 1 ] = name2;
   names[ 2 ] = name3;
   names[ 3 ] = name4;

   for(int i = 0 ; i < 4 ; i++)
          cout << names[ i ] << endl;

   return 0;
}

","Line 9 declares an array name  which is an array of pointers to chars. ie, each cell in the array holds a pointer to a character. Pointers are assigned values just as for normal pointers. Note that the array names are pointers themselves. ","Array of Pointers","Sam","Fri Dec 06 05:29:08","1","1","1","18",""); INSERT INTO exdata VALUES("64","7","1","\r\n\r\n\r\n\r\n\r\n
























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
\r\n

#include <iostream>
using namespace std;

int main()
{
   char name[ 50 ] = \"Happy Birthday\";
   char *pc=name;
   cout << *pc << endl; // prints \'H\'

   pc = pc + 4;    // advance the pointer by 4 characters in the array
   cout << *pc << endl;   // prints \'y\'

   int a[ 5 ]= { 10, 20, 30, 40, 50 };
   int *pi = a;
   cout << \"Address of pi is \" << pi <<endl;
   cout << \"Value pointer to by pi is \"<< *pi << endl;   // prints a[ 0 ]
   cout << endl;

   cout << \"Advancing pi by 1...\" << endl;
   pi = pi + 1;         // advances the pointer by one integer ( 4 bytes )

   cout << \"Address of pi is \" << pi <<endl;
   cout << \"Value pointer to by pi is \"<< *pi << endl;   // prints a[ 1 ]

   return 0;
}

","

This example demonstrates how to index stuff using pointers. Line 6 declares a character array. We can access a particular element in the array by using the array indexing mechanism. Or, we can use a pointer, as shown in lines 7 to 12.

Line 13 declares an integer array and initializes it with values. Line 14 declares a pointer to the array that will be used to access particular elements in the array. Line 20 advances the pointer by one position in the array. Note that advancing an integer array by 1, actually advances the memory address by 4, which is the size of an integer.

","Pointer - Based Indexing","Sam","Sat Dec 07 00:17:55","1","1","1","25",""); INSERT INTO exdata VALUES("65","7","1","\r\n\r\n\r\n\r\n\r\n
















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
\r\n

#include <iostream>
using namespace std;

int main()
{
   char name[ 50 ] = \"Happy Birthday\";
   int arr[ 5 ] = { 1, 2, 45, -10, 5 };

   void *pv;
   pv = name;
   cout << *( ( char* ) pv ) << endl;       // prints H

   pv = arr;
   cout << *( ( int* ) pv + 2 ) << endl;    // prints 45

   return 0;
}

","A void pointer is a typeless pointer, which can hold a pointer of any datatype. In the example, a void pointer pv is assigned the address of a character array. Later on in the code, the same variable is assigned the address of an integer array. Both are perfectly valid statements.

Note that, when using the void pointer, to print out data, or to retrieve the value, you need to specify the datatype of the value to be printed/retrieved. Thats why lines 11 and 14 specify a data type for the void pointer. Without the datatype being specified, the compiler has no clue how to pint out or to retrieve the stuff pointed to by the void pointer.","Void Pointer","Sam","Sat Dec 07 00:24:58","3","1","1","17",""); INSERT INTO exdata VALUES("66","7","1","\r\n\r\n\r\n\r\n\r\n











1
2
3
4
5
6
7
8
9
10
11
\r\n

#include <iostream>
#include <string>
using namespace std;

int main()
{
   char* paEvents;                             // declare a pointer to an array.
   paEvents = new char[40];               // allocate memory for a new array of chars, of size 40.
   strcpy( paEvents , \"HelloWorld\") ;   // assign value to it
   cout << paEvents << endl ;            // print the contents of the array

   return 0;
}




","","Memory allocation","Sam","Sat Dec 07 00:27:18","3","1","1","12",""); INSERT INTO exdata VALUES("67","7","1","\r\n\r\n\r\n\r\n\r\n
















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
\r\n

#include <iostream>
using namespace std;

int main()
{
   char* str;
   str = new char[ 100 ];

   strcpy( str , \"This is a sentence.\" );
   cout << str << endl;

   int len = strlen( str );
   for( int i = 0 ; i < len ; i++ )
     cout << str[ i ];

   return 0;
}

","

A string in C++ is an array of continuous characters. A string is delimited by a \'\\0\' character. This character tells the compiler that the string ends there. A string is zero-ended, which means the first character is at position 0, the second is at position 1, and so on.

The strcpy function copies a source string into a destination string, along with the \'\\0\' character
The strlen  function  returns the length of the string, excluding the \'\\0\' character

\r\n

You can access a particular character of a string by using the [ ] operator. For example, str[4] will return the 5th character in the string str.

","String Usage","Sam","Wed Mar 05 03:37:31","12","1","1","17",""); INSERT INTO exdata VALUES("68","7","1","\r\n\r\n\r\n\r\n\r\n





















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
\r\n

#include <iostream>
#include <string>
using namespace std;

int main()
{
   char* str;
   str = new char[ 100 ];
   strcpy( str , \"This is a sentence.\" );
   cout << str << endl;

   char strName[ 50 ] = \"HelloWorld!\";
   strcat( strName , \"Kirsten!\" );
   cout << str << endl;

   cout << \"Type a string:\";
   cin >> str;
   if( strcmp( str , \"charge\" ) == 0 )
      cout << \"You typed \'charge\'\" << endl;

   return 0;
}

","

In this example we introduce a new header file - <string>.  This file contains declarations for string manipulation functions.

The strcpy function  copies a source string into a destination string, along with the \'\\0\' character ( line 9 )
The strlen  function  returns the length of the string, excluding the \'\\0\' character ( not shown )
The strcat  function  adds a string to another string, and also adds the \'\\0\' character to the end ( line 13 )
The strcmp function compares two strings and returns 0, -ve, or +ve numbers. 0 indicates that the two strings are equal. A +ve value indicates string1 is \'greater\' than string2. ( line 18 )


","String Functions","Sam","Thu Dec 05 22:12:05","7","1","1","22",""); INSERT INTO exdata VALUES("71","7","1","\r\n\r\n\r\n\r\n\r\n

















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
\r\n

#include <iostream>
using namespace std;

int main()
{
    int a = 10;
    int b = 30;
    int total;
    total = a + b;
    cout << a << \" + \" << b << \" = \" << total <<endl;

   return 0;
}
 

","

Operators in C++:

The following operators are available.

Arithmetic                       +  -  /   *   %   +=   -=   /=   *=   %=   ++  --

Logical                           &&    ||   !

Relational                       <   >   <=   <=   ==    !=

Bitwise                          &   |     ~    ^    >>   <<   &=   !=   ^=

\r\n


The example above shows the use of the addition arithmetic operator( + ). An Operation is a statement that uses an operator to perform a task. The output value of an operation is determined by the type of the variables in the operation. In the example above, both variables a and b are of type integer. So the output will also be an integer.

","Introduction","Sam","Mon Dec 16 15:02:24","7","1","1","18",""); INSERT INTO exdata VALUES("72","7","1","\r\n\r\n\r\n\r\n\r\n


























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
\r\n

#include <iostream>
using namespace std;

int main()
{
   int i = 40;
   int j = -20;

   int sum         = i + j;
   int diff           = i  - j;

   int product    = i * j;
   int divident    = i / j;
   int remainder = i % j;

   cout << i << \" + \" << j << \" = \" << sum << endl;
   cout << i << \" - \" << j << \" = \" << diff << endl;
   cout << i << \" * \" << j << \" = \" << product << endl;
   cout << i << \" / \" << j << \" = \" << divident << endl;
   cout << i << \" % \" << j << \" = \" << remainder << endl;

   return 0;
}

","

The statements in the code above show the use of different common arithmetic operators in C++. An arithmetic statement is generallyof the form

\r\n

                                          value  = operand1  operator  operand2


","Arithmetic","Sam","Mon Dec 16 15:21:46","5","1","1","27",""); INSERT INTO exdata VALUES("73","7","1","\r\n\r\n\r\n












<