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/ch04/Ex04_18.cpp | 49 ++++++++ Bachelor/Prog1/examples/ch04/Ex04_21.cpp | 47 ++++++++ Bachelor/Prog1/examples/ch04/Fig04_03.cpp | 44 +++++++ Bachelor/Prog1/examples/ch04/Fig04_04.cpp | 42 +++++++ Bachelor/Prog1/examples/ch04/Fig04_05.cpp | 46 +++++++ Bachelor/Prog1/examples/ch04/Fig04_06.cpp | 35 ++++++ Bachelor/Prog1/examples/ch04/Fig04_07.cpp | 29 +++++ Bachelor/Prog1/examples/ch04/Fig04_08.cpp | 41 +++++++ Bachelor/Prog1/examples/ch04/Fig04_09.cpp | 49 ++++++++ Bachelor/Prog1/examples/ch04/Fig04_10.cpp | 53 ++++++++ Bachelor/Prog1/examples/ch04/Fig04_11.cpp | 58 +++++++++ Bachelor/Prog1/examples/ch04/Fig04_12.cpp | 49 ++++++++ Bachelor/Prog1/examples/ch04/Fig04_13.cpp | 82 +++++++++++++ Bachelor/Prog1/examples/ch04/Fig04_14.cpp | 87 ++++++++++++++ Bachelor/Prog1/examples/ch04/Fig04_15.cpp | 46 +++++++ Bachelor/Prog1/examples/ch04/Fig04_16.cpp | 65 ++++++++++ Bachelor/Prog1/examples/ch04/Fig04_17.cpp | 193 ++++++++++++++++++++++++++++++ Bachelor/Prog1/examples/ch04/Fig04_19.cpp | 63 ++++++++++ Bachelor/Prog1/examples/ch04/Fig04_20.cpp | 142 ++++++++++++++++++++++ Bachelor/Prog1/examples/ch04/Fig04_22.cpp | 57 +++++++++ Bachelor/Prog1/examples/ch04/Fig04_23.cpp | 134 +++++++++++++++++++++ 21 files changed, 1411 insertions(+) create mode 100644 Bachelor/Prog1/examples/ch04/Ex04_18.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Ex04_21.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_03.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_04.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_05.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_06.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_07.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_08.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_09.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_10.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_11.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_12.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_13.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_14.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_15.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_16.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_17.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_19.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_20.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_22.cpp create mode 100644 Bachelor/Prog1/examples/ch04/Fig04_23.cpp (limited to 'Bachelor/Prog1/examples/ch04') diff --git a/Bachelor/Prog1/examples/ch04/Ex04_18.cpp b/Bachelor/Prog1/examples/ch04/Ex04_18.cpp new file mode 100644 index 0000000..9ccbc6e --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Ex04_18.cpp @@ -0,0 +1,49 @@ +// Ex. 4.18: ex04_18.cpp +// What does this program do? +#include + +using std::cout; +using std::endl; + +int whatIsThis( int [], int ); // function prototype + +int main() +{ + const int arraySize = 10; + int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + int result = whatIsThis( a, arraySize ); + + cout << "Result is " << result << endl; + + return 0; // indicates successful termination + +} // end main + +// What does this function do? +int whatIsThis( int b[], int size ) +{ + // base case + if ( size == 1 ) + return b[ 0 ]; + + // recursive step + else + return b[ size - 1 ] + whatIsThis( b, size - 1 ); + +} // end function whatIsThis + +/************************************************************************** + * (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/ch04/Ex04_21.cpp b/Bachelor/Prog1/examples/ch04/Ex04_21.cpp new file mode 100644 index 0000000..06c3e49 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Ex04_21.cpp @@ -0,0 +1,47 @@ +// Ex. 4.21: ex04_21.cpp +// What does this program do? +#include + +using std::cout; +using std::endl; + +void someFunction( int [], int, int ); // function prototype + +int main() +{ + const int arraySize = 10; + int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + cout << "The values in the array are:" << endl; + someFunction( a, 0, arraySize ); + cout << endl; + + return 0; // indicates successful termination + +} // end main + +// What does this function do? +void someFunction( int b[], int current, int size ) +{ + if ( current < size ) { + someFunction( b, current + 1, size ); + cout << b[ current ] << " "; + } + +} // end function someFunction + + +/************************************************************************** + * (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/ch04/Fig04_03.cpp b/Bachelor/Prog1/examples/ch04/Fig04_03.cpp new file mode 100644 index 0000000..9dffb95 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_03.cpp @@ -0,0 +1,44 @@ +// Fig. 4.3: fig04_03.cpp +// Initializing an array. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +int main() +{ + int n[ 10 ]; // n is an array of 10 integers + + // initialize elements of array n to 0 + for ( int i = 0; i < 10; i++ ) + n[ i ] = 0; // set element at location i to 0 + + cout << "Element" << setw( 13 ) << "Value" << endl; + + // output contents of array n in tabular format + for ( int j = 0; j < 10; j++ ) + cout << setw( 7 ) << j << setw( 13 ) << n[ j ] << 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/ch04/Fig04_04.cpp b/Bachelor/Prog1/examples/ch04/Fig04_04.cpp new file mode 100644 index 0000000..6f6efb0 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_04.cpp @@ -0,0 +1,42 @@ +// Fig. 4.4: fig04_04.cpp +// Initializing an array with a declaration. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +int main() +{ + // use initializer list to initialize array n + int n[ 10 ] = { 32, 27, 64, 18, 95, 14, 90, 70, 60, 37 }; + + cout << "Element" << setw( 13 ) << "Value" << endl; + + // output contents of array n in tabular format + for ( int i = 0; i < 10; i++ ) + cout << setw( 7 ) << i << setw( 13 ) << n[ i ] << 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/ch04/Fig04_05.cpp b/Bachelor/Prog1/examples/ch04/Fig04_05.cpp new file mode 100644 index 0000000..4905155 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_05.cpp @@ -0,0 +1,46 @@ +// Fig. 4.5: fig04_05.cpp +// Initialize array s to the even integers from 2 to 20. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +int main() +{ + // constant variable can be used to specify array size + const int arraySize = 10; + + int s[ arraySize ]; // array s has 10 elements + + for ( int i = 0; i < arraySize; i++ ) // set the values + s[ i ] = 2 + 2 * i; + + cout << "Element" << setw( 13 ) << "Value" << endl; + + // output contents of array s in tabular format + for ( int j = 0; j < arraySize; j++ ) + cout << setw( 7 ) << j << setw( 13 ) << s[ j ] << 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/ch04/Fig04_06.cpp b/Bachelor/Prog1/examples/ch04/Fig04_06.cpp new file mode 100644 index 0000000..f62da85 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_06.cpp @@ -0,0 +1,35 @@ +// Fig. 4.6: fig04_06.cpp +// Using a properly initialized constant variable. +#include + +using std::cout; +using std::endl; + +int main() +{ + const int x = 7; // initialized constant variable + + cout << "The value of constant variable x is: " + << x << 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/ch04/Fig04_07.cpp b/Bachelor/Prog1/examples/ch04/Fig04_07.cpp new file mode 100644 index 0000000..bc1cc0c --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_07.cpp @@ -0,0 +1,29 @@ +// Fig. 4.7: fig04_07.cpp +// A const object must be initialized. + +int main() +{ + const int x; // Error: x must be initialized + + x = 7; // Error: cannot modify a const variable + + 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/ch04/Fig04_08.cpp b/Bachelor/Prog1/examples/ch04/Fig04_08.cpp new file mode 100644 index 0000000..bda7cc0 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_08.cpp @@ -0,0 +1,41 @@ +// Fig. 4.8: fig04_08.cpp +// Compute the sum of the elements of the array. +#include + +using std::cout; +using std::endl; + +int main() +{ + const int arraySize = 10; + + int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + int total = 0; + + // sum contents of array a + for ( int i = 0; i < arraySize; i++ ) + total += a[ i ]; + + cout << "Total of array element values is " << total << 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/ch04/Fig04_09.cpp b/Bachelor/Prog1/examples/ch04/Fig04_09.cpp new file mode 100644 index 0000000..1b722e9 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_09.cpp @@ -0,0 +1,49 @@ +// Fig. 4.9: fig04_09.cpp +// Histogram printing program. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +int main() +{ + const int arraySize = 10; + int n[ arraySize ] = { 19, 3, 15, 7, 11, 9, 13, 5, 17, 1 }; + + cout << "Element" << setw( 13 ) << "Value" + << setw( 17 ) << "Histogram" << endl; + + // for each element of array n, output a bar in histogram + for ( int i = 0; i < arraySize; i++ ) { + cout << setw( 7 ) << i << setw( 13 ) + << n[ i ] << setw( 9 ); + + for ( int j = 0; j < n[ i ]; j++ ) // print one bar + cout << '*'; + + cout << endl; // start next line of output + + } // end outer for structure + + 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/ch04/Fig04_10.cpp b/Bachelor/Prog1/examples/ch04/Fig04_10.cpp new file mode 100644 index 0000000..9984df6 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_10.cpp @@ -0,0 +1,53 @@ +// Fig. 4.10: fig04_10.cpp +// Roll a six-sided die 6000 times. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +#include +#include + +int main() +{ + const int arraySize = 7; + int frequency[ arraySize ] = { 0 }; + + srand( time( 0 ) ); // seed random-number generator + + // roll die 6000 times + for ( int roll = 1; roll <= 6000; roll++ ) + ++frequency[ 1 + rand() % 6 ]; // replaces 20-line switch + // of Fig. 3.8 + + cout << "Face" << setw( 13 ) << "Frequency" << endl; + + // output frequency elements 1-6 in tabular format + for ( int face = 1; face < arraySize; face++ ) + cout << setw( 4 ) << face + << setw( 13 ) << frequency[ face ] << 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/ch04/Fig04_11.cpp b/Bachelor/Prog1/examples/ch04/Fig04_11.cpp new file mode 100644 index 0000000..86eba62 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_11.cpp @@ -0,0 +1,58 @@ +// Fig. 4.11: fig04_11.cpp +// Student poll program. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +int main() +{ + // define array sizes + const int responseSize = 40; // size of array responses + const int frequencySize = 11; // size of array frequency + + // place survey responses in array responses + int responses[ responseSize ] = { 1, 2, 6, 4, 8, 5, 9, 7, 8, + 10, 1, 6, 3, 8, 6, 10, 3, 8, 2, 7, 6, 5, 7, 6, 8, 6, 7, + 5, 6, 6, 5, 6, 7, 5, 6, 4, 8, 6, 8, 10 }; + + // initialize frequency counters to 0 + int frequency[ frequencySize ] = { 0 }; + + // for each answer, select value of an element of array + // responses and use that value as subscript in array + // frequency to determine element to increment + for ( int answer = 0; answer < responseSize; answer++ ) + ++frequency[ responses[answer] ]; + + // display results + cout << "Rating" << setw( 17 ) << "Frequency" << endl; + + // output frequencies in tabular format + for ( int rating = 1; rating < frequencySize; rating++ ) + cout << setw( 6 ) << rating + << setw( 17 ) << frequency[ rating ] << 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/ch04/Fig04_12.cpp b/Bachelor/Prog1/examples/ch04/Fig04_12.cpp new file mode 100644 index 0000000..115d033 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_12.cpp @@ -0,0 +1,49 @@ +// Fig. 4_12: fig04_12.cpp +// Treating character arrays as strings. +#include + +using std::cout; +using std::cin; +using std::endl; + +int main() +{ + char string1[ 20 ]; // reserves 20 characters + char string2[] = "string literal"; // reserves 15 characters + + // read string from user into array string2 + cout << "Enter the string \"hello there\": "; + cin >> string1; // reads "hello" [space terminates input] + + // output strings + cout << "string1 is: " << string1 + << "\nstring2 is: " << string2; + + cout << "\nstring1 with spaces between characters is:\n"; + + // output characters until null character is reached + for ( int i = 0; string1[ i ] != '\0'; i++ ) + cout << string1[ i ] << ' '; + + cin >> string1; // reads "there" + cout << "\nstring1 is: " << string1 << 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/ch04/Fig04_13.cpp b/Bachelor/Prog1/examples/ch04/Fig04_13.cpp new file mode 100644 index 0000000..ed21456 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_13.cpp @@ -0,0 +1,82 @@ +// Fig. 4.13: fig04_13.cpp +// Static arrays are initialized to zero. +#include + +using std::cout; +using std::endl; + +void staticArrayInit( void ); // function prototype +void automaticArrayInit( void ); // function prototype + +int main() +{ + cout << "First call to each function:\n"; + staticArrayInit(); + automaticArrayInit(); + + cout << "\n\nSecond call to each function:\n"; + staticArrayInit(); + automaticArrayInit(); + cout << endl; + + return 0; // indicates successful termination + +} // end main + +// function to demonstrate a static local array +void staticArrayInit( void ) +{ + // initializes elements to 0 first time function is called + static int array1[ 3 ]; + + cout << "\nValues on entering staticArrayInit:\n"; + + // output contents of array1 + for ( int i = 0; i < 3; i++ ) + cout << "array1[" << i << "] = " << array1[ i ] << " "; + + cout << "\nValues on exiting staticArrayInit:\n"; + + // modify and output contents of array1 + for ( int j = 0; j < 3; j++ ) + cout << "array1[" << j << "] = " + << ( array1[ j ] += 5 ) << " "; + +} // end function staticArrayInit + +// function to demonstrate an automatic local array +void automaticArrayInit( void ) +{ + // initializes elements each time function is called + int array2[ 3 ] = { 1, 2, 3 }; + + cout << "\n\nValues on entering automaticArrayInit:\n"; + + // output contents of array2 + for ( int i = 0; i < 3; i++ ) + cout << "array2[" << i << "] = " << array2[ i ] << " "; + + cout << "\nValues on exiting automaticArrayInit:\n"; + + // modify and output contents of array2 + for ( int j = 0; j < 3; j++ ) + cout << "array2[" << j << "] = " + << ( array2[ j ] += 5 ) << " "; + +} // end function automaticArrayInit + + +/************************************************************************** + * (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/ch04/Fig04_14.cpp b/Bachelor/Prog1/examples/ch04/Fig04_14.cpp new file mode 100644 index 0000000..a1db3ea --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_14.cpp @@ -0,0 +1,87 @@ +// Fig. 4.14: fig04_14.cpp +// Passing arrays and individual array elements to functions. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +void modifyArray( int [], int ); // appears strange +void modifyElement( int ); + +int main() +{ + const int arraySize = 5; // size of array a + int a[ arraySize ] = { 0, 1, 2, 3, 4 }; // initialize a + + cout << "Effects of passing entire array by reference:" + << "\n\nThe values of the original array are:\n"; + + // output original array + for ( int i = 0; i < arraySize; i++ ) + cout << setw( 3 ) << a[ i ]; + + cout << endl; + + // pass array a to modifyArray by reference + modifyArray( a, arraySize ); + + cout << "The values of the modified array are:\n"; + + // output modified array + for ( int j = 0; j < arraySize; j++ ) + cout << setw( 3 ) << a[ j ]; + + // output value of a[ 3 ] + cout << "\n\n\n" + << "Effects of passing array element by value:" + << "\n\nThe value of a[3] is " << a[ 3 ] << '\n'; + + // pass array element a[ 3 ] by value + modifyElement( a[ 3 ] ); + + // output value of a[ 3 ] + cout << "The value of a[3] is " << a[ 3 ] << endl; + + return 0; // indicates successful termination + +} // end main + +// in function modifyArray, "b" points to +// the original array "a" in memory +void modifyArray( int b[], int sizeOfArray ) +{ + // multiply each array element by 2 + for ( int k = 0; k < sizeOfArray; k++ ) + b[ k ] *= 2; + +} // end function modifyArray + +// in function modifyElement, "e" is a local copy of +// array element a[ 3 ] passed from main +void modifyElement( int e ) +{ + // multiply parameter by 2 + cout << "Value in modifyElement is " + << ( e *= 2 ) << endl; + +} // end function modifyElement + + +/************************************************************************** + * (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/ch04/Fig04_15.cpp b/Bachelor/Prog1/examples/ch04/Fig04_15.cpp new file mode 100644 index 0000000..5d35b9d --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_15.cpp @@ -0,0 +1,46 @@ +// Fig. 4.15: fig04_15.cpp +// Demonstrating the const type qualifier. +#include + +using std::cout; +using std::endl; + +void tryToModifyArray( const int [] ); // function prototype + +int main() +{ + int a[] = { 10, 20, 30 }; + + tryToModifyArray( a ); + + cout << a[ 0 ] << ' ' << a[ 1 ] << ' ' << a[ 2 ] << '\n'; + + return 0; // indicates successful termination + +} // end main + +// In function tryToModifyArray, "b" cannot be used +// to modify the original array "a" in main. +void tryToModifyArray( const int b[] ) +{ + b[ 0 ] /= 2; // error + b[ 1 ] /= 2; // error + b[ 2 ] /= 2; // error + +} // end function tryToModifyArray + + +/************************************************************************** + * (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/ch04/Fig04_16.cpp b/Bachelor/Prog1/examples/ch04/Fig04_16.cpp new file mode 100644 index 0000000..e009daf --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_16.cpp @@ -0,0 +1,65 @@ +// Fig. 4.16: fig04_16.cpp +// This program sorts an array's values into ascending order. +#include + +using std::cout; +using std::endl; + +#include + +using std::setw; + +int main() +{ + const int arraySize = 10; // size of array a + int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 }; + int hold; // temporary location used to swap array elements + + cout << "Data items in original order\n"; + + // output original array + for ( int i = 0; i < arraySize; i++ ) + cout << setw( 4 ) << a[ i ]; + + // bubble sort + // loop to control number of passes + for ( int pass = 0; pass < arraySize - 1; pass++ ) + + // loop to control number of comparisons per pass + for ( int j = 0; j < arraySize - 1; j++ ) + + // compare side-by-side elements and swap them if + // first element is greater than second element + if ( a[ j ] > a[ j + 1 ] ) { + hold = a[ j ]; + a[ j ] = a[ j + 1 ]; + a[ j + 1 ] = hold; + + } // end if + + cout << "\nData items in ascending order\n"; + + // output sorted array + for ( int k = 0; k < arraySize; k++ ) + cout << setw( 4 ) << a[ k ]; + + cout << 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/ch04/Fig04_17.cpp b/Bachelor/Prog1/examples/ch04/Fig04_17.cpp new file mode 100644 index 0000000..c6442c1 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_17.cpp @@ -0,0 +1,193 @@ +// Fig. 4.17: fig04_17.cpp +// This program introduces the topic of survey data analysis. +// It computes the mean, median, and mode of the data. +#include + +using std::cout; +using std::endl; +using std::fixed; + +#include + +using std::setw; +using std::setprecision; + +void mean( const int [], int ); +void median( int [], int ); +void mode( int [], int [], int ); +void bubbleSort( int[], int ); +void printArray( const int[], int ); + +int main() +{ + const int responseSize = 99; // size of array responses + + int frequency[ 10 ] = { 0 }; // initialize array frequency + + // initialize array responses + int response[ responseSize ] = + { 6, 7, 8, 9, 8, 7, 8, 9, 8, 9, + 7, 8, 9, 5, 9, 8, 7, 8, 7, 8, + 6, 7, 8, 9, 3, 9, 8, 7, 8, 7, + 7, 8, 9, 8, 9, 8, 9, 7, 8, 9, + 6, 7, 8, 7, 8, 7, 9, 8, 9, 2, + 7, 8, 9, 8, 9, 8, 9, 7, 5, 3, + 5, 6, 7, 2, 5, 3, 9, 4, 6, 4, + 7, 8, 9, 6, 8, 7, 8, 9, 7, 8, + 7, 4, 4, 2, 5, 3, 8, 7, 5, 6, + 4, 5, 6, 1, 6, 5, 7, 8, 7 }; + + // process responses + mean( response, responseSize ); + median( response, responseSize ); + mode( frequency, response, responseSize ); + + return 0; // indicates successful termination + +} // end main + +// calculate average of all response values +void mean( const int answer[], int arraySize ) +{ + int total = 0; + + cout << "********\n Mean\n********\n"; + + // total response values + for ( int i = 0; i < arraySize; i++ ) + total += answer[ i ]; + + // format and output results + cout << fixed << setprecision( 4 ); + + cout << "The mean is the average value of the data\n" + << "items. The mean is equal to the total of\n" + << "all the data items divided by the number\n" + << "of data items (" << arraySize + << "). The mean value for\nthis run is: " + << total << " / " << arraySize << " = " + << static_cast< double >( total ) / arraySize + << "\n\n"; + +} // end function mean + +// sort array and determine median element's value +void median( int answer[], int size ) +{ + cout << "\n********\n Median\n********\n" + << "The unsorted array of responses is"; + + printArray( answer, size ); // output unsorted array + + bubbleSort( answer, size ); // sort array + + cout << "\n\nThe sorted array is"; + printArray( answer, size ); // output sorted array + + // display median element + cout << "\n\nThe median is element " << size / 2 + << " of\nthe sorted " << size + << " element array.\nFor this run the median is " + << answer[ size / 2 ] << "\n\n"; + +} // end function median + +// determine most frequent response +void mode( int freq[], int answer[], int size ) +{ + int largest = 0; // represents largest frequency + int modeValue = 0; // represents most frequent response + + cout << "\n********\n Mode\n********\n"; + + // initialize frequencies to 0 + for ( int i = 1; i <= 9; i++ ) + freq[ i ] = 0; + + // summarize frequencies + for ( int j = 0; j < size; j++ ) + ++freq[ answer[ j ] ]; + + // output headers for result columns + cout << "Response" << setw( 11 ) << "Frequency" + << setw( 19 ) << "Histogram\n\n" << setw( 55 ) + << "1 1 2 2\n" << setw( 56 ) + << "5 0 5 0 5\n\n"; + + // output results + for ( int rating = 1; rating <= 9; rating++ ) { + cout << setw( 8 ) << rating << setw( 11 ) + << freq[ rating ] << " "; + + // keep track of mode value and largest fequency value + if ( freq[ rating ] > largest ) { + largest = freq[ rating ]; + modeValue = rating; + + } // end if + + // output histogram bar representing frequency value + for ( int k = 1; k <= freq[ rating ]; k++ ) + cout << '*'; + + cout << '\n'; // begin new line of output + + } // end outer for + + // display the mode value + cout << "The mode is the most frequent value.\n" + << "For this run the mode is " << modeValue + << " which occurred " << largest << " times." << endl; + +} // end function mode + +// function that sorts an array with bubble sort algorithm +void bubbleSort( int a[], int size ) +{ + int hold; // temporary location used to swap elements + + // loop to control number of passes + for ( int pass = 1; pass < size; pass++ ) + + // loop to control number of comparisons per pass + for ( int j = 0; j < size - 1; j++ ) + + // swap elements if out of order + if ( a[ j ] > a[ j + 1 ] ) { + hold = a[ j ]; + a[ j ] = a[ j + 1 ]; + a[ j + 1 ] = hold; + + } // end if + +} // end function bubbleSort + +// output array contents (20 values per row) +void printArray( const int a[], int size ) +{ + for ( int i = 0; i < size; i++ ) { + + if ( i % 20 == 0 ) // begin new line every 20 values + cout << endl; + + cout << setw( 2 ) << a[ i ]; + + } // end for + +} // end function printArray + + +/************************************************************************** + * (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/ch04/Fig04_19.cpp b/Bachelor/Prog1/examples/ch04/Fig04_19.cpp new file mode 100644 index 0000000..0be6aa3 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_19.cpp @@ -0,0 +1,63 @@ +// Fig. 4.19: fig04_19.cpp +// Linear search of an array. +#include + +using std::cout; +using std::cin; +using std::endl; + +int linearSearch( const int [], int, int ); // prototype + +int main() +{ + const int arraySize = 100; // size of array a + int a[ arraySize ]; // create array a + int searchKey; // value to locate in a + + for ( int i = 0; i < arraySize; i++ ) // create some data + a[ i ] = 2 * i; + + cout << "Enter integer search key: "; + cin >> searchKey; + + // attempt to locate searchKey in array a + int element = linearSearch( a, searchKey, arraySize ); + + // display results + if ( element != -1 ) + cout << "Found value in element " << element << endl; + else + cout << "Value not found" << endl; + + return 0; // indicates successful termination + +} // end main + +// compare key to every element of array until location is +// found or until end of array is reached; return subscript of +// element if key or -1 if key not found +int linearSearch( const int array[], int key, int sizeOfArray ) +{ + for ( int j = 0; j < sizeOfArray; j++ ) + + if ( array[ j ] == key ) // if found, + return j; // return location of key + + return -1; // key not found + +} // end function linearSearch + +/************************************************************************** + * (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/ch04/Fig04_20.cpp b/Bachelor/Prog1/examples/ch04/Fig04_20.cpp new file mode 100644 index 0000000..241c800 --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_20.cpp @@ -0,0 +1,142 @@ +// Fig. 4.20: fig04_20.cpp +// Binary search of an array. +#include + +using std::cout; +using std::cin; +using std::endl; + +#include + +using std::setw; + +// function prototypes +int binarySearch( const int [], int, int, int, int ); +void printHeader( int ); +void printRow( const int [], int, int, int, int ); + +int main() +{ + const int arraySize = 15; // size of array a + int a[ arraySize ]; // create array a + int key; // value to locate in a + + for ( int i = 0; i < arraySize; i++ ) // create some data + a[ i ] = 2 * i; + + cout << "Enter a number between 0 and 28: "; + cin >> key; + + printHeader( arraySize ); + + // search for key in array a + int result = + binarySearch( a, key, 0, arraySize - 1, arraySize ); + + // display results + if ( result != -1 ) + cout << '\n' << key << " found in array element " + << result << endl; + else + cout << '\n' << key << " not found" << endl; + + return 0; // indicates successful termination + +} // end main + +// function to perform binary search of an array +int binarySearch( const int b[], int searchKey, int low, + int high, int size ) +{ + int middle; + + // loop until low subscript is greater than high subscript + while ( low <= high ) { + + // determine middle element of subarray being searched + middle = ( low + high ) / 2; + + // display subarray used in this loop iteration + printRow( b, low, middle, high, size ); + + // if searchKey matches middle element, return middle + if ( searchKey == b[ middle ] ) // match + return middle; + + else + + // if searchKey less than middle element, + // set new high element + if ( searchKey < b[ middle ] ) + high = middle - 1; // search low end of array + + // if searchKey greater than middle element, + // set new low element + else + low = middle + 1; // search high end of array + } + + return -1; // searchKey not found + +} // end function binarySearch + +// print header for output +void printHeader( int size ) +{ + cout << "\nSubscripts:\n"; + + // output column heads + for ( int j = 0; j < size; j++ ) + cout << setw( 3 ) << j << ' '; + + cout << '\n'; // start new line of output + + // output line of - characters + for ( int k = 1; k <= 4 * size; k++ ) + cout << '-'; + + cout << endl; // start new line of output + +} // end function printHeader + +// print one row of output showing the current +// part of the array being processed +void printRow( const int b[], int low, int mid, + int high, int size ) +{ + // loop through entire array + for ( int m = 0; m < size; m++ ) + + // display spaces if outside current subarray range + if ( m < low || m > high ) + cout << " "; + + // display middle element marked with a * + else + + if ( m == mid ) // mark middle value + cout << setw( 3 ) << b[ m ] << '*'; + + // display other elements in subarray + else + cout << setw( 3 ) << b[ m ] << ' '; + + cout << endl; // start new line of output + +} // end function printRow + + +/************************************************************************** + * (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/ch04/Fig04_22.cpp b/Bachelor/Prog1/examples/ch04/Fig04_22.cpp new file mode 100644 index 0000000..44c17da --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_22.cpp @@ -0,0 +1,57 @@ +// Fig. 4.22: fig04_22.cpp +// Initializing multidimensional arrays. +#include + +using std::cout; +using std::endl; + +void printArray( int [][ 3 ] ); + +int main() +{ + int array1[ 2 ][ 3 ] = { { 1, 2, 3 }, { 4, 5, 6 } }; + int array2[ 2 ][ 3 ] = { 1, 2, 3, 4, 5 }; + int array3[ 2 ][ 3 ] = { { 1, 2 }, { 4 } }; + + cout << "Values in array1 by row are:" << endl; + printArray( array1 ); + + cout << "Values in array2 by row are:" << endl; + printArray( array2 ); + + cout << "Values in array3 by row are:" << endl; + printArray( array3 ); + + return 0; // indicates successful termination + +} // end main + +// function to output array with two rows and three columns +void printArray( int a[][ 3 ] ) +{ + for ( int i = 0; i < 2; i++ ) { // for each row + + for ( int j = 0; j < 3; j++ ) // output column values + cout << a[ i ][ j ] << ' '; + + cout << endl; // start new line of output + + } // end outer for structure + +} // end function printArray + + +/************************************************************************** + * (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/ch04/Fig04_23.cpp b/Bachelor/Prog1/examples/ch04/Fig04_23.cpp new file mode 100644 index 0000000..7957c1e --- /dev/null +++ b/Bachelor/Prog1/examples/ch04/Fig04_23.cpp @@ -0,0 +1,134 @@ +// Fig. 4.23: fig04_23.cpp +// Double-subscripted array example. +#include + +using std::cout; +using std::endl; +using std::fixed; +using std::left; + +#include + +using std::setw; +using std::setprecision; + +const int students = 3; // number of students +const int exams = 4; // number of exams + +// function prototypes +int minimum( int [][ exams ], int, int ); +int maximum( int [][ exams ], int, int ); +double average( int [], int ); +void printArray( int [][ exams ], int, int ); + +int main() +{ + // initialize student grades for three students (rows) + int studentGrades[ students ][ exams ] = + { { 77, 68, 86, 73 }, + { 96, 87, 89, 78 }, + { 70, 90, 86, 81 } }; + + // output array studentGrades + cout << "The array is:\n"; + printArray( studentGrades, students, exams ); + + // determine smallest and largest grade values + cout << "\n\nLowest grade: " + << minimum( studentGrades, students, exams ) + << "\nHighest grade: " + << maximum( studentGrades, students, exams ) << '\n'; + + cout << fixed << setprecision( 2 ); + + // calculate average grade for each student + for ( int person = 0; person < students; person++ ) + cout << "The average grade for student " << person + << " is " + << average( studentGrades[ person ], exams ) + << endl; + + return 0; // indicates successful termination + +} // end main + +// find minimum grade +int minimum( int grades[][ exams ], int pupils, int tests ) +{ + int lowGrade = 100; // initialize to highest possible grade + + for ( int i = 0; i < pupils; i++ ) + + for ( int j = 0; j < tests; j++ ) + + if ( grades[ i ][ j ] < lowGrade ) + lowGrade = grades[ i ][ j ]; + + return lowGrade; + +} // end function minimum + +// find maximum grade +int maximum( int grades[][ exams ], int pupils, int tests ) +{ + int highGrade = 0; // initialize to lowest possible grade + + for ( int i = 0; i < pupils; i++ ) + + for ( int j = 0; j < tests; j++ ) + + if ( grades[ i ][ j ] > highGrade ) + highGrade = grades[ i ][ j ]; + + return highGrade; + +} // end function maximum + +// determine average grade for particular student +double average( int setOfGrades[], int tests ) +{ + int total = 0; + + // total all grades for one student + for ( int i = 0; i < tests; i++ ) + total += setOfGrades[ i ]; + + return static_cast< double >( total ) / tests; // average + +} // end function maximum + +// Print the array +void printArray( int grades[][ exams ], int pupils, int tests ) +{ + // set left justification and output column heads + cout << left << " [0] [1] [2] [3]"; + + // output grades in tabular format + for ( int i = 0; i < pupils; i++ ) { + + // output label for row + cout << "\nstudentGrades[" << i << "] "; + + // output one grades for one student + for ( int j = 0; j < tests; j++ ) + cout << setw( 5 ) << grades[ i ][ j ]; + + } // end outer for + +} // end function printArray + + +/************************************************************************** + * (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