From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Bachelor/Prog1/examples/ch05/Ex05_21.cpp | 49 +++++++++++++ Bachelor/Prog1/examples/ch05/Ex05_22.cpp | 48 +++++++++++++ Bachelor/Prog1/examples/ch05/Ex05_30.cpp | 49 +++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_04.cpp | 43 +++++++++++ Bachelor/Prog1/examples/ch05/Fig05_06.cpp | 45 ++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_07.cpp | 46 ++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_10.cpp | 53 ++++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_11.cpp | 45 ++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_12.cpp | 38 ++++++++++ Bachelor/Prog1/examples/ch05/Fig05_13.cpp | 34 +++++++++ Bachelor/Prog1/examples/ch05/Fig05_14.cpp | 39 ++++++++++ Bachelor/Prog1/examples/ch05/Fig05_15.cpp | 77 ++++++++++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_16.cpp | 45 ++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_17.cpp | 55 ++++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_20.cpp | 60 ++++++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_21.cpp | 58 +++++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_24.cpp | 103 ++++++++++++++++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_25.cpp | 115 ++++++++++++++++++++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_26.cpp | 76 ++++++++++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_28.cpp | 44 ++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_29.cpp | 50 +++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_30.cpp | 50 +++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_31.cpp | 47 ++++++++++++ Bachelor/Prog1/examples/ch05/Fig05_32.cpp | 40 +++++++++++ 24 files changed, 1309 insertions(+) create mode 100644 Bachelor/Prog1/examples/ch05/Ex05_21.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Ex05_22.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Ex05_30.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_04.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_06.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_07.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_10.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_11.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_12.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_13.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_14.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_15.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_16.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_17.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_20.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_21.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_24.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_25.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_26.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_28.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_29.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_30.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_31.cpp create mode 100644 Bachelor/Prog1/examples/ch05/Fig05_32.cpp (limited to 'Bachelor/Prog1/examples/ch05') diff --git a/Bachelor/Prog1/examples/ch05/Ex05_21.cpp b/Bachelor/Prog1/examples/ch05/Ex05_21.cpp new file mode 100644 index 0000000..1fd9111 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Ex05_21.cpp @@ -0,0 +1,49 @@ +// Ex. 5.21: ex05_21.cpp +// What does this program do? +#include + +using std::cout; +using std::cin; +using std::endl; + +void mystery1( char *, const char * ); // prototype + +int main() +{ + char string1[ 80 ]; + char string2[ 80 ]; + + cout << "Enter two strings: "; + cin >> string1 >> string2; + mystery1( string1, string2 ); + cout << string1 << endl; + + return 0; // indicates successful termination + +} // end main + +// What does this function do? +void mystery1( char *s1, const char *s2 ) +{ + while ( *s1 != '\0' ) + ++s1; + + for ( ; *s1 = *s2; s1++, s2++ ) + ; // empty statement + +} // end function mystery1 + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Ex05_22.cpp b/Bachelor/Prog1/examples/ch05/Ex05_22.cpp new file mode 100644 index 0000000..9299669 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Ex05_22.cpp @@ -0,0 +1,48 @@ +// Ex. 5.22: ex05_22.cpp +// What does this program do? +#include + +using std::cout; +using std::cin; +using std::endl; + +int mystery2( const char * ); // prototype + +int main() +{ + char string1[ 80 ]; + + cout << "Enter a string: "; + cin >> string1; + cout << mystery2( string1 ) << endl; + + return 0; // indicates successful termination + +} // end main + +// What does this function do? +int mystery2( const char *s ) +{ + int x; + + for ( x = 0; *s != '\0'; s++ ) + ++x; + + return x; + +} // end function mystery2 + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Ex05_30.cpp b/Bachelor/Prog1/examples/ch05/Ex05_30.cpp new file mode 100644 index 0000000..88ede48 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Ex05_30.cpp @@ -0,0 +1,49 @@ +// Ex. 5.30: ex05_30.cpp +// What does this program do? +#include + +using std::cout; +using std::cin; +using std::endl; + +bool mystery3( const char *, const char * ); // prototype + +int main() +{ + char string1[ 80 ], string2[ 80 ]; + + cout << "Enter two strings: "; + cin >> string1 >> string2; + cout << "The result is " + << mystery3( string1, string2 ) << endl; + + return 0; // indicates successful termination + +} // end main + +// What does this function do? +bool mystery3( const char *s1, const char *s2 ) +{ + for ( ; *s1 != '\0' && *s2 != '\0'; s1++, s2++ ) + + if ( *s1 != *s2 ) + return false; + + return true; + +} // end function mystery3 + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_04.cpp b/Bachelor/Prog1/examples/ch05/Fig05_04.cpp new file mode 100644 index 0000000..bcf52ff --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_04.cpp @@ -0,0 +1,43 @@ +// Fig. 5.4: fig05_04.cpp +// Using the & and * operators. +#include + +using std::cout; +using std::endl; + +int main() +{ + int a; // a is an integer + int *aPtr; // aPtr is a pointer to an integer + + a = 7; + aPtr = &a; // aPtr assigned address of a + + cout << "The address of a is " << &a + << "\nThe value of aPtr is " << aPtr; + + cout << "\n\nThe value of a is " << a + << "\nThe value of *aPtr is " << *aPtr; + + cout << "\n\nShowing that * and & are inverses of " + << "each other.\n&*aPtr = " << &*aPtr + << "\n*&aPtr = " << *&aPtr << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_06.cpp b/Bachelor/Prog1/examples/ch05/Fig05_06.cpp new file mode 100644 index 0000000..5aad3b7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_06.cpp @@ -0,0 +1,45 @@ +// Fig. 5.6: fig05_06.cpp +// Cube a variable using pass-by-value. +#include + +using std::cout; +using std::endl; + +int cubeByValue( int ); // prototype + +int main() +{ + int number = 5; + + cout << "The original value of number is " << number; + + // pass number by value to cubeByValue + number = cubeByValue( number ); + + cout << "\nThe new value of number is " << number << endl; + + return 0; // indicates successful termination + +} // end main + +// calculate and return cube of integer argument +int cubeByValue( int n ) +{ + return n * n * n; // cube local variable n and return result + +} // end function cubeByValue + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_07.cpp b/Bachelor/Prog1/examples/ch05/Fig05_07.cpp new file mode 100644 index 0000000..b4da523 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_07.cpp @@ -0,0 +1,46 @@ +// Fig. 5.7: fig05_07.cpp +// Cube a variable using pass-by-reference +// with a pointer argument. +#include + +using std::cout; +using std::endl; + +void cubeByReference( int * ); // prototype + +int main() +{ + int number = 5; + + cout << "The original value of number is " << number; + + // pass address of number to cubeByReference + cubeByReference( &number ); + + cout << "\nThe new value of number is " << number << endl; + + return 0; // indicates successful termination + +} // end main + +// calculate cube of *nPtr; modifies variable number in main +void cubeByReference( int *nPtr ) +{ + *nPtr = *nPtr * *nPtr * *nPtr; // cube *nPtr + +} // end function cubeByReference + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_10.cpp b/Bachelor/Prog1/examples/ch05/Fig05_10.cpp new file mode 100644 index 0000000..cfd0fce --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_10.cpp @@ -0,0 +1,53 @@ +// Fig. 5.10: fig05_10.cpp +// Converting lowercase letters to uppercase letters +// using a non-constant pointer to non-constant data. +#include + +using std::cout; +using std::endl; + +#include // prototypes for islower and toupper + +void convertToUppercase( char * ); + +int main() +{ + char phrase[] = "characters and $32.98"; + + cout << "The phrase before conversion is: " << phrase; + convertToUppercase( phrase ); + cout << "\nThe phrase after conversion is: " + << phrase << endl; + + return 0; // indicates successful termination + +} // end main + +// convert string to uppercase letters +void convertToUppercase( char *sPtr ) +{ + while ( *sPtr != '\0' ) { // current character is not '\0' + + if ( islower( *sPtr ) ) // if character is lowercase, + *sPtr = toupper( *sPtr ); // convert to uppercase + + ++sPtr; // move sPtr to next character in string + + } // end while + +} // end function convertToUppercase + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_11.cpp b/Bachelor/Prog1/examples/ch05/Fig05_11.cpp new file mode 100644 index 0000000..6d92cef --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_11.cpp @@ -0,0 +1,45 @@ +// Fig. 5.11: fig05_11.cpp +// Printing a string one character at a time using +// a non-constant pointer to constant data. +#include + +using std::cout; +using std::endl; + +void printCharacters( const char * ); + +int main() +{ + char phrase[] = "print characters of a string"; + + cout << "The string is:\n"; + printCharacters( phrase ); + cout << endl; + + return 0; // indicates successful termination + +} // end main + +// sPtr cannot modify the character to which it points, +// i.e., sPtr is a "read-only" pointer +void printCharacters( const char *sPtr ) +{ + for ( ; *sPtr != '\0'; sPtr++ ) // no initialization + cout << *sPtr; + +} // end function printCharacters + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_12.cpp b/Bachelor/Prog1/examples/ch05/Fig05_12.cpp new file mode 100644 index 0000000..c9f089a --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_12.cpp @@ -0,0 +1,38 @@ +// Fig. 5.12: fig05_12.cpp +// Attempting to modify data through a +// non-constant pointer to constant data. + +void f( const int * ); // prototype + +int main() +{ + int y; + + f( &y ); // f attempts illegal modification + + return 0; // indicates successful termination + +} // end main + +// xPtr cannot modify the value of the variable +// to which it points +void f( const int *xPtr ) +{ + *xPtr = 100; // error: cannot modify a const object + +} // end function f + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_13.cpp b/Bachelor/Prog1/examples/ch05/Fig05_13.cpp new file mode 100644 index 0000000..ac697ba --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_13.cpp @@ -0,0 +1,34 @@ +// Fig. 5.13: fig05_13.cpp +// Attempting to modify a constant pointer to +// non-constant data. + +int main() +{ + int x, y; + + // ptr is a constant pointer to an integer that can + // be modified through ptr, but ptr always points to the + // same memory location. + int * const ptr = &x; + + *ptr = 7; // allowed: *ptr is not const + ptr = &y; // error: ptr is const; cannot assign new address + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_14.cpp b/Bachelor/Prog1/examples/ch05/Fig05_14.cpp new file mode 100644 index 0000000..8193ad1 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_14.cpp @@ -0,0 +1,39 @@ +// Fig. 5.14: fig05_14.cpp +// Attempting to modify a constant pointer to constant data. +#include + +using std::cout; +using std::endl; + +int main() +{ + int x = 5, y; + + // ptr is a constant pointer to a constant integer. + // ptr always points to the same location; the integer + // at that location cannot be modified. + const int *const ptr = &x; + + cout << *ptr << endl; + + *ptr = 7; // error: *ptr is const; cannot assign new value + ptr = &y; // error: ptr is const; cannot assign new address + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_15.cpp b/Bachelor/Prog1/examples/ch05/Fig05_15.cpp new file mode 100644 index 0000000..bcdd13a --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_15.cpp @@ -0,0 +1,77 @@ +// Fig. 5.15: fig05_15.cpp +// This program puts values into an array, sorts the values into +// ascending order, and prints the resulting array. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +void bubbleSort( int *, const int ); // prototype +void swap( int * const, int * const ); // prototype + +int main() +{ + const int arraySize = 10; + int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 }; + + cout << "Data items in original order\n"; + + for ( int i = 0; i < arraySize; i++ ) + cout << setw( 4 ) << a[ i ]; + + bubbleSort( a, arraySize ); // sort the array + + cout << "\nData items in ascending order\n"; + + for ( int j = 0; j < arraySize; j++ ) + cout << setw( 4 ) << a[ j ]; + + cout << endl; + + return 0; // indicates successful termination + +} // end main + +// sort an array of integers using bubble sort algorithm +void bubbleSort( int *array, const int size ) +{ + // loop to control passes + for ( int pass = 0; pass < size - 1; pass++ ) + + // loop to control comparisons during each pass + for ( int k = 0; k < size - 1; k++ ) + + // swap adjacent elements if they are out of order + if ( array[ k ] > array[ k + 1 ] ) + swap( &array[ k ], &array[ k + 1 ] ); + +} // end function bubbleSort + +// swap values at memory locations to which +// element1Ptr and element2Ptr point +void swap( int * const element1Ptr, int * const element2Ptr ) +{ + int hold = *element1Ptr; + *element1Ptr = *element2Ptr; + *element2Ptr = hold; + +} // end function swap + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_16.cpp b/Bachelor/Prog1/examples/ch05/Fig05_16.cpp new file mode 100644 index 0000000..921e8dd --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_16.cpp @@ -0,0 +1,45 @@ +// Fig. 5.16: fig05_16.cpp +// Sizeof operator when used on an array name +// returns the number of bytes in the array. +#include + +using std::cout; +using std::endl; + +size_t getSize( double * ); // prototype + +int main() +{ + double array[ 20 ]; + + cout << "The number of bytes in the array is " + << sizeof( array ); + + cout << "\nThe number of bytes returned by getSize is " + << getSize( array ) << endl; + + return 0; // indicates successful termination + +} // end main + +// return size of ptr +size_t getSize( double *ptr ) +{ + return sizeof( ptr ); + +} // end function getSize + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_17.cpp b/Bachelor/Prog1/examples/ch05/Fig05_17.cpp new file mode 100644 index 0000000..7091880 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_17.cpp @@ -0,0 +1,55 @@ +// Fig. 5.17: fig05_17.cpp +// Demonstrating the sizeof operator. +#include + +using std::cout; +using std::endl; + +int main() +{ + char c; + short s; + int i; + long l; + float f; + double d; + long double ld; + int array[ 20 ]; + int *ptr = array; + + cout << "sizeof c = " << sizeof c + << "\tsizeof(char) = " << sizeof( char ) + << "\nsizeof s = " << sizeof s + << "\tsizeof(short) = " << sizeof( short ) + << "\nsizeof i = " << sizeof i + << "\tsizeof(int) = " << sizeof( int ) + << "\nsizeof l = " << sizeof l + << "\tsizeof(long) = " << sizeof( long ) + << "\nsizeof f = " << sizeof f + << "\tsizeof(float) = " << sizeof( float ) + << "\nsizeof d = " << sizeof d + << "\tsizeof(double) = " << sizeof( double ) + << "\nsizeof ld = " << sizeof ld + << "\tsizeof(long double) = " << sizeof( long double ) + << "\nsizeof array = " << sizeof array + << "\nsizeof ptr = " << sizeof ptr + << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_20.cpp b/Bachelor/Prog1/examples/ch05/Fig05_20.cpp new file mode 100644 index 0000000..63bc2f7 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_20.cpp @@ -0,0 +1,60 @@ +// Fig. 5.20: fig05_20.cpp +// Using subscripting and pointer notations with arrays. + +#include + +using std::cout; +using std::endl; + +int main() +{ + int b[] = { 10, 20, 30, 40 }; + int *bPtr = b; // set bPtr to point to array b + + // output array b using array subscript notation + cout << "Array b printed with:\n\n" + << "Array subscript notation\n"; + + for ( int i = 0; i < 4; i++ ) + cout << "b[" << i << "] = " << b[ i ] << '\n'; + + // output array b using the array name and + // pointer/offset notation + cout << "\nPointer/offset notation where " + << "the pointer is the array name\n"; + + for ( int offset1 = 0; offset1 < 4; offset1++ ) + cout << "*(b + " << offset1 << ") = " + << *( b + offset1 ) << '\n'; + + // output array b using bPtr and array subscript notation + cout << "\nPointer subscript notation\n"; + + for ( int j = 0; j < 4; j++ ) + cout << "bPtr[" << j << "] = " << bPtr[ j ] << '\n'; + + cout << "\nPointer/offset notation\n"; + + // output array b using bPtr and pointer/offset notation + for ( int offset2 = 0; offset2 < 4; offset2++ ) + cout << "*(bPtr + " << offset2 << ") = " + << *( bPtr + offset2 ) << '\n'; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_21.cpp b/Bachelor/Prog1/examples/ch05/Fig05_21.cpp new file mode 100644 index 0000000..e045aba --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_21.cpp @@ -0,0 +1,58 @@ +// Fig. 5.21: fig05_21.cpp +// Copying a string using array notation +// and pointer notation. +#include + +using std::cout; +using std::endl; + +void copy1( char *, const char * ); // prototype +void copy2( char *, const char * ); // prototype + +int main() +{ + char string1[ 10 ]; + char *string2 = "Hello"; + char string3[ 10 ]; + char string4[] = "Good Bye"; + + copy1( string1, string2 ); + cout << "string1 = " << string1 << endl; + + copy2( string3, string4 ); + cout << "string3 = " << string3 << endl; + + return 0; // indicates successful termination + +} // end main + +// copy s2 to s1 using array notation +void copy1( char *s1, const char *s2 ) +{ + for ( int i = 0; ( s1[ i ] = s2[ i ] ) != '\0'; i++ ) + ; // do nothing in body + +} // end function copy1 + +// copy s2 to s1 using pointer notation +void copy2( char *s1, const char *s2 ) +{ + for ( ; ( *s1 = *s2 ) != '\0'; s1++, s2++ ) + ; // do nothing in body + +} // end function copy2 + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_24.cpp b/Bachelor/Prog1/examples/ch05/Fig05_24.cpp new file mode 100644 index 0000000..746fd13 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_24.cpp @@ -0,0 +1,103 @@ +// Fig. 5.24: fig05_24.cpp +// Card shuffling dealing program. +#include + +using std::cout; +using std::left; +using std::right; + +#include + +using std::setw; + +#include // prototypes for rand and srand +#include // prototype for time + +// prototypes +void shuffle( int [][ 13 ] ); +void deal( const int [][ 13 ], const char *[], const char *[] ); + +int main() +{ + // initialize suit array + const char *suit[ 4 ] = + { "Hearts", "Diamonds", "Clubs", "Spades" }; + + // initialize face array + const char *face[ 13 ] = + { "Ace", "Deuce", "Three", "Four", + "Five", "Six", "Seven", "Eight", + "Nine", "Ten", "Jack", "Queen", "King" }; + + // initialize deck array + int deck[ 4 ][ 13 ] = { 0 }; + + srand( time( 0 ) ); // seed random number generator + + shuffle( deck ); + deal( deck, face, suit ); + + return 0; // indicates successful termination + +} // end main + +// shuffle cards in deck +void shuffle( int wDeck[][ 13 ] ) +{ + int row; + int column; + + // for each of the 52 cards, choose slot of deck randomly + for ( int card = 1; card <= 52; card++ ) { + + // choose new random location until unoccupied slot found + do { + row = rand() % 4; + column = rand() % 13; + } while( wDeck[ row ][ column ] != 0 ); // end do/while + + // place card number in chosen slot of deck + wDeck[ row ][ column ] = card; + + } // end for + +} // end function shuffle + +// deal cards in deck +void deal( const int wDeck[][ 13 ], const char *wFace[], + const char *wSuit[] ) +{ + // for each of the 52 cards + for ( int card = 1; card <= 52; card++ ) + + // loop through rows of wDeck + for ( int row = 0; row <= 3; row++ ) + + // loop through columns of wDeck for current row + for ( int column = 0; column <= 12; column++ ) + + // if slot contains current card, display card + if ( wDeck[ row ][ column ] == card ) { + cout << setw( 5 ) << right << wFace[ column ] + << " of " << setw( 8 ) << left + << wSuit[ row ] + << ( card % 2 == 0 ? '\n' : '\t' ); + + } // end if + +} // end function deal + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_25.cpp b/Bachelor/Prog1/examples/ch05/Fig05_25.cpp new file mode 100644 index 0000000..8073108 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_25.cpp @@ -0,0 +1,115 @@ +// Fig. 5.25: fig05_25.cpp +// Multipurpose sorting program using function pointers. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include + +using std::setw; + +// prototypes +void bubble( int [], const int, bool (*)( int, int ) ); +void swap( int * const, int * const ); +bool ascending( int, int ); +bool descending( int, int ); + +int main() +{ + const int arraySize = 10; + int order; + int counter; + int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 }; + + cout << "Enter 1 to sort in ascending order,\n" + << "Enter 2 to sort in descending order: "; + cin >> order; + cout << "\nData items in original order\n"; + + // output original array + for ( counter = 0; counter < arraySize; counter++ ) + cout << setw( 4 ) << a[ counter ]; + + // sort array in ascending order; pass function ascending + // as an argument to specify ascending sorting order + if ( order == 1 ) { + bubble( a, arraySize, ascending ); + cout << "\nData items in ascending order\n"; + } + + // sort array in descending order; pass function descending + // as an argument to specify descending sorting order + else { + bubble( a, arraySize, descending ); + cout << "\nData items in descending order\n"; + } + + // output sorted array + for ( counter = 0; counter < arraySize; counter++ ) + cout << setw( 4 ) << a[ counter ]; + + cout << endl; + + return 0; // indicates successful termination + +} // end main + +// multipurpose bubble sort; parameter compare is a pointer to +// the comparison function that determines sorting order +void bubble( int work[], const int size, + bool (*compare)( int, int ) ) +{ + // loop to control passes + for ( int pass = 1; pass < size; pass++ ) + + // loop to control number of comparisons per pass + for ( int count = 0; count < size - 1; count++ ) + + // if adjacent elements are out of order, swap them + if ( (*compare)( work[ count ], work[ count + 1 ] ) ) + swap( &work[ count ], &work[ count + 1 ] ); + +} // end function bubble + +// swap values at memory locations to which +// element1Ptr and element2Ptr point +void swap( int * const element1Ptr, int * const element2Ptr ) +{ + int hold = *element1Ptr; + *element1Ptr = *element2Ptr; + *element2Ptr = hold; + +} // end function swap + +// determine whether elements are out of order +// for an ascending order sort +bool ascending( int a, int b ) +{ + return b < a; // swap if b is less than a + +} // end function ascending + +// determine whether elements are out of order +// for a descending order sort +bool descending( int a, int b ) +{ + return b > a; // swap if b is greater than a + +} // end function descending + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_26.cpp b/Bachelor/Prog1/examples/ch05/Fig05_26.cpp new file mode 100644 index 0000000..916dbb9 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_26.cpp @@ -0,0 +1,76 @@ +// Fig. 5.26: fig05_26.cpp +// Demonstrating an array of pointers to functions. +#include + +using std::cout; +using std::cin; +using std::endl; + +// function prototypes +void function1( int ); +void function2( int ); +void function3( int ); + +int main() +{ + // initialize array of 3 pointers to functions that each + // take an int argument and return void + void (*f[ 3 ])( int ) = { function1, function2, function3 }; + + int choice; + + cout << "Enter a number between 0 and 2, 3 to end: "; + cin >> choice; + + // process user's choice + while ( choice >= 0 && choice < 3 ) { + + // invoke function at location choice in array f + // and pass choice as an argument + (*f[ choice ])( choice ); + + cout << "Enter a number between 0 and 2, 3 to end: "; + cin >> choice; + } + + cout << "Program execution completed." << endl; + + return 0; // indicates successful termination + +} // end main + +void function1( int a ) +{ + cout << "You entered " << a + << " so function1 was called\n\n"; + +} // end function1 + +void function2( int b ) +{ + cout << "You entered " << b + << " so function2 was called\n\n"; + +} // end function2 + +void function3( int c ) +{ + cout << "You entered " << c + << " so function3 was called\n\n"; + +} // end function3 + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_28.cpp b/Bachelor/Prog1/examples/ch05/Fig05_28.cpp new file mode 100644 index 0000000..d973c37 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_28.cpp @@ -0,0 +1,44 @@ +// Fig. 5.28: fig05_28.cpp +// Using strcpy and strncpy. +#include + +using std::cout; +using std::endl; + +#include // prototypes for strcpy and strncpy + +int main() +{ + char x[] = "Happy Birthday to You"; + char y[ 25 ]; + char z[ 15 ]; + + strcpy( y, x ); // copy contents of x into y + + cout << "The string in array x is: " << x + << "\nThe string in array y is: " << y << '\n'; + + // copy first 14 characters of x into z + strncpy( z, x, 14 ); // does not copy null character + z[ 14 ] = '\0'; // append '\0' to z's contents + + cout << "The string in array z is: " << z << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_29.cpp b/Bachelor/Prog1/examples/ch05/Fig05_29.cpp new file mode 100644 index 0000000..daa58f6 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_29.cpp @@ -0,0 +1,50 @@ +// Fig. 5.29: fig05_29.cpp +// Using strcat and strncat. +#include + +using std::cout; +using std::endl; + +#include // prototypes for strcat and strncat + +int main() +{ + char s1[ 20 ] = "Happy "; + char s2[] = "New Year "; + char s3[ 40 ] = ""; + + cout << "s1 = " << s1 << "\ns2 = " << s2; + + strcat( s1, s2 ); // concatenate s2 to s1 + + cout << "\n\nAfter strcat(s1, s2):\ns1 = " << s1 + << "\ns2 = " << s2; + + // concatenate first 6 characters of s1 to s3 + strncat( s3, s1, 6 ); // places '\0' after last character + + cout << "\n\nAfter strncat(s3, s1, 6):\ns1 = " << s1 + << "\ns3 = " << s3; + + strcat( s3, s1 ); // concatenate s1 to s3 + cout << "\n\nAfter strcat(s3, s1):\ns1 = " << s1 + << "\ns3 = " << s3 << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_30.cpp b/Bachelor/Prog1/examples/ch05/Fig05_30.cpp new file mode 100644 index 0000000..1f55555 --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_30.cpp @@ -0,0 +1,50 @@ +// Fig. 5.30: fig05_30.cpp +// Using strcmp and strncmp. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +#include // prototypes for strcmp and strncmp + +int main() +{ + char *s1 = "Happy New Year"; + char *s2 = "Happy New Year"; + char *s3 = "Happy Holidays"; + + cout << "s1 = " << s1 << "\ns2 = " << s2 + << "\ns3 = " << s3 << "\n\nstrcmp(s1, s2) = " + << setw( 2 ) << strcmp( s1, s2 ) + << "\nstrcmp(s1, s3) = " << setw( 2 ) + << strcmp( s1, s3 ) << "\nstrcmp(s3, s1) = " + << setw( 2 ) << strcmp( s3, s1 ); + + cout << "\n\nstrncmp(s1, s3, 6) = " << setw( 2 ) + << strncmp( s1, s3, 6 ) << "\nstrncmp(s1, s3, 7) = " + << setw( 2 ) << strncmp( s1, s3, 7 ) + << "\nstrncmp(s3, s1, 7) = " + << setw( 2 ) << strncmp( s3, s1, 7 ) << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_31.cpp b/Bachelor/Prog1/examples/ch05/Fig05_31.cpp new file mode 100644 index 0000000..280bddc --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_31.cpp @@ -0,0 +1,47 @@ +// Fig. 5.31: fig05_31.cpp +// Using strtok. +#include + +using std::cout; +using std::endl; + +#include // prototype for strtok + +int main() +{ + char sentence[] = "This is a sentence with 7 tokens"; + char *tokenPtr; + + cout << "The string to be tokenized is:\n" << sentence + << "\n\nThe tokens are:\n\n"; + + // begin tokenization of sentence + tokenPtr = strtok( sentence, " " ); + + // continue tokenizing sentence until tokenPtr becomes NULL + while ( tokenPtr != NULL ) { + cout << tokenPtr << '\n'; + tokenPtr = strtok( NULL, " " ); // get next token + + } // end while + + cout << "\nAfter strtok, sentence = " << sentence << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ diff --git a/Bachelor/Prog1/examples/ch05/Fig05_32.cpp b/Bachelor/Prog1/examples/ch05/Fig05_32.cpp new file mode 100644 index 0000000..ae612dd --- /dev/null +++ b/Bachelor/Prog1/examples/ch05/Fig05_32.cpp @@ -0,0 +1,40 @@ +// Fig. 5.32: fig05_32.cpp +// Using strlen. +#include + +using std::cout; +using std::endl; + +#include // prototype for strlen + +int main() +{ + char *string1 = "abcdefghijklmnopqrstuvwxyz"; + char *string2 = "four"; + char *string3 = "Boston"; + + cout << "The length of \"" << string1 + << "\" is " << strlen( string1 ) + << "\nThe length of \"" << string2 + << "\" is " << strlen( string2 ) + << "\nThe length of \"" << string3 + << "\" is " << strlen( string3 ) << endl; + + return 0; // indicates successful termination + +} // end main + +/************************************************************************** + * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * + * Hall. All Rights Reserved. * + * * + * DISCLAIMER: The authors and publisher of this book have used their * + * best efforts in preparing the book. These efforts include the * + * development, research, and testing of the theories and programs * + * to determine their effectiveness. The authors and publisher make * + * no warranty of any kind, expressed or implied, with regard to these * + * programs or to the documentation contained in these books. The authors * + * and publisher shall not be liable in any event for incidental or * + * consequential damages in connection with, or arising out of, the * + * furnishing, performance, or use of these programs. * + *************************************************************************/ -- cgit v1.2.3