This page contains any code snippets or source code from our discussions in class or lab that may be of good use.
In the box below, are code snippets that you are free to add to your programs (remember, code re-use is an awesome idea in which we do not spend time "re-inventing" the wheel).
Code snippet: getIntegerNumber.snp
Example of code in use: getIntegerNumber_example.cpp
Chapter 6 Algorithm Workbench 37
The following are select programming examples that are found in Chapter 7.
Program 7-1: ch7_1.cpp
Program 7-2: ch7_2.cpp
Program 7-5: ch7_5.cpp
Program 7-6: ch7_6.cpp
Program 7-7: ch7_7.cpp
Program 7-9: ch7_9.cpp
Program 7-10: ch7_10.cpp
Parallel Arrays: ch7_parallel_arrays_1.cpp
Writing out Text File, with text file containing the array content in the format of:
number_of_elements (n)
Element_0
...
Element_(n-1)
The file can be found here: array_write_demo.cpp
Reading In Text File, Filling Array with textfile content in the format of:
number_of_elements (n)
Element_0
...
Element_(n-1)
The file can be found here: array_read_demo_main.cpp
Reading In Text File, Filling Array with text file content in the format of (number of elements in array is unknown - program has to count the number of elements, then re-read in the items):
Element_0
...
Element_(n-1)
The file can be found here: array_read_demo_unknown_array_size.cpp
Here is a vector based version of the program named array_read_demo_unknown_array_size.cpp, which does the same logic for the most part except, it does not read in the file twice! It utilizes then vector class member function called push_back, to read in the value from the text file, and place it at the end of the vector as the vector is being built through each iteration.
The file can be found here: vector_read_demo_unknown_list_size.cpp
Linear Search and Binary Search Demos / Sorting
Search demo: search_demo.cpp
The Bubble Sort and Selection Sort code snippets.
Bubble Sort: bubbleSort.snp
Selection Sort: selectionSort.snp
Arrays and Pointers: array_pointers.cpp
Functions and Pointers: functions_pointers.cpp
Introduction to #include <cctype> (Chapter 10): cctype_intro.cpp
and corresponding .h header file: Money.h
RCC Courses Page
Go back to Riverside City College Courses page:
rcc.courses.html
. . . . . . . . . ( end of section CSC 5 - Code Snippets) <<Contents | Index>>