100% found this document useful (1 vote)
10 views

Instant Access to (Ebook) Programming Fundamentals: A Modular Structured Approach Using C++ by Kenneth Leroy Busbee ISBN 9781616100650, 1616100656 ebook Full Chapters

The document provides information on various ebooks available for download, including 'Programming Fundamentals: A Modular Structured Approach Using C++' by Kenneth Leroy Busbee. It lists several other recommended ebooks with their respective links and ISBNs. The document also includes a brief overview of the content structure and topics covered in the programming fundamentals ebook.

Uploaded by

yzabelwazani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
10 views

Instant Access to (Ebook) Programming Fundamentals: A Modular Structured Approach Using C++ by Kenneth Leroy Busbee ISBN 9781616100650, 1616100656 ebook Full Chapters

The document provides information on various ebooks available for download, including 'Programming Fundamentals: A Modular Structured Approach Using C++' by Kenneth Leroy Busbee. It lists several other recommended ebooks with their respective links and ISBNs. The document also includes a brief overview of the content structure and topics covered in the programming fundamentals ebook.

Uploaded by

yzabelwazani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

Visit https://ebooknice.

com to download the full version and


explore more ebooks

(Ebook) Programming Fundamentals: A Modular


Structured Approach Using C++ by Kenneth Leroy
Busbee ISBN 9781616100650, 1616100656

_____ Click the link below to download _____


https://ebooknice.com/product/programming-fundamentals-
a-modular-structured-approach-using-c-10013992

Explore and download more ebooks at ebooknice.com


Here are some recommended products that might interest you.
You can download now and explore!

(Ebook) Mnemonics for Radiologists and FRCR 2B Viva Preparation Ebook:


A systematic approach (Masterpass) by William Bugg ISBN 9781908911049,
1908911042

https://ebooknice.com/product/mnemonics-for-radiologists-and-
frcr-2b-viva-preparation-ebook-a-systematic-approach-
masterpass-5754006
ebooknice.com

(Ebook) Primary Mathematics Workbook 2B by Jennifer Hoerst ISBN


9780761469933, 0761469931

https://ebooknice.com/product/primary-mathematics-workbook-2b-23520620

ebooknice.com

(Ebook) Primary Mathematics Textbook 2B by Jennifer Hoerst ISBN


9780761469797, 0761469796

https://ebooknice.com/product/primary-mathematics-textbook-2b-23519854

ebooknice.com

(Ebook) Computer Science: A Structured Approach Using C by Behrouz A.


Forouzan; Richard F. Gilberg ISBN 9780534491321, 0534491324

https://ebooknice.com/product/computer-science-a-structured-approach-
using-c-10453060

ebooknice.com
(Ebook) Final FRCR 2B Long Cases: A Survival Guide by Jessie Aw, John
Curtis ISBN 9780521740692, 052174069X

https://ebooknice.com/product/final-frcr-2b-long-cases-a-survival-
guide-1828512

ebooknice.com

(Ebook) My Pals are Here! Maths Pupil's Book 2B by Unknown ISBN


9789810119355, 9810119356

https://ebooknice.com/product/my-pals-are-here-maths-pupil-s-
book-2b-55756818

ebooknice.com

(Ebook) Mnemonics for Radiologists and FRCR 2B Viva Preparation - A


Systematic Approach (Aug 15, 2013)_(1908911956)_(CRC Press) by Yoong,
Phillip, Bugg, William, Johnson, Catherine A. ISBN 9781908911957,
1908911956
https://ebooknice.com/product/mnemonics-for-radiologists-and-
frcr-2b-viva-preparation-a-systematic-approach-
aug-15-2013-1908911956-crc-press-54901480
ebooknice.com

(Ebook) Advanced Complex Analysis: A Comprehensive Course in Analysis,


Part 2B by Barry Simon ISBN 9781470411015, 9781470437770, 1470411016,
1470437775

https://ebooknice.com/product/advanced-complex-analysis-a-
comprehensive-course-in-analysis-part-2b-7440176

ebooknice.com

(Ebook) Programming Fundamentals Using JAVA: A Game Application


Approach by William McAllister, S. Jane Fritz ISBN 9781683926696,
1683926692

https://ebooknice.com/product/programming-fundamentals-using-java-a-
game-application-approach-33795060

ebooknice.com
Programming Fundamentals - A Modular
Structured Approach using C++

By:
Kenneth Leroy Busbee
Programming Fundamentals - A Modular
Structured Approach using C++

By:
Kenneth Leroy Busbee

Online:
< http://cnx.org/content/col10621/1.22/ >

CONNEXIONS

Rice University, Houston, Texas


This selection and arrangement of content as a collection is copyrighted by Kenneth Leroy Busbee. It is licensed
under the Creative Commons Attribution 3.0 license (http://creativecommons.org/licenses/by/3.0/).
Collection structure revised: January 10, 2013
PDF generated: January 10, 2013
For copyright and attribution information for the modules contained in this collection, see p. 318.
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Author Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Orientation and Syllabus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Sharing/Rating Connexions Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1 1. Introduction to Programming
1.1 Systems Development Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2 Bloodshed Dev-C++ 5 Compiler/IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3 Modularization and C++ Program Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4 Practice 1: Introduction to Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

2 2. Program Planning & Design


2.1 Program Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.2 Pseudocode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.3 Test Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.4 Practice 2: Program Planning & Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

3 3. Data & Operators


3.1 Data Types in C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.2 Identier Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.3 Constants and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.4 Data Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.5 Assignment Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.6 Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.7 Data Type Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.8 Practice 3: Data & Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

4 4. Often Used Data Types


4.1 Integer Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4.2 Floating-Point Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.3 String Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.4 Arithmetic Assignment Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.5 Lvalue and Rvalue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
4.6 Integer Division and Modulus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.7 Practice 4: Often Used Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

5 5. Integrated Development Environment


5.1 Integrated Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
5.2 Standard Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
5.3 Compiler Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
5.4 Practice 5: Integrated Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

6 6. Program Control Functions


6.1 Pseudocode Examples for Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
6.2 Hierarchy or Structure Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
6.3 Program Control Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
iv

6.4 Void Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83


6.5 Documentation and Making Source Code Readable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
6.6 Practice 6: Program Control Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

7 7. Specic Task Functions


7.1 Specic Task Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
7.2 Global vs Local Data Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
7.3 Using a Header File for User Dened Specic Task Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
7.4 Practice 7: Specic Task Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

8 8. Standard Libraries
8.1 Standard Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
8.2 Practice 8: Standard Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

9 9. Character Data, Sizeof, Typedef, Sequence


9.1 Character Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
9.2 Sizeof Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
9.3 Typedef - An Alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
9.4 Sequence Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
9.5 Practice 9: Character Data, Sizeof, Typedef, Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

10 10. Introduction to Structured Programming


10.1 Structured Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
10.2 Pseudocode Examples for Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
10.3 Flowcharting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
10.4 Practice 10: Introduction to Structured Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

11 11. Two Way Selection


11.1 If Then Else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
11.2 Boolean Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
11.3 Relational Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
11.4 Compound Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
11.5 Practice 11: Two Way Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

12 12. Multiway Selection


12.1 Nested If Then Else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
12.2 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
12.3 Case Control Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
12.4 Branching Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
12.5 Practice 12: Multiway Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

13 13. Test After Loops


13.1 Do While Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
13.2 Flag Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
13.3 Assignment vs Equality within C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
13.4 Repeat Until Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
13.5 Practice 13: Test After Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


v

14 14. Test Before Loops


14.1 Increment and Decrement Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
14.2 While Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
14.3 Practice 14: Test Before Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195

15 15. Counting Loops


15.1 For Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
15.2 Circular Nature of the Integer Data Type Family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
15.3 Formatting Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 203
15.4 Nested For Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
15.5 Practice 15: Counting Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212

16 16. String Class, Unary Positive and Negative


16.1 String Class within C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
16.2 Unary Positive and Negative Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
16.3 Practice 16: String Class, Unary Positive and Negative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219

17 17. Conditional Operator and Recursion


17.1 Conditional Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
17.2 Recursion vs Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
17.3 Practice 17: Conditional Operator and Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . 224
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226

18 18. Introduction to Arrays


18.1 Array Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
18.2 Array Index Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
18.3 Displaying Array Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
18.4 Practice 18: Introduction to Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234

19 19. File I/O and Array Functions


19.1 File Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
19.2 Arrays and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
19.3 Loading an Array from a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
19.4 Math Statistics with Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
19.5 Practice 19: File I/O and Array Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243

20 20. More Array Functions


20.1 Finding a Specic Member of an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
20.2 Sorting an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
20.3 Practice 20: More Array Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251

21 21. More on Typedef


21.1 Versatile Code with Typedef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
21.2 Practice 21: More on Typedef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257

22 22. Pointers
22.1 Address Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
22.2 Parameter Passing by Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


vi

22.3 Pointer Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261


22.4 Indirection Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
22.5 Practice 22: Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266

23 23. More Arrays & Compiler Directives


23.1 Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
23.2 Conditional Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
23.3 Practice 23: More Arrays & Compiler Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272

24 24. OOP & HPC


24.1 Object Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
24.2 Understanding High Performance Computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
24.3 Practice 24: OOP & HPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283

25 Review Materials
25.1 Review: Foundation Topics Group: 1-5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
25.2 Review: Modular Programming Group: 6-9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
25.3 Review: Structured Programming Group: 10-16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
25.4 Review: Intermediate Topics Group: 17-21 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
25.5 Review: Advanced Topics Group: 22-24 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
26 Appendix
26.1 Abbreviated Precedence Chart for C++ Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
26.2 C++ Reserved Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
26.3 ASCII Character Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
26.4 Show Hide File Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
26.5 Academic or Scholastic Dishonesty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
26.6 Successful Learning Skills . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
26.7 Study Habits that Build the Brain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305

Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Attributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


Preface 1

About this Textbook/Collection


Programming Fundamentals  A Modular Structured Approach using C++
Programming Fundamentals - A Modular Structured Approach using C++ is written by Kenneth Leroy
Busbee, a faculty member at Houston Community College in Houston, Texas. The materials used in this
textbook/collection were developed by the author and others as independent modules for publication within
the Connexions environment. Programming fundamentals are often divided into three college courses: Mod-
ular/Structured, Object Oriented and Data Structures. This textbook/collection covers the rst of those
three courses.
On January 10, 2013 Version 1.22 was created with the modules that make up the collection "xed" to
the their current versions. This will allow Version 1.22 to remain static with the modules as of that date.
The collection is going to be revised with a dierent organization of chapters along with updated modules
to handle C++, Java and C# programming languages. The next version of the collection will have signicant
changes.

Connexions Learning Modules


The learning modules of this textbook/collection were written as standalone modules. Students using a
collection of modules as a textbook will usually view it contents by reading the modules sequentially as
presented by the author of the collection.
However, the majority of readers of these modules will nd them as a result of an Internet search. The
Connexions Project allows the author of a module to create web links to other Connexions modules and
Internet locations. These links are shown when viewing materials on-line and are categorized into three
types: Example, Prerequisite and Supplemental. The importance of each link is numbered from 1 to 3 by
the author. When viewing the module each links shows a three part box with yellow or white rectangles.
strongly related link. As the yellow decreases the importance decreases.
All three yellow means it is a
Prerequisite links within
Students using this collection for a college course should note that all of the
the modules will be modules that student should have already read and most of the Supplemental links
will be modules that the student will read shortly. Thus, students should use Prerequisite links for review
as needed and not be overly concerned about viewing all of the Supplemental links at the rst reading of
this textbook/collection.

Conceptual Approach
The learning modules of this textbook/collection were, for the most part, written without consideration of
a specic programming language. In many cases the C++ language is discussed as part of the explanation
of the concept. Often the examples used for C++ are exactly the same for the Java programming language.
However, some modules were written specically for the C++ programming language. This could not be

1 This content is available online at <http://cnx.org/content/m19049/1.17/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>

1
2

avoided as the C++ language is used in conjunction with this textbook/collection by the author in teaching
college courses.

Bloodshed Dev-C++ 5 Compiler/IDE


This open source compiler/IDE (Integrated Development Environment) was used to develop the demon-
stration source code les provided within the modules of this textbook/collection. The compiler/IDE is
presented to the student in the second module of Chapter 1, with instructions for downloading, installing
and using the compiler/IDE. A more complete explanation of the IDE along with demonstration source code
listings with errors is presented in rst module of Chapter 5. All of the source code les provided in this
textbook/collection contain only ANSI standard C++ code and should work on any standard C++ compiler
like Microsoft Visual Studio (which includes C++), Microsoft Visual C++ Express or Borland C++ Builder.

Instructor Materials
Encrypted instructor materials are available in a module that is not part of this collection. It's title: Instruc-
tor Materials for: Programming Fundamentals - A Modular Structured Approach using C++ is available
at: http://cnx.org/content/m34529/latest/
2 and the encryption code is only available to educational insti-
tutional faculty that are considering adoption of this collection as a textbook.

About Connexions
Connexions Modular Content
The Connexions Project http://cnx.org
3 is part of the Open Educational Resources (OER) movement
dedicated to providing high quality learning materials free online, free in printable PDF format, and at
low cost in bound volumes through print-on-demand publishing. This textbook is one of many collections
available to Connexions users. Each collection is composed of a number of re-usable learning modules
written in the Connexions XML markup language. Each module may also be re-used (or 're-purposed') as
part of other collections and may be used outside of Connexions.

Re-use and Customization


The Creative Commons (CC) Attribution license
4 applies to all Connexions modules. Under this license,
any Connexions module may be used or modied for any purpose as long as proper attribution to the
original author(s) is maintained. Connexions' authoring tools make re-use (or re-purposing) easy. There-
fore, instructors anywhere are permitted to create customized versions of this textbook by editing modules,
deleting unneeded modules, and adding their own supplementary modules. Connexions' authoring tools
keep track of these changes and maintain the CC license's required attribution to the original authors. This
process creates a new collection that can be viewed online, downloaded as a single PDF le, or ordered in
any quantity by instructors and students as a low-cost printed textbook.

Read the book online, print the PDF, or buy a copy of the book.
To browse this textbook online, visit the collection home page. You will then have three options.

1. You may view the collection modules on-line by clicking on the "Start " link, which takes you to
the rst module in the collection. You can then navigate to the next module using "NEXT " and

2 "Instructor Materials for: Programming Fundamentals - A Modular Structured Approach using C++"
<http://cnx.org/content/m34529/latest/>
3 http://cnx.org/
4 http://creativecommons.org/licenses/by/2.0/

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


3

through the subsequent modules by using the " PREVIOUS | NEXT " button that is towards
the upper right to move forward and backward in the collection. You can jump to any module in the
collection by clicking on that module's title in the "TABLE OF CONTENTS" box on the left side of
the window. If these contents are hidden, make them visible by clicking on the small triangle to the
right of the "TABLE OF CONTENTS". Chapters also have a small triangle to show or hide contents.
2. You may obtain a PDF of the entire textbook to print or view oine by clicking on the "Download
PDF" link in the "Content Actions" box.
3. You may order a bound copy of the collection (for a reasonable printing and shipping fee) by clicking
on the "Order printed copy" button.

Connexions PDF Conversion Problems


Buying a copy of the textbook/collection is basically sending the PDF le to a printing service that has
a contract with the Connexions project. There are several known printing problems and the Connexions
Project is aware of them and seeking a solution. In the mean time, be aware that quirks exist for printed
PDF materials. A description of the known problems are:

1. When it converts an "Example" the PDF displays the rst line of an example properly but indents
the remaining lines of the example. This problem occurs for the printing of a book (because it prints
a PDF) and downloading either a module or a textbook/collection as a PDF.
2. Chapter numbering has been added to the on-line Table of Contents. This will make it easier for
students to quickly get to the chapter reading materials. However this creates a "double" chapter
numbering within the textbook/collection's PDF and custom printing formats.
3. Within C++ there are three operators that do not convert properly to PDF format.

decrement  which is two minus signs

insertion  which is two less than signs

extraction  which is two greater than signs

Table 1

Rating Connexion Modules


A rating feature was added during 2009 for Connexions modules. It will not be useful until more people
rate modules within the Connexions repository. If a module is rated by several people, it can be used as a
measure of quality. Thus, your participation in rating modules is welcomed and helps others determine
the quality of the educational materials being viewed.
In order to rate modules you must have a Connexions account. Three (3) modules have been added to
the preface series of modules for this collection. They explain why and how to create a Connexions account
and how to rate a Connexions module.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


4

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


Author Acknowledgements 5

I wish to acknowledge the many people who have helped me and have encouraged me in this project.

1. Mr. Abass Alamnehe, who is a fellow faculty member at Houston Community College. He has encour-
aged the use of Connexions as an "open source" publishing concept. His comments on several modules
have led directly to the improvement of the materials in this textbook/collection.
2. The hundreds (most likely a thousand plus) students that I have taken programming courses that I
have taught since 1984. The languages include: COBOL, main frame IBM assembly, Intel assembly,
Pascal, "C" and "C++". They have often suggested that I write my own book because they thought
that I was explaining the subject matter better than the author of the textbook that we were using.
Little did my students understand that directly or indirectly they aided in the improvement of the
materials from which I taught as well as improving me as a teacher.
3. To my future students and all those that will use this textbook/collection. They will provide suggestions
for improvement as well as being the thousand eyes identifying the hard to nd typos, etc.
4. My wife, Carol, who supports me in all that I do. She has tolerated the many hours that I have spent
in concentration on developing the modules that comprise this work. Without her support, this work
would not have happened.

5 This content is available online at <http://cnx.org/content/m19055/1.5/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>

5
6

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


Orientation and Syllabus 6

Orientation
Textbook/Collection Layout
The approach of this course will be to take the student through a progression of materials that will allow
the student to develop the skills of programming. The basic unit of study is a Connexions module. Several
modules are collected into a chapter. The chapters are divided into ve groups.

Group Title Chapters Modules

Pre-Chapter Items N/A 4

Foundation Topics 1-5 27

Modular Programming 6-9 17

Structured Programming 10-16 30

Intermediate Topics 17-21 17

Advanced Topics 22-24 11

Review Materials N/A 5

Appendix N/A 7

Total Modules N/A 118

Table 1

Some professors using this textbook/collection might decide to eliminate certain modules or chapters.
Some may eliminate the entire Advanced Topics group. Other professors may choose to add additional study
materials. The advantage of this textbook/collection is that it may be adapted by professors to suit the
needs of their students.

Chapter Layout
Each chapter will usually ow from:

1. One or more Connexions modules built for independent delivery.


2. A Connexions Practice module built specically for this textbook/collection.

As you proceed with the Connexions modules that comprise a chapter, you should:

• Complete any tasks/demos that require downloading items.

6 This content is available online at <http://cnx.org/content/m19684/1.12/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>

7
8

• Do any exercises.
• Create 3x5 study cards for all denitions. When this material is used as a textbook for a course the
denitions are to be memorized. Conrm this with your professor.

As you start the Practice module you will usually encounter:

• Learning Objectives
• Memory Building Activities aka MBAs Link  These could consist of any of the following types of
interactive computer activities: ash card, crossword puzzle, seek a word, drag n drop, labeling,
ordering or sorting. When the materials are used as a textbook for a course, it is imperative that
students do a variety of repetitive activities in order to memorize basic course material. Besides, have
fun learning.
• Exercises  In addition to any exercises within the study modules that you completed before the
practice module, there will be at least one exercise for students to complete.
• Miscellaneous Items  These will exist for some of the chapters.
• Lab Assignment  Usually, completed on one's own eorts. Review the instructions/restrictions from
your professor/teacher if using this for a high school or college credit course.
• Problems  The intent of this activity is for students to formulate their own answers. Thus, solutions
to the problems will not be provided. When the materials are used as a textbook for a course, the
professor/teacher may assign students to a "Study Group" or let students form study groups to discuss
their solutions with each other. If you are using this for a high school or college credit course, verify that
you may work as team at solving the problems. This type of approved activity is called "authorized
collusion" and is not a violation of "Academic or Scholastic Dishonesty" rules.

A professor using this textbook/collection/course will most likely have additional lab assignments, quizzes
and exams that would be used in calculating your grade.

Connexions Module Reading List


no
The modules in this textbook/collection have had content reviewed and are believed to be sucient, thus
additional textbook is required. However, some students desire additional references or reading. The
author has used several textbooks over the years for teaching "COSC1436  Programming Fundamentals I"
course at Houston Community College and at the Community College of Qatar. A reading reference list has
been prepared and includes references for the following textbooks:

1. Starting Out with C++ Early Objects, by: Tony Gaddis et. al., 7
th Edition, International Edition,
ISBN: 978-0-13-137714-1
2. Starting Out with C++ Early Objects, by: Tony Gaddis et. al., 6
th Edition, ISBN: 0-321-51238-3
3. Starting Out with C++ Early Objects, by: Tony Gaddis et. al., 5
th Edition, ISBN: 0-321-38348-6
4. Computer Science  A structured Approach using C++, by: Behrouz A. Forouzan et. al., 2
nd Edition,
ISBN: 0-534-37480-8

These textbooks are typically available in the used textbook market at a reasonable price. You may use
any one of the three books. If you acquire one of the above optional traditional textbooks, you may want
to download and store the following le to your storage device (disk drive or ash drive) in an appropriate
folder.
Download from Connexions: Connexions_Module_Reading_List_col10621.pdf
7

Syllabus
The syllabus for a course that is for credit will be provided by your specic course professor. If you are using
this textbook/collection for non-credit as self-study, we have some suggestions:

7 See the le at <http://cnx.org/content/m19684/latest/Connexions_Module_Reading_List_col10621_V2.pdf>

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


9

1. Plan regular study periods


2. Review the three (3) Pre-Chapter Items modules
3. Review the last four (4) modules in the Appendix
4. Proceed with Chapter 1 going through all 24 chapters
5. Do all of the demo programs as you encounter them
6. Memorize all of the terms and denitions
7. Do all lab assignments
8. Prepare answers to all of the problems in the Practice modules
9. At the end of every section, do the Review module

These is no magic way to learn about computer programming other than to immerse yourself into regular
study and study includes more than casual reading. To help you keep track of your study, we have
included a check o list for the textbook/collection.

Check Description # Modules

Pre-Chapter Items 4

Last four Appendix Items 4

Chapters 1 to 5 27

Review Materials for 1 to 5 1

Chapters 6 to 9 17

Review Materials for 6 to 9 1

Chapters 10 to 16 30

Review Materials for 10 to 16 1

Chapters 17 to 21 17

Review Materials for 17 to 21 1

Chapters 22 to 24 11

Review Materials for 22 to 24 1

First three Appendix Items 3

N/A Total Modules 118

Table 2

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


10

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


Sharing/Rating Connexions Materials 8

Historical Rating System


At one time within Connexions there was a ve (5) star rating system provided within each Connexions
module. This feature was not often used and was discontinued.

Sharing Connexions Materials


The ve (5) star rating feature was replaced with several ways for users of Connexions materials to share
with others. Available at the top and bottom of each module or collection are:

• Google's +1
• Facebook's Like
• twitter's Tweet
8 This content is available online at <http://cnx.org/content/m33960/1.2/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>

11
12

Figure 1: Sharing Connexions Materials

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


Chapter 1

1. Introduction to Programming

1.1 Systems Development Life Cycle1


1.1.1 Discussion
The Systems Development Life Cycle is the big picture of creating an information system that handles
The applications usually consist of many programs. An
a major task (referred to as an application).
example would be the Department of Defense supply system, the customer system used at your local bank,
the repair parts inventory system used by car dealerships. There are thousands of applications that use an
information system created just to help solve a business problem.
Another example of an information system would be the "101 Computer Games" software you might buy
at any of several retail stores. This is an entertainment application, that is we are applying the computer
to do a task (entertain you). The software actually consists of many dierent programs (checkers, chess, tic
tac toe, etc.) that were most likely written by several dierent programmers.
Computer professionals that are in charge of creating applications often have the job title of System
Analyst. The major steps in creating an application include the following and start at Planning step.
1 This content is available online at <http://cnx.org/content/m18684/1.6/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>

13
14 CHAPTER 1. 1. INTRODUCTION TO PROGRAMMING

Figure 1.1: Systems Development Life Cycle

During the Design phase the System Analyst will document the inputs, processing and outputs of each
program within the application. During the Implementation phase programmers would be assigned to
write the specic programs using a programming language decided by the System Analyst. Once the system
of programs is tested the new application is installed for people to use. As time goes by, things change and a
specic part or program might need repair. During the Maintenance phase, it goes through a mini planning,
analysis, design and implementation. The programs that need modication are identied and programmers
change or repair those programs. After several years of use, the system usually becomes obsolete. At this
point a major revision of the application is done. Thus the cycle repeats itself.

1.1.2 Denitions
Denition 1.1: system analyst
Computer professional in charge of creating applications.

Denition 1.2: applications


An information system or collection of programs that handles a major task.

Denition 1.3: life cycle


Systems Development Life Cycle: Planning - Analysis - Design - Implementation - Maintenance

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


15

Denition 1.4: implementation


The phase of a Systems Development Life Cycle where the programmers would be assigned to write
specic programs.

1.2 Bloodshed Dev-C++ 5 Compiler/IDE2


1.2.1 Introduction
Microsoft and Borland are the two reputable names within the programming world for compilers. They sell
compiler software for many programming languages. For the C++ programming language, the Microsoft
Visual Studio which includes C++ and Borland C++ Builder are excellent compilers. Often with textbooks
or free via the internet; you can get Microsoft's Visual C++ Express or Borland's Personal Edition version
of a compiler. However, installing either of these compliers can be complex. Microsoft's Visual Studio
compiler often creates a variety of installation problems (such as making sure the operating system and .net
components are current) thus making it dicult for students to install at home. These compliers require
you to build a project to encompass every program. Using a commercially sold compiler that professional
programmers would consider using for project development is ne for professionals but often confusing to
beginners. Eventually, if you are going to become a professional programmer, you will need to become
familiar with the commercially sold compilers.
We suggest that beginning students consider one of the easier to install compiler software packages for use
in a programming fundamentals course. The best option we have found is an open source compiler/IDE
(Integrated Development Environment) named: Bloodshed Dev-C++ 5 compiler/IDE.
Denition 1.5: open source
Group development of source code for software that is made available to the public at no cost.

1.2.2 Bloodshed Dev-C++ 5 compiler/IDE


Advantages: Can be installed on Windows 95/98/NT/2000/XP operating systems. I have it installed on
Windows Vista operating system, thus it can work with slower processors and almost any Windows operating
system. It only requires about 80 MB of storage space (usually enough for the compiler with all of its les
and storage room for several of your programs). It is very easy to install and easy to use. Does not require
the use of a "project"; thus individual source code les can be easily compiled.
Disadvantages: Would not normally be used by professional programmers, but is sucient for a beginning
computer programming course and is a full-featured compiler/IDE.
Unique Advantage: Can be installed and run on a ash drive, thus giving the student the ability to
portability,
work on their lab assignments on any computer that has a USB port. This can give the student
being able to do lab assignments at home, work, library, open lab, classroom, friend's house, etc.

Denition 1.6: portability


The ability to transport software on a ash drive and thus use it on various machines.

1.2.3 Preparation before Installation


1.2.3.1 Creating the Needed Folders and Sub-Folders

You need to get the software and a C++ source code program that has been tested and is error free.
two folders on your hard drive or
You will need about 80MB of storage space. We suggest that you create
ash drive depending on which installation you choose. If on a ash drive create them at the root level of
the drive. If on your home machine, you can use the folder area set up by the operating system for you as a
user. Name them:
2 This content is available online at <http://cnx.org/content/m18785/1.15/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


16 CHAPTER 1. 1. INTRODUCTION TO PROGRAMMING
• Cpp_Software_Download
• Cpp_Source_Code_Files

Within the Cpp_Source_Code_Files folder, create a sub-folder named:

• Compiler_Test

To help you keep les organized, you will want to create other sub-folders for storing source code les. We
suggest you create at least two other sub-folder to be used with Connexions' related modules. Within the
Cpp_Source_Code_Files, create sub-folders named:

• Demo_Programs
• Monitor_Header

Denition 1.7: folder


A named area for storage of documents or other les on a disk drive or ash drive.

Denition 1.8: source code


Any collection of statements or declarations written in some human-readable computer program-
ming language.

1.2.3.2 Getting the Software

The full version of the software is named: Dev-C++ 5.0 beta 9.2 (4.9.9.2) (9.0 MB) with Mingw/GCC
3.4.2 You can either download it from Bloodshed or download the version as of 12/8/2008 that is stored
on the Connexions web site. Store it in the Cpp_Software_Download folder you created. The software is
approximately 9.1 MB and will take several minutes to download if you are using a dial-up modem connection.

tip: The software has not signicantly changed since 2007 and the Connexions version will be
sucient for most users. The Bloodshed link requires some additional navigation to get to the
software download. Thus, because it is signicantly easier, we recommend that you download the
software from the Connections web site.

Link to Bloodshed: http://www.bloodshed.net/dev/devcpp.html


3
Download from Connexions: devcpp-4.9.9.2_setup.exe
4

1.2.3.3 Getting a C++ Source Code File

Listed below is a C++ source code le titled: Compiler_Test.cpp It has been prepared for Connexions web
delivery. Download and store it in the Compiler_Test sub-folder you created. You may need to right click
on the link and select "Save Target As" in order to download the le.
Download from Connexions: Compiler_Test.cpp
5

1.2.4 Installation Instructions for Bloodshed Dev-C++ 5 compiler/IDE


The Version 5 which is well tested (don't let the beta release scare you) and should work on a variety of
machines and various Microsoft Operating systems including Windows 98, Windows 2000, Windows XP and
Windows Vista. Below are installation instructions for installing it on a machine or installing it on a ash
drive. We don't suggest trying to switch between the machine drive and ash drive. If it is installed on
the machine drive and you try installing it on a ash drive, it creates problems and will not work perperly.
Either install it on the ash drive to gain your portability or install it on your machine.

3 http://www.bloodshed.net/dev/devcpp.html
4 See the le at <http://cnx.org/content/m18785/latest/devcpp-4.9.9.2_setup.exe>
5 See the le at <http://cnx.org/content/m18785/latest/Compiler_Test.cpp>

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


17

1.2.4.1 Computer Installation Instructions

1. Navigate to the Cpp_Software_Download folder and run the devcpp-4.9.9.2_setup.exe software


by double cliking on the lename.
2. Use common sense and answer the installation prompts. NOTE THE FOLLOWING TWO ITEMS:
3. When it gets to the "Choose Install Location" use the default software location of: C:\Dev-Cpp\ (or
select the location you want to store the installed program but use the default unless you are familiar
with installing software).
4. When it asks: "Do you want to install Dev C++ for all users on this computer?" answer "Yes".
5. After it installs, it will ask some "rst time conguration" questions. Again, use common sense and
answer the questions. NOTE THE FOLLOWING ITEM:
6. Answer "No" to the retrieve information from header les.
7. It will start your compiler/IDE with a "Tip of the day". We suggest you check the box in the lower
left and select "Close".
8. Close your compiler/IDE by using the normal red "X" box. We want to show you how to start your
compiller normally.
9. You start your compiler software similar to starting any software loaded on your machine ("Start" then
"All Programs" then "Bloodshed Dev-C++" then "Dev-C++").
10. On the menus at the top  Select "File" then "Open project or le" then navigate to where your source
code le (Compiler_Test.cpp) is stored on your hard drive. See the suggested folder name above.
Select the source code le and open it.
11. You should see the source code listing. Press F9 key or select the "Execute" then "Compile & Run"
from the menus at the top. A black screen box should appear and you answer questions appropriately
to run the program. When you are done running your program the black screen box goes away.

1.2.4.2 Flash Drive Installation Instructions

1. Navigate to the Cpp_Software_Download folder and run the devcpp-4.9.9.2_setup.exe software


by double cliking on the lename.
2. Use common sense and answer the installation prompts. NOTE THE FOLLOWING TWO ITEMS:
3. When it gets to the "Choose Install Location" you can see that the default software location of:
C:\Dev-Cpp\ however, it needs to be changed. Change the "Destination Directory" by selecting
C:\Dev-Cpp\ to DriveLetter:\Dev-Cpp\ (where the
changing the default software location from:
DriveLetter is the drive that represents your ash drive).
4. When it asks: "Do you want to install Dev C++ for all users on this computer?" answer "No".
5. After it installs, it will ask some "rst time conguration" questions. Again, use common sense and
answer the questions. NOTE THE FOLLOWING ITEM:
6. Answer "No" to the retrieve information from header les.
7. It will start your compiler/IDE with a "Tip of the day". We suggest you check the box in the lower
left and select "Close".
8. Close your compiler/IDE by using the normal red "X" box. We want to show you how to start your
compiller normally.
9. To start your compiler software you navigate to the "Dev-Cpp" folder on your ash drive and select the
"devcpp.exe" application. NOTE: When using the ash drive you should not try starting the compiler
by double clicking on a C++ source code le. This method works on a machine installation but does
not work on a ash drive installation.
10. On the menus at the top  Select "File" then "Open project or le" then navigate to where your source
code le (Compiler_Test.cpp) is stored on your ash drive. See the suggested folder name above.
Select the source code le and open it.
11. You should see the source code listing. Press F9 key or select the "Execute" then "Compile & Run"
from the menus at the top. A black screen box should appear and you answer questions appropriately
to run the program. When you are done running your program the black screen box goes away.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


18 CHAPTER 1. 1. INTRODUCTION TO PROGRAMMING
1.3 Modularization and C++ Program Layout6
1.3.1 Concept of Modularization
One of the most important concepts of programming is the ability to group some lines of code into a unit
that can be included in our program. The original wording for this was a sub-program. Other names include:
macro, sub-routine, procedure, module and function. We are going to use the term function for that is
what they are called in the two predominant programming languages of today: C++ and Java. Functions
are important because they allow us to take large complicated programs and to divide them into smaller
manageable pieces. Because the function is a smaller piece of the overall program, we can concentrate on
what we want it to do and test it to make sure it works properly. Generally functions fall into two categories:

1. Program Control - Functions used to simply sub divide and control the program. These functions are
unique to the program being written. Other programs may use similar functions maybe even functions
with the same name, but the content of the functions are almost always very dierent.
2. Specic Task - Functions designed to be used with several programs. These functions perform a
specic task and thus are useable in many dierent programs because the other programs also need
to do the specic task. Specic task functions are sometimes referred to as building blocks. Because
they are already coded and tested, we can use them with condence to more eciently write a large
program.

The main program must establish the existence of functions used in that program. Depending on the
programming language, there is a formal way to:

1. dene a function (it's denition or the code it will execute)


2. call a function
3. declare a function (a prototype is a declaration to a complier)

Program Control functions normally do not communicate information to each other but use a common area
for variable storage. Specic Task functions are constructed so that data can be communicated between
the calling program piece (which is usually another function) and the function being called. This ability to
communicate data is what allows us to build a specic task function that may be used in many programs.
The rules for how the data is communicated in and out of a function vary greatly by programming language,
but the concept is the same. The data items passed (or communicated) are called parameters. Thus the
wording: parameter passing. The four data communication options include:

1. no communication in with no communication out


2. some communication in with no communication out
3. some communication in with some communication out
4. no communication in with some communication out

1.3.2 Introduction of Functions within C++


We are going to consider a simple program that might be used for testing a compiler to make sure that it is
installed correctly.

Example 1.1: Compiler_Test.cpp source code

//******************************************************
// Filename: Compiler_Test.cpp
6 This content is available online at <http://cnx.org/content/m18861/1.13/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


19

// Purpose: Average the ages of two people


// Author: Ken Busbee; © Kenneth Leroy Busbee
// Date: Jan 5, 2009
// Comment: Main idea is to be able to
// debug and run a program on your compiler.
//******************************************************

// Headers and Other Technical Items

#include <iostream>
using namespace std;

// Function Prototypes

void pause(void);

// Variables

int age1;
int age2;
double answer;

//******************************************************
// main
//******************************************************

int main(void)
{
// Input
cout  "\nEnter the age of the first person --->: ";
cin  age1;
cout  "\nEnter the age of the second person -->: ";
cin  age2;

// Process
answer = (age1 + age2) / 2.0;

// Output
cout  "\nThe average of their ages is -------->: ";
cout  answer;

pause();
return 0;
}

//******************************************************
// pause
//******************************************************

void pause(void)
{

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


20 CHAPTER 1. 1. INTRODUCTION TO PROGRAMMING
cout  "\n\n";
system("PAUSE");
cout  "\n\n";
return;
}

//******************************************************
// End of Program
//******************************************************

This program has two functions, one from each of our categories. The technical layout of functions are the
same, it is our distinction that creates the two categories based on how a function is being implemented.

1.3.2.1 Program Control Function

The main program piece in C++ program is a special function with the identier name of main. The
special or uniqueness of main as a function is that this is where the program starts executing code and this is
where it usually stops executing code. It is usually the rst function dened in a program and appears after
the area used for includes, other technical items, declaration of prototypes, the listing of global constants
and variables and any other items generally needed by the program. The code to dene the function main
is provided; however, it is not prototyped or usually called like other functions within a program. In this
simple example, there are no other program control functions.

1.3.2.2 Specic Task Function

We often have the need to perform a specic task that might be used in many programs. In the Com-
pile_Test.cpp source code above we have such a task that is used to stop the execution of the code until the
user hits the enter key. The functions name is: pause. This function is not communicating any information
between the calling function and itself, thus the use of the data type void.

Example 1.2: general layout of a function

<return value data type> function identifier name(<data type> <identifier name for input value>)
{
lines of code;

return <value>;
}

There is no semi-colon after the rst line. Semi-colons are used at the end of a statement in C++, but not
on the rst line when dening a function. Functions have a set of braces {} used for identifying a group or
block of statements or lines of code. There are normally several lines of code within a function. Lines of code
containing the instructions end in a semi-colon. Can you identify the denition of the pause function in the
above program example? The pause function denition is after the function main. Though not technically
required, most programs list all functions (program control or specic task) after the function main.
Let's identify the location where the function pause is called. The calling function is the function main
and it towards the end of the function. The line looks like:
pause();
When you call a function you use its identier name and a set of parentheses. You place any data items
you are passing inside the parentheses, and in our example there are none. A semi-colon ends the statement

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


21

or line of code. After our program is compiled and running, the lines of code in the function main are
executed and when it gets to the calling of the pause function, the control of the program moves to the pause
function and starts executing the lines of code in the pause function. When it's done with the lines of code,
it will return to the place in the program that called it (in our example the function main) and continue
with the code in that function.
Once we know how to dene a function and how to call a function, we usually will need to know how to
declare a function to the compiler (called a prototype). Because of normal computer programming industry
standards, programmers usually list the function main rst with other functions dened after it. Then
somewhere in the function main, we will call a function. When we convert our source code program to an
executable version for running on our computer, the rst step of the process is compiling. The compiler
program demands to know what the communication will be between two functions when a function is called.
It will know the communication (what going in and out as parameters) if the function being called has been
dened. But, we have not dened that function yet; it is dened after the function main. To solve this
problem, we show the compiler a prototype of what the function will look like (at least the communication
features of the function) when we dene it.
void pause(void);
This line of code looks exactly like the rst line in our function denition with one important addition
of a semi-colon. Prototypes (or declarations to the compiler of the communications of a function not yet
Summary concept: If you call
dened) are placed near the top of the program before the function main.
a function before it is dened you must prototype it before it is called. Looking at our list of the
three things you do in conjunction with a function in the order that they normally appear in a program,
there is a formal way to:

1. declare a function (a prototype is a communications declaration to a complier)


2. call a function
3. dene a function

1.3.3 C++ Program Layout


From the above example, you can see that 2/3 of the program is the two functions. Most C++ programs
have several items before the function main. As in the example, they often are:

1. Documentation  Most programs have a comment area at the start of the program with a variety
of comments pertinent to the program. Any line starting with two slashes // is a comment and the
compiler software disregards everything from the // to the end of the line.
2. #include<iostream>  This line of code inserts a le into the source code. The le contains necessary
code to be able to do simple input and output.
3. using namespace std  The C++ compiler has an area where it keeps the identier names used in a
program organized and it is called a namespace. There is a namespace created in conjunction with the
iostream le called: std. This line informs the compiler to use the namespace std where the identier
names in the iostream are established.
4. Function prototypes have already been explained.
5. We need some variables (storage areas) for this program to work. They are dened next.

1.3.4 Denitions
Denition 1.9: modularization
The ability to group some lines of code into a unit that can be included in our program.

Denition 1.10: function


What modules are called in the two predominant programming languages of today: C++ and Java.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


22 CHAPTER 1. 1. INTRODUCTION TO PROGRAMMING
Denition 1.11: program control
Functions used to simply sub divide and control the program.

Denition 1.12: specic task


Functions designed to be used with several programs.

Denition 1.13: parameter passing


How the data is communicated in to and out of a function.

Denition 1.14: identier name


The name given by the programmer to identify a function or other program items such as variables.

Denition 1.15: function prototype


A function's communications declaration to a complier.

Denition 1.16: function call


A function's using or invoking of another function.

Denition 1.17: function denition


The code that denes what a function does.

Denition 1.18: braces


Used to identify a block of code in C++.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


23

1.4 Practice 1: Introduction to Programming7


1.4.1 Learning Objectives
With 100% accuracy during a: memory building activity, exercises, lab assignment, problems, or timed
quiz/exam; the student is expected to:

1. Dene the terms on the denitions as listed in the modules associated with this chapter.
2. Install the Bloodshed Dev-C++ 5 compiler
3. Make minor modications to an existing program

1.4.2 Memory Building Activities


Link to: MBA 01
8

1.4.3 Exercises
Exercise 1.4.1 (Solution on p. 26.)
Answer the following statements as either true or false:

1. Beginning programmers participate in all phases of the Systems Development Life Cycle.
2. The Bloodshed Dev-C++ 5 compiler/IDE is the preferred compiler for this text-
book/collection, however any C++ compiler will work.
3. Most compilers can be installed on a ash drive.
4. In addition to function as the name of a sub-program, the computer industry also uses macro,
procedure and module.
5. Generally functions fall into two categories: Program Control and Specic Task.

1.4.4 Miscellaneous Items


None at this time.

1.4.5 Lab Assignment


1.4.5.1 Creating a Folder or Sub-Folder for Chapter 01 Files

Within the Chapter 1 Connexions modules you were given directions on how to install the Bloodshed
Dev-C++ 5 compiler/IDE and to test your installation with the Compiler_Test.cpp source code le. If
you have not done this, return to the Connexions materials and complete this task.
In the compiler installation directions you were asked to make a folder named: Cpp_Source_Code_Files.
All of your lab assignments in this course assume you have that folder on the same drive as your compiler
(either drive C: your hard disk drive, or on a ash drive). If you don't have that folder, go create it now.
Depending on your compiler/IDE, you should decide where to download and store source code les for
processing. Prudence dictates that you create these folders as needed prior to downloading source code les.
A suggested sub-folder for the Bloodshed Dev-C++ 5 compiler/IDE might be named:

• Chapter_01 within the folder named: Cpp_Source_Code_Files

If you have not done so, please create the folder(s) and/or sub-folder(s) as appropriate.

7 This content is available online at <http://cnx.org/content/m22450/1.4/>.


8 See the le at <http://cnx.org/content/m22450/latest/index.html>

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


24 CHAPTER 1. 1. INTRODUCTION TO PROGRAMMING
1.4.5.2 Download the Lab File(s)

Download and store the following le(s) to your storage device in the appropriate folder(s). You may need
to right click on the link and select "Save Target As" in order to download the le.
Download from Connexions: Compiler_Test.cpp
9

1.4.5.3 Detailed Lab Instructions

Read and follow the directions below carefully, and perform the steps in the order listed.

• Navigate to your sub-folder: Chapter_01 and rename the Compiler_Test.cpp source code le to:
Lab_01.cpp
• If you are having problems seeing the le extensions, visit the Show Hide File Extensions instructions
within the Appendix.
• Start your compiler and open the source code le. Carefully make the following modications:

• Change the comments at the top, specically:

• The lename should be: Lab_01.cpp


• Purpose should be: Average the weight of three people
• Remove the next 2 lines of comment talking about the main idea
• Author: put your name and erase my name and copyright
• Date: Put today's date
• Remove the next 3 lines of comment dealing with licensing (don't erase the asterisk line)

note: During the rest of the course you will often use a source code le provided by the instructor
as your starting point for a new lab assignment. Sometimes you will use a source code le that
you have created as your starting point for a new lab assignment. Either way, you should modify
the comments area as appropriate to include at a minimum the four lines of information (lename,
purpose, author and date) as established in this lab assignment.

• We are now going to make simple modications to this program so that it is able to
average the weight of three people. Do the following:

• Within the variables area, change the variable names for age1 and age2 to weight1 and weight2. Add
another variable of integer data type with the identier name of weight3.
• The input area has two prompts and requests for data from the user. They are paired up  a prompt
and getting data from the keyboard. We need to modify the prompt to ask for weight instead of age.
We need to change the variable name from age1 to weight1. Do this for the second pair that prompts
and gets the second data item. Create a third pair that prompts and gets the third data item.
• The process area has only one line of code and we need to make changes that add the weight3 and
divides by 3.0 instead of 2.0. The code should look like this:
• answer = (weight1 + weight2 + weight3) / 3.0;
• The output area needs the text modied from ages to weights.

• Build (compile and run) your program. You have successfully written this program if when it run and
you put in the three weights; it tells you the correct average.

• After you have successfully written this program, if you are taking this course for college credit, follow
the instructions from your professor/instructor for submitting it for grading.

9 See the le at <http://cnx.org/content/m22450/latest/Compiler_Test.cpp>

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


25

1.4.6 Problems
1.4.6.1 Problem 01a  Instructions

List the steps of the Systems Development Life Cycle and indicate which step you are likely to work in as a
new computer professional.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


26 CHAPTER 1. 1. INTRODUCTION TO PROGRAMMING
Solutions to Exercises in Chapter 1
Solutions to Practice 1: Introduction to Programming
Solution to Exercise 1.4.1 (p. 23)
Answers:

1. false
2. true
3. false
4. true
5. true

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


Chapter 2

2. Program Planning & Design

2.1 Program Design1


2.1.1 Topic Introduction
Program Design consists of the steps a programmer should do before they start coding the program in a
specic language. These steps when properly documented will make the completed program easier for other
programmers to maintain in the future. There are three broad areas of activity:

• Understanding the Program


• Using Design Tools to Create a Model
• Develop Test Data

2.1.2 Understanding the Program


If you are working on a project as a one of many programmers, the system analyst may have created a variety
of documentation items that will help you understand what the program is to do. These could include screen
layouts, narrative descriptions, documentation showing the processing steps, etc. If you are not on a project
and you are creating a simple program you might be given only a simple description of the purpose of the
program. Understanding the purpose of a program usually involves understanding it's:

• Inputs
• Processing
• Outputs

This IPO approach works very well for beginning programmers. Sometimes, it might help to visualize the
programming running on the computer. You can imagine what the monitor will look like, what the user
must enter on the keyboard and what processing or manipulations will be done.

2.1.3 Using Design Tools to Create a Model


At rst you will not need a hierarchy chart because your rst programs will not be complex. But as they
grow and become more complex, you will divide your program into several modules (or functions).
The rst modeling tool you will usually learn is pseudocode. You will document the logic or algorithm
of each function in your program. At rst, you will have only one function, and thus your pseudocode will
follow closely the IPO approach above.

1 This content is available online at <http://cnx.org/content/m18686/1.5/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>

27
28 CHAPTER 2. 2. PROGRAM PLANNING & DESIGN
There are several methods or tools for planning the logic of a program. They include: owcharting,
hierarchy or structure charts, pseudocode, HIPO, Nassi-Schneiderman charts, Warnier-Orr diagrams, etc.
Programmers are expected to be able to understand and do owcharting and pseudocode. These methods of
developing the model of a program are usually taught in most computer courses. Several standards exist for
owcharting and pseudocode and most are very similar to each other. However, most companies have their
own documentation standards and styles. Programmers are expected to be able to quickly adapt to any
owcharting or pseudocode standards for the company at which they work. The others methods that are
less universal require some training which is generally provided by the employer that chooses to use them.
Later in your programming career, you will learn about using applications software that helps create an
information system and/or programs. This type of software is called Computer-aided Software Engineering.
Understanding the logic and planning the algorithm on paper before you start to code is very important
concept. Many students develop poor habits and skipping this step is one of them.

2.1.4 Develop Test Data


Test data consists of the user providing some input values and predicting the outputs. This can be quite
easy for a simple program and the test data can be used to check the model to see if it produces the correct
results.

2.1.5 Denitions
Denition 2.1: IPO
Inputs - Processing - Outputs

Denition 2.2: pseudocode


English-like statements used to convey the steps of an algorithm or function.

Denition 2.3: test data


Providing input values and predicting the outputs.

2.2 Pseudocode2
2.2.1 Overview
Pseudocode is one method of designing or planning a program. Pseudo means false, thus pseudocode means
false code. A better translation would be the word fake or imitation. Pseudocode is fake (not the real thing).
It looks like (imitates) real code but it is NOT real code. It uses English statements to describe what a
program is to accomplish. It is fake because no complier exists that will translate the pseudocode to any
machine language. Pseudocode is used for documenting the program or module design (also known as the
algorithm).
The following outline of a simple program illustrates pseudocode. We want to be able to enter the ages
of two people and have the computer calculate their average age and display the answer.

Example 2.1: Outline using Pseudocode

Input
display a message asking the user to enter the first age
get the first age from the keyboard
display a message asking the user to enter the second age
get the second age from the keyboard
2 This content is available online at <http://cnx.org/content/m18648/1.10/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


29

Processing
calculate the answer by adding the two ages together and dividing by two
Output
display the answer on the screen
pause so the user can see the answer

After developing the program design, we use the pseudocode to write code in a language (like Pascal, COBOL,
FORTRAN, "C", " C++", etc.) where you must follow the rules of the language (syntax) in order to code the
logic or algorithm presented in the pseudocode. Pseudocode usually does not include other items produced
during programming design such as identier lists for variables or test data.
There are other methods for planning and documenting the logic for a program. One method is HIPO. It
stands for Hierarchy plus Input Process Output and was developed by IBM in the 1960s. It involved using a
hierarchy (or structure) chart to show the relationship of the sub-routines (or functions) in a program. Each
sub-routine had an IPO piece. Since the above problem/task was simple, we did not need to use multiple
sub-routines, thus we did not produce a hierarchy chart. We did incorporate the IPO part of the concept
for the pseudocode outline.

2.2.2 Denitions
Denition 2.4: pseudo
Means false and includes the concepts of fake or imitation.

2.3 Test Data3


2.3.1 Overview
Test data consists of the user providing some input values and predicting the outputs. This can be quite
easy for a simple program and the test data can be used twice.

1. to check the model to see if it produces the correct results (model checking)
2. to check the coded program to see if it produces the correct results (code checking)

Test data is developed by using the algorithm of the program. This algorithm is usually documented during
the program design with either owcharting or pseudocode. Here is the pseudocode in outline form describing
the inputs, processing and outputs for a program used for painting rectangular buildings.

Example 2.2: Pseudocode using an IPO Outline for Painting a Rectangular Building

Input
display a message asking user for the length of the building
get the length from the keyboard
display a message asking user for the width of the building
get the width from the keyboard
display a message asking user for the height of the building
get the height from the keyboard
display a message asking user for the price per gallon of paint
get the price per gallon of paint from the keyboard
display a message asking user for the sq ft coverage of a gallon of paint
get the sq ft coverage of a gallon of paint from the keyboard
3 This content is available online at <http://cnx.org/content/m18781/1.4/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


30 CHAPTER 2. 2. PROGRAM PLANNING & DESIGN
Processing
calculate the total area of the building by:
multiplying the length by height by 2
then multiply the width by height by 2
then add the two results together
calculate the number of gallons of paint needed by:
dividing the total area by the coverage per gallon
then round up to the next whole gallon
calculate the total cost of the paint by:
multiplying the total gallons needed by the price of one gallon of paint
Output
display the number of gallons needed on the monitor
display the total cost of the paint on the monitor
pause so the user can see the answer

2.3.2 Creating Test Data and Model Checking


Test data is used to verify that the inputs, processing and outputs are working correctly. As test data is
initially developed it can verify that the documented algorithm (pseudocode in the example we are doing)
is correct. It helps us understand and even visualize the inputs, processing and outputs of the program.
Inputs: My building is 100 feet long by 40 feet wide and 10 feet in height and I selected paint costing $28.49
per gallon that will cover 250 square feet per gallon. We should verify that the pseudocode is prompting the
user for this data.
Processing: Using my solar powered hand held calculator, I can calculate (or predict) the total area
would be: (100 x 10 x 2 plus 40 x 10 x 2) or 2,800 sq ft. The total gallons of paint would be: (2800 / 250)
or 11.2 gallons. But rounded up, I would need twelve (12) gallons of paint. The total cost would be: (28.49
times 12) or $341.88. We should verify that the pseudocode is performing the correct calculations.
Output: Only the signicant information (number of gallons to buy and the total cost) are displayed for
the user to see. We should verify that the appropriate information is being displayed.

2.3.3 Testing the Coded Program  Code Checking


The test data can be developed and used to test the algorithm that is documented (in our case our pseu-
docode) during the program design phase. Once the program is code with compiler and linker errors resolved,
the programmer gets to play user and should test the program using the test data developed. When you
run your program, how will you know that it is working properly? Did you properly plan your logic to
accomplish your purpose? Even if your plan was correct, did it get converted correctly (coded) into the
chosen programming language (in our case C++)? The answer (or solution) to all of these questions is our
test data.
By developing test data we are predicting what the results should be, thus we can verify that our
program is working properly. When we run the program we would enter the input values used in our test
data. Hopefully the program will output the predicted values. If not then our problem could be any of the
following:

1. The plan (IPO outline or other item) could be wrong


2. The conversion of the plan to code might be wrong
3. The test data results were calculated wrong

Resolving problems of this nature can be the most dicult problems a programmer encounters. You must
review each of the above to determine where the error is lies. Fix the error and re-test your program.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


31

2.3.4 Denitions
Denition 2.5: model checking
Using test data to check the design model (usually done in pseudocode).

Denition 2.6: code checking


Using test data to check the coded program in a specic language (like C++).

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


32 CHAPTER 2. 2. PROGRAM PLANNING & DESIGN
2.4 Practice 2: Program Planning & Design4
2.4.1 Learning Objectives
With 100% accuracy during a: memory building activity, exercises, lab assignment, problems, or timed
quiz/exam; the student is expected to:

1. Dene the terms on the denitions as listed in the modules associated with this chapter.
2. Create a pseudocode document for a programming problem
3. Create a test data document for a programming problem

2.4.2 Memory Building Activities


Link to: MBA 02
5

2.4.3 Exercises
Exercise 2.4.1 (Solution on p. 35.)
Answer the following statements as either true or false:

1. Coding the program in a language like C++ is the rst task of planning. You plan as you
code.
2. Pseudocode is the only commonly used planning tool.
3. Test data is developed for testing the program once it is code into a language like C++.
4. The word pseudo means false and includes the concepts of fake or imitation.
5. Many programmers pick up the bad habit of not completing the planning step before starting
to code the program.

2.4.4 Miscellaneous Items


None at this time.

2.4.5 Lab Assignment


2.4.5.1 Creating a Folder or Sub-Folder for Chapter 02 Files

Depending on your compiler/IDE, you should decide where to download and store source code les for
processing. Prudence dictates that you create these folders as needed prior to downloading source code les.
A suggested sub-folder for the Bloodshed Dev-C++ 5 compiler/IDE might be named:

• Chapter_02 within the folder named: Cpp_Source_Code_Files

If you have not done so, please create the folder(s) and/or sub-folder(s) as appropriate.

2.4.5.2 Download the Lab File(s)

Download and store the following le(s) to your storage device in the appropriate folder(s). You may need
to right click on the link and select "Save Target As" in order to download the le.
Download from Connexions: Solution_Lab_01_Pseudocode.txt
6
Download from Connexions: Solution_Lab_01_Test_Data.txt
7

4 This content is available online at <http://cnx.org/content/m22453/1.3/>.


5 See the le at <http://cnx.org/content/m22453/latest/index.html>
6 See the le at <http://cnx.org/content/m22453/latest/Solution_Lab_01_Pseudocode.txt>
7 See the le at <http://cnx.org/content/m22453/latest/Solution_Lab_01_Test_Data.txt>

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


33

2.4.5.3 Detailed Lab Instructions

Read and follow the directions below carefully, and perform the steps in the order listed.

• Navigate to your sub-folder: Chapter_02 and print the: Solution_Lab_01_Pseudocode.txt and the:
Solution_Lab_01_Test_Data.txt les. Review the printouts in conjunction with your Lab 01 source
code le. Note: In Lab 01 we gave you step by step directions for modifying the Compiler_Test.cpp
source code le into the Lab_01.cpp source code le. I could have given you the pseudocode and
test data les, but you had not received any instructions about them. Now, after having studied the
Chapter 2 materials, these les should make sense.
• Make copies of the: Solution_Lab_01_Pseudocode.txt and Solution_Lab_01_Test_Data.txt and
rename them: Lab_02_Pseudocode.txt and Lab_02_Test_Data.txt
• Here is the problem. Your local bank has many customers who save their change and periodically bring
it in for deposit. The customers have sorted the coins (pennies, nickels, dimes and quarters  forget
half dollars and dollar coins) and know how many (an integer data type) of each value they have but
have evolved (or their environment has made them lazy). They have lost their ability to do simple
arithmetic. They can't seem to determine the total value of all of the coins without a calculator (or
computer). Write a program to interact with the customers and to determine and report the total
value of their coins.
• No! No! No! We are not going to write a program (create source code) using the C++ programming
language. We are going to design a plan for a program using pseudocode as our model. Additionally,
we need to develop some test data for use in testing our model.
• Start your text editor (Microsoft Notepad. Set the font on Notepad to: Courier 12 font because Courier
uses the same amount of space horizontally for each letter. It will make the information in the les
show as it should be seen. Open your Lab 02 pseudocode text le. Change all items as needed to
be able to solve the above problem. NOTE: You may use any application software that will let you
open, modify and save ASCII text les. You may even use the Bloodshed Dev-C++ 5 compiler/IDE
software to view, modify and save ASCII text les; after all, our source code les are ASCII text les
with a special extension of .cpp
• Open your Lab 02 test data text le. Modify the text le as appropriate. Use your test data and step
through your pseudocode. Does everything seem to work? Have you missed something?
• When you are satised that you have your program plan and test data completed, close your text les.
That's right, I said, "Save and close your text les." Files should be properly closed before being used
by other software and this includes the Operating System software that moves, copies and renames
les.
• After you have successfully written this program, if you are taking this course for college credit, follow
the instructions from your professor/instructor for submitting it for grading.

2.4.6 Problems
2.4.6.1 Problem 02a  Instructions

Create simple IPO pseudocode to solve the following:


Problem: I have a friend who is visiting from Europe and he does not understand exactly how much gas
he is buying for his car. We need to write a program that allows him to enter the gallons of gas and convert
it to liters (metric system). NOTE: One US gallon equals 3.7854 liters.

2.4.6.2 Problem 02b  Instructions

Create test data for the following:


Problem: A major restaurant sends a chef to purchase fruits and vegetables every day. Upon returning
to the store the chef must enter two pieces of data for each item he purchased. The quantity (Example: 2

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


34 CHAPTER 2. 2. PROGRAM PLANNING & DESIGN
cases) and the price he paid (Example: $4.67). The program has a list of 20 items and after the chef enters
the information, the program provides a total for the purchases for that day. You need to prepare test data
for ve (5) items: apples, oranges, bananas, lettuce and tomatoes.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


35

Solutions to Exercises in Chapter 2


Solutions to Practice 2: Program Planning & Design
Solution to Exercise 2.4.1 (p. 32)
Answers:

1. false
2. false
3. false
4. true
5. true

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


36 CHAPTER 2. 2. PROGRAM PLANNING & DESIGN

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


Chapter 3

3. Data & Operators

3.1 Data Types in C++1


3.1.1 General Discussion
Our interactions (inputs and outputs) of a program are treated in many languages as a stream of bytes.
These bytes represent data that can be interpreted as representing values that we understand. Additionally,
within a program we process this data in various ways such as adding them up or sorting them. This data
comes in dierent forms. Examples include: yourname which is a string of characters; your age which is
usually an integer; or the amount of money in your pocket which is usually a value measured in dollars and
cents (something with a fractional part). A major part of understanding how to design and code programs in
centered in understanding the types of data that we want to manipulate and how to manipulate that data.
"A type denes a set of values and a set of operations that can be applied on those values. The set of
values for each type is known as the domain for that type."
2 The four major families of data include:

• Nothing
• Integer
• Floating-point
• Complex

The C++ programming language identies ve data types as standard data types:

• Void
• Boolean
• Character
• Integer
• Floating-point

The standard data types and the complex data types within C++ have a series of attributes, which include:

• C++ Reserved or Key Word


• Domain  the allowed values
• Signage  do they allow negative numbers or only positive numbers
• Meaning  i.e. What do they represent
• Rules of Denition  What special characters indicate the data type
• Size  in terms of the number of bytes of storage used in the memory

1 This content is available online at <http://cnx.org/content/m18653/1.13/>.


2 Behrouz A. Forouzan and Richard F. Gilberg, Computer Science A Structured Approach using C++ Second Edition (United
States of America: Thompson  Brooks/Cole, 2004) 33.
Available for free at Connexions <http://cnx.org/content/col10621/1.22>

37
38 CHAPTER 3. 3. DATA & OPERATORS
• Operations Allowed  i.e. Which operators can I use on the data type

Placing some of the above into a summary table, we get:

Family Data Type Reserved Word Represents Standard Type

Nothing Null or nothing void No data Yes

Integer Boolean bool Logical true and Yes


false

Integer Character char Single characters Yes

Integer Integer int Whole numbers Yes

Floating Point Floating Point oat Fractional num- Yes


bers

Complex String string A sequence (sting No


them along) of
characters

Complex Array N/A A collection of ele- No


ments of the same
data type

Complex Pointer N/A A value that No


points to a loca-
tion (an address)
within the data
area

Table 3.1

The ve standard data types usually exist in most programming languages and act or behave similarly
from language to language. Most courses of study for a programming course or language will explain the
standard data types rst. After they are learned, the complex data types are introduced.
The Boolean, character and integer data types are identied as belonging to the Integer Family. These
data types are all represented by integer numbers and thus act or behave similarly.

3.1.2 Denitions
Denition 3.1: data type
Denes a set of values and a set of operations that can be applied on those values.

Denition 3.2: data type families


1) Nothing 2) Integer 3) Floating-Point 4) Complex

Denition 3.3: domain


The set of allowed values for a data type.

Denition 3.4: integer


A data type representing whole numbers.

Denition 3.5: oating point


A data type representing numbers with fractional parts.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


39

3.2 Identier Names3


3.2.1 Overview
Within programming a variety of items are given descriptive names to make the code more meaningful to
us as humans. These names are called "Identier Names". Constants, variables, type denitions, functions,
etc. when declared or dened are identied by a name. These names follow a set of rules that are imposed
by:

1. the language's technical limitations


2. good programming practices
3. common industry standards for the language

3.2.2 Technical to Language


• Use only allowable characters (for C++ the rst character alphabetic or underscore, can continue with
alphanumeric or underscore)
• Can't use reserved words
• Length limit

These attributes vary from one programming language to another. The allowable characters and reserved
words will be dierent. The length limit refers to how many characters are allowed in an identier name
and often is compiler dependent and may vary from compiler to compiler for the same language. However,
all programming languages have these three technical rules.

3.2.3 Good Programming Techniques


• Meaningful
• Be case consistent

Meaningful identier names make your code easier for another to understand. After all what does "p" mean?
Is it pi, price, pennies, etc. Thus do not use cryptic (look it up in the dictionary) identier names.
Some programming languages treat upper and lower case letters used in identier names as the same.
Thus: pig and Pig are treated as the same identier name. Unknown to you the programmer, the compiler
usually forces all identier names to upper case. Thus: pig and Pig both get changed to PIG. However
not all programming languages act this way. Some will treat upper and lower case letters as being dierent
things. Thus: pig and Pig are two dierent identier names. If you declare it as pig and then reference it in
be
your code later as Pig  you get a compiler error. To avoid the problem altogether, we teach students to
case consistent. Use an identier name only once and spell it (upper and lower case) the same way within
your program.

3.2.4 Industry Rules


ˆ Do not start with underscore (used for technical programming)
ˆ variables in all lower case
ˆ CONSTANTS IN ALL UPPER CASE

These rules are decided by the industry (those who are using the programming language). The above rules
were commonly used within the "C" programming language and have to large degree carried over to C++.

3 This content is available online at <http://cnx.org/content/m18692/1.5/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


40 CHAPTER 3. 3. DATA & OPERATORS
3.2.5 Denitions
Denition 3.6: reserved word
Words that cannot be used by the programmer as identier names because they already have a
specic meaning within the programming language.

3.3 Constants and Variables4


3.3.1 Understanding Constants
Various textbooks describe constants using dierent terminology. Added to the complexity are the explana-
tions from various industry professionals will vary greatly. Let's see if we can clear it up.
A constant is a data item whose value cannot change during the program's execution. Thus, as its name
implies  their value is constant.
A variable is a data item whose value can change during the program's execution. Thus, as its name
implies  their value can vary.
Constants are used in three ways within C++. They are:

1. literal constant
2. dened constant
3. memory constant

A literal constant is a value you type into your program wherever it is needed. Examples include the
constants used for initializing a variable and constants used in lines of code:

Example 3.1: Literal Constants

int age = 21;


char grade = 'A';
float money = 12.34;
bool rich = false;

cout  "\nStudents love computers";


age = 57;

Additionally, we have learned how to recognize the data types of literal constants. Single quotes for char,
double quotes for string, number without a decimal point for integer, number with a decimal point belongs
to the oating-point family, and Boolean can use the reserved words of true or false.
In addition to literal constants, most text books refer to either symbolic constants or named constants
but these two refer to the same concept. A symbolic constant is represented by a name similar to how we
name variables. Let's say it backwards; the identier name is the symbol that represents the data item.
Within C++ identier names have some rules. One of the rules says those names should be meaningful.
Another rule about using ALL CAPS FOR CONSTANTS is an industry rule. There are two ways to create
symbolic or named constants:
#define PI 3.14159
Called a dened constant because it uses a textual substitution method controlled by the compiler
pre-processor command word "dene".
const double PI = 3.14159;
4 This content is available online at <http://cnx.org/content/m18719/1.8/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


41

The second one is called sometimes called constant variable but that name is contradictory all by
itself. How can it be constant and vary at the same time? The better name for the second one is a memory
constant because they have a "specic storage location in memory".

3.3.2 Dening Constants and Variables


In the above examples we see how to dene both variables and constants along with giving them an initial
value. Memory constants must be assigned a value when they are dened. But variables do not have to be
assigned initial values.
int height;
float value_coins;
Variables once dened may be assigned a value within the instructions of the program.
height = 72;
value_coins = 2 * 0.25 + 3 * 0.05;

3.3.3 Denitions
Denition 3.7: constant
A data item whose value cannot change during the program's execution.

Denition 3.8: variable


A data item whose value can change during the program's execution.

3.4 Data Manipulation5


3.4.1 Introduction
Single values by themselves are important; however we need a method of manipulating values (processing
data). Scientists wanted an accurate machine for manipulating values. They wanted a machine to process
numbers or calculate answers (that is compute the answer). Prior to 1950, dictionaries listed the denition of
computers as " humans that do computations". Thus, all of the terminology for describing data manipulation
is math oriented. Additionally, the two fundamental data type families (the integer family and oating-point
family) consist entirely of number values.

3.4.2 Denitions
Denition 3.9: expression
A valid sequence of operand(s) and operator(s) that reduces (or evaluates) to a single value.

Denition 3.10: operator


A language-specic syntactical token (usually a symbol) that causes an action to be taken on one
or more operands.

Denition 3.11: operand


A value that receives the operator's action.

Denition 3.12: precedence


Determines the order in which the operators are allowed to manipulate the operands.

Denition 3.13: associativity


Determines the order in which the operators of the same precedence are allowed to manipulate the
operands.

5 This content is available online at <http://cnx.org/content/m18705/1.6/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


42 CHAPTER 3. 3. DATA & OPERATORS
Denition 3.14: evaluation
The process of applying the operators to the operands and resulting in a single value.

Denition 3.15: parentheses


Change the order of evaluation in an expression. You do what's in the parentheses rst.

3.4.3 An Expression Example with Evaluation


Let's look at an example: 2 + 3 * 4 + 5 is our expression but what does it equal?

1. the symbols of + meaning addition and * meaning multiplication are our operators
2. the values 2, 3, 4 and 5 are our operands
3. precedence says that multiplication is higher than addition
4. thus, we evaluate the 3 * 4 to get 12
5. now we have: 2 + 12 + 5
6. the associativity rules say that addition goes left to right, thus we evaluate the 2 +12 to get 14
7. now we have: 14 + 5
8. nally, we evaluate the 14 + 5 to get 19; which is the value of the expression

Parentheses would change the outcome. (2 + 3) * (4 + 5) evaluates to 45.


Parentheses would change the outcome. (2 + 3) * 4 + 5 evaluates to 25.

3.4.4 Precedence of Operators Chart


Each computer language has some rules that dene precedence and associativity. They often follow rules
we may have already learned. Multiplication and division come before addition and subtraction is a rule we
learned in grade school. This rule still works. The precedence rules vary from one programming language
to another. You should refer to the reference sheet that summarizes the rules for the language that you are
using. It is often called a Precedence of Operators Chart. You should review this chart as needed when
evaluating expressions.
A valid expression consists of operand(s) and operator(s) that are put together properly. Why the (s)?
Some operators are:

1. Unary  that is only have one operand


2. Binary  that is have two operands, one on each side of the operator
3. Trinary  which has two operator symbols that separate three operands

Most operators are binary, that is they require two operands. Within C++ there is only one trinary operator,
the conditional. All of the unary operators are on the left side of the operand, except postx increment and
postx decrement. Some precedence charts indicate of which operators are unary and trinary and thus all
others are binary.

3.5 Assignment Operator6


3.5.1 Discussion
The assignment operator allows us to change the value of a modiable data object (for beginning programmers
this typically means a variable). It is associated with the concept of moving a value into the storage location
(again usually a variable). Within C++ programming language the symbol used is the equal symbol. But
bite your tongue, when you see the = symbol you need to start thinking: assignment. The assignment
operator has two operands. The one to the left of the operator is usually an identier name for a variable.
The one to the right of the operator is a value.

6 This content is available online at <http://cnx.org/content/m18725/1.4/>.

Available for free at Connexions <http://cnx.org/content/col10621/1.22>


Exploring the Variety of Random
Documents with Different Content
CHAPTER X—THIRTY ANGRY MEN
He had been given forty-eight hours! When twenty-four of them had
elapsed, Rock lay in his bunk at the TL, staring at roof beams dim
above his head. The small noises of the night, insect voices, and the
river’s eternal whisper drifted through an open window. In an
opposite corner the two hired men snored. Perhaps to-morrow
something would happen. Perhaps not. Yet Rock could not take easy
refuge behind the idea that Buck Walters’ talk had been a bluff. Fire
burned under that smoke. To-morrow would tell the tale.
Sunrise came and breakfast. Rock set the men at work in a
meadow. The whir of the mower blades droned in the quiet valley.
There were odds and ends of work that kept him busy until ten
o’clock. While he attended to these jobs, he debated with himself
whether to tell Nona Parke about his encounter with Buck. He
concluded to keep it to himself. He wished that he had taken
advantage of Dave Wells’ presence to establish his own identity. Yet
who the devil, he asked himself fretfully, would have expected Buck
Walters to declare open war?
At the next opportunity, he decided, he would be himself and be
done with a dead man’s troubles. It had been altogether too easy to
let people go on thinking he was Doc Martin. But there was no use
worrying Nona Parke with that just now. She wasn’t concerned. If
anything happened to him, she could get other riders. And she was
quite helpless to prevent anything happening. Rock didn’t intend that
anything should happen to him. He would be wary, watchful, his
weapons always handy.
Something took him to the house.
Nona sat on the porch, darning stockings for Betty. She stopped
Rock to mention the need of getting in more work horses, and while
they talked, her eyes, looking past Rock, began to twinkle.
“Well,” she said, “we are about to have a distinguished visitor.
There’s Alice Snell, and she’s certainly burning the earth.”
Rock turned. That range phrase for speed was apt. Alice came
across the flat on a high gallop, her skirt flapping, bareheaded, and
the gold of her hair like a halo in the sun. Her bay horse, when she
jerked him to a stop, was lathered with sweat, his breast spotted
with foam flecks. The girl’s face struck Rock as being stricken with a
terrible fear. She swung down. To Nona Parke she gave no greeting
whatever. Her eyes never left Rock, except for one furtive, backward
glance. And she cried with a hysterical tremble in her voice:
“Buck Walters and Elmer Duffy, with all the boys, are coming to
hang you! For God’s sake, Doc, get away from here before they
come! I heard them talking it over, and I sneaked away from the
ranch. They can’t be far behind me.”
So that was it. Rock’s lip curled. But a vigilance committee from
two big outfits didn’t function without some excuse.
“What are they going to hang me for?” he asked.
Alice Snell put her hands on his arms, her white face turned up to
his in a fever of anxiety.
“They say—they say,” she gulped, “you’re stealing cattle. They
mean to hang you.”
Rock laughed.
“They won’t hang me,” he said lightly. “Thank you, just the same,
for coming to tell me of their kind intentions.”
“Doc, please! There’s a lot of them. Elmer Duffy and his crew as
well as the Maltese Cross riders. You can’t fight that bunch. Get a
horse and ride fast.”
Rock smiled and put Alice Snell’s trembling, clutching hands off his
own. But there was no mirth in that smile, for a squad of horsemen,
a long line of them abreast, had swung around the point of brush, a
quarter of a mile away. Nona Parke stared at the two of them in
blank amazement. Alice didn’t seem to know that she was there. She
had no thought for anything but this man she took for Doc Martin.
But out of one corner of her eye she marked the approaching riders
and began to babble incoherently.
“Take her into the kitchen,” Rock commanded Nona. “Stay in
there. If she’s right, there’ll be a fuss. I can’t run. And neither Buck
Walters nor anybody else is going to hang me.”

He darted into the bunk room. His rifle hung above his bed, and he
took it down. Out of his war bag he snatched two boxes of
cartridges and stuffed them in his trousers pocket. He had on his
belt gun. Both six-shooter and carbine were the same caliber. Then
he went back to the door. The line of riders drew close, bobbing in
unison, a long row. The sun made their silver ornaments gleam—
white hats and black, red horses, blacks, bays, dun, and spotted—on
they came, a brave sight. Thirty riders to confront a single
miscreant. Rock wondered if Charlie Shaw rode with them, and if he
would stand by, unprotesting. But he had brief time to speculate.
The two girls were still on the porch. Nona had her arms about Alice,
steadying her, encouraging her, and Alice was sobbing in a panic of
grief and fear.
“For Heaven’s sake get her and yourself inside,” Rock snapped.
“This is not going to be a Sunday-school picnic. Buck Walters warned
me in Fort Benton that he’d get me inside of forty-eight hours. He’s
going to make it good, if he can. This is nothing for you to be mixed
up in.”
“This is as good a place as any for her and me,” Nona declared.
“This is my ranch. They won’t dare!”
“Dare!” Rock grinned. “The man leading that bunch will dare
anything. But I aim to fool him, if I get a chance to declare myself.”
“And if you don’t, they won’t stop to listen to anything,” she
declared. Her eyes were full of questions.
“From the bunk room,” Rock said softly. “I will give them a good
run for their money. The walls are thick, and I have plenty of
ammunition.”
The eyeballs of horses and men were visible now, faces staring
from under hat brims. Rock could see Seventy Seven riders he had
worked with on trail. Charlie Shaw rode beside Buck Walters and
Elmer Duffy. They slowed to a trot, then to a walk and drew up
before the house. Rock moved back a little in the doorway, his rifle
in the crook of his arm. He stood in plain sight; but if a hand moved
toward a weapon he would be under cover before it could be drawn,
or fired, at least.
Walters, Duffy and Charlie Shaw dismounted. Buck Walters looked
at Alice Snell, her face hidden yet against Nona’s shoulder. His own
face remained impassive, but his eyes burned. And Rock got in the
first word.
“Miss Snell, not liking the idea of coldblooded murder to satisfy a
personal grudge, rode up a little ahead of you-all to tell us you
aimed to hang Doc Martin. If——”
“If that is true,” Nona Parke’s voice cut like a knife across his
sentence, “you are a pack of dirty cowards—and you are too late.”
She thrust the weeping girl away from her and faced them, with
her head up, her gray eyes wide with scorn.
“Is it true?” she demanded. “What do you want here, all of you
with rifles, as if you were going to war?”
“We want him,” Buck Walters pointed at Rock. “And we will take
him, dead or alive. He is a thief.”
“That,” said Nona without a moment’s hesitation, “is a lie.”

Duffy, Walters, and Charlie Shaw had stepped up on the porch. They
stood within eight feet of Rock, apparently secure in the belief that
under thirty pairs of watchful eyes he could neither escape nor
menace them.
“You two girls better go inside,” Duffy said. “Leave us men handle
this thing. They ain’t no room for argument, I guess.”
“Guess again, Elmer,” Rock said quietly. “There is lots of room for
argument. In the first place, I am not Doc Martin. I can prove that
by you, Duffy, and by Buck Walters himself.”
“What the hell are you givin’ us?” Walters growled.
“It is quite true,” Nona declared. “Doc Martin is dead. He was shot
from ambush ten days ago. This man, no matter how much he may
look like Doc, is not Doc.”
“I told you that, but you wouldn’t listen, you were so hell-bent to
hang somebody,” declared Charlie Shaw, opening his mouth for the
first time and addressing Buck Walters. “Now it can be proved right
here, unless you got to hang somebody for your own personal
satisfaction.”
“Listen, all of you!” Rock put in. “I have told you, and Miss Parke
has told you, I am not Doc Martin. Do you want to listen to proof, or
do you want it proved to you after a bunch of men have gone to hell
in a fog of powder smoke? Because, if you don’t want to listen to
reason, there will be a lot of shooting before there is any hanging.
And I will get you, Mr. Buck Walters, first crack, in spite of all your
men. Just think that over.”
Charlie Shaw winked at Rock, then took two quick steps to the
doorway and slid through. Walters’ right hand moved ever so little,
suggestively and involuntarily, and the muzzle of Rock’s carbine
pointed straight at his breast.
“Just one move,” said Rock, “one more little move like that, Buck,
and the Maltese Cross will be shy your services for good. I will give
you leave to hang me or shoot me, if you can, but this crowd is
going to hear who I am before the ball opens. I am going to keep
this gun right on your middle. If I feel anything or hear anything, I
pull trigger. If one of your men should pot me, I can still kill you,
even if I were dead on my feet. Now, I tell you again I am not Doc
Martin. I came to this ranch the day he was killed—murdered, as a
matter of fact. I helped to bury him. His riding gear and all his stuff
is here in the house.”
The riders edged their horses nearer and craned their necks. At
best, destroying a thief was an unpleasant task even for honest men
who despised stock thieves with the contempt such a thief inspired
on the range. Every word uttered on that porch carried distinctly to
their ears. They were not fools. They knew, and Rock banked on
that knowledge, that, whether the man in the doorway was Doc
Martin or not, he had the drop on Buck Walters, and the chances
were a hundred to one he would kill not only Walters but several of
them before they got him. Perhaps too late they realized the tactical
error of letting Charlie Shaw get inside. He was a TL man. Right or
wrong, if there was a fight, Shaw would fight against them. They
would have been confirmed in that supposition if they could have
looked behind Rock. That young man’s heart warmed at the boy’s
quick wit and unhesitating loyalty. A little behind him Charlie
whispered:
“Stand pat. I’ll back any play you make. I got two guns on me.”
Elmer Duffy stared at Rock. He glanced sidewise at Buck Walters,
then back to the man in the door.
“If you ain’t Doc Martin,” he said at last, “there’s only one other
man you could be.”
“Hell and damnation!” Walters burst out. “Who else could he be?
Are we goin’ to be old women and let him bluff us out with a fairy
story?”
“We got plenty of time, Buck,” Elmer Duffy reminded him. “He
can’t get away. We don’t want to get off on the wrong foot. Young
Shaw did tell us this before we started.”
“Rats!” Rock laughed. “You sure don’t want to be convinced, do
you, Buck? You surely want to see Doc Martin dance on a rope end.
Maybe you’d just as soon hang me, even if I’m not Doc. You
recollect what Dave Wells named me in Fort Benton, night before
last, don’t you? Well, you have Elmer Duffy say who he thinks I
might be if I’m not Doc.”
“If Doc Martin is dead an’ buried,” Duffy said, “there’s only one
man you can be.”
“You are right,” Rock said. “I will bet you a new hat, Walters, that
Elmer Duffy names me what Dave Wells called me in Benton. I can
see half a dozen riders in this crowd I worked on trail with, until we
came to Clark’s Ford in Nebraska. If you want to be dead sure,
Elmer, there is a sorrel horse with two white hind feet and a big star
on his forehead, branded JB, and a black, branded a Bleeding Heart,
grazing in the pasture back of the barn. And I could tell you more
that only one man could know, Elmer. Tell Buck Walters who I am.”
“You’re Rock Holloway,” Duffy muttered.
“Bull’s-eye!” Rock said. “I have been in Montana less than three
weeks. It seems a plumb exciting place. Are you satisfied, Buck? Are
you still eager to hang me under the impression that I’m Doc
Martin? Do you want to see his saddle, with bloodstains on it, where
somebody—who also wanted to see him dead—shot him, while he
rode along the river bottoms? Maybe you’d like to dig up his body,
where he’s buried over by those poplars?”
“What is the use of carrying this on any longer?” Nona demanded.
“I don’t believe Doc did what Alice says you claim he did. I don’t
believe he was a thief. But, whether he was or was not, he is dead.
This man is what he says he is. He came here the day Doc was
killed. He told me his name was Rock Holloway. I hired him. That is
all there is to it.”
“Isn’t that what Dave Wells called me?” Rock said to Walters. “Are
you satisfied?”
“You denied it,” Walters said. “When he spoke to you, you used
me to prove you were Doc Martin.”
“A man can have a joke with his friends, if he likes. It isn’t against
any law that I know of. He probably told you I joined his outfit on
the Yellowstone last summer and worked for him all winter.”
“I don’t recollect him mentionin’ it,” Walters replied. “Why have
you passed yourself off for Doc Martin, anyway?”
“Shucks!” Rock said. “Everybody just naturally insisted on taking
me for Doc. Miss Parke knew my name. I explained myself to Charlie
Shaw as soon as I had a chance. I didn’t care much, one way or the
other. I didn’t know anybody in this neck of the woods, barring the
Seventy Seven. I fooled Elmer Duffy purposely, the first time I saw
him, because I was kinda interested in trying to find out who killed
Doc Martin, seeing I looked so much like him and was taking his
place as a TL rider. Are you satisfied, or is there still something you’d
like to know about?”
“Yes, I can see there’s been a mistake,” Walters said in a different
tone. “You can’t blame us. We got it straight that Martin was
standing in with some pretty bald-faced stealing. We’ve cleaned out
his partners. I guess this settles it as far as you’re concerned. I’ll
have to take Elmer’s word for it. He ought to know you, seein’ you
killed his brother.”
It seemed to Rock that Walters raised his voice a trifle, and that
he managed to impart a sneer into those words. Every man could
hear. It seemed to Rock like a deliberate taunt, a barb purposely
planted to rankle in Duffy’s skin. For a second there was silence.
Elmer Duffy’s Adam’s apple slid nervously up and down his lean
throat. His face flushed. Rock read the signs for himself. A few
spiteful reminders like that, and Duffy would feel that he had to go
gunning for his brother’s slayer. Buck Walters broke that strained
hush. He lifted his hat to Nona.
“I’m sorry if this has been disagreeable,” he said politely. “But
those Burris thieves incriminated your man Martin. He has been in
with them on their rustling. We’ve lost a lot of stock. Maybe they
didn’t overlook you. It’s as well Doc Martin has cashed in. We would
certainly have hung him to the nearest cottonwood. We don’t reckon
there’ll be any more trouble. I hope you don’t hold grudges,” he
said, turning to Rock. “In our place you’d do the same. Nobody told
us what happened to Martin. You passed for him. We got to protect
our range. There’s only one way to deal with rustlers.”
He turned to his men with a wave of his hand.
“All right, boys,” he said. “You’ve heard the whole show, and we’re
saved a nasty job. Ride on. We’ll catch up with you.”
Elmer Duffy muttered something, stepped down off the porch, and
swung into his saddle, without a word or a look at Rock. Buck
Walters stepped over beside Alice. She had listened, wide-eyed and
open-mouthed. Now she shrank away from Buck.
“Come on home with us, Al,” he said coaxingly.
“Go home with you!” Alice Snell shrilled. “I’ll never go on that
ranch again till you’re off it for good, you blackhearted beast! If Doc
Martin was murdered, I know who did it and why. I hate you—I hate
you!”
“You’re all worked up,” Walters said diffidently. “You’ll be sorry for
saying such a thing about me when you cool off. I didn’t kill Doc
Martin, although he had it coming. A man who steals can’t flourish
on any range I have charge of.”
“Doc Martin never stole anything in his life,” the girl cried. “He was
a better man than you, any day. You were afraid of him,” she raved.
“I know. You hated him because I loved him, and he loved me. Get
away from me, you—you toad!”
Walters’ face flamed. He shot a quick sidewise look at Nona and
Rock Holloway. But he was cool and patient.
“Hysterics,” he said to Nona. “I guess I’ll have to leave her to you,
Miss Parke. See she gets home, will you? Sorry about all this fuss.
Couldn’t be helped, the way things stood.”
Rock said nothing. He had declared himself. This was a matter
between these others, interesting, dramatic, and with hints of
passionate conflict. Rock knew Nona Parke’s side of it. What she had
told him about Doc Martin was fresh in his mind. And there was
Martin’s attitude and actions toward Elmer Duffy. She, like himself,
stood silent, while Alice leaned against the log wall and lashed at her
foreman, her breast heaving, a fury blazing in her pansy-blue eyes.
Walters stepped off the porch and mounted his horse. The riders
were crossing the flat at a walk. Buck lifted his hat to Nona, flung
“So long, boys!” over his shoulder to Rock and Charlie Shaw, and
loped away after his men.
A very cool hand, Rock reflected. Smooth and dangerous. He had
denied that Dave Wells mentioned anything. Rock felt that to be a
lie. It was simpler now that he had established his real identity. But
he wasn’t done with Buck Walters yet. No! Rock couldn’t quite say
why he had that conviction; but he had it very clear in his mind.
CHAPTER XI—RIDERS ON A RISE
“Is the excitement all over?” Charlie Shaw asked, grinning. “Guess
I’ll go put my caballo in the barn. I’ll go back an’ cut my string this
afternoon.”
“Round-up over?” Nona asked.
She had put one arm protectingly about Alice Snell. That disturbed
young woman, her tawny hair in a tangle, her cheeks tear stained,
stared at Rock. Her eyes expressed complete incredulity, surprise
and a strange blend of grief and wonder.
Charlie nodded. “Glad, too,” he said. “Hope you don’t send me
with that outfit this fall.”
“Some one will have to go,” Nona said dispiritedly.
“Oh, well!” Charlie shrugged his shoulders and took his horse
away to the stable. Nona led Alice inside. Rock stood his rifle against
the wall and sat down on the porch steps to roll a smoke. He found
the fingers that sifted tobacco into the paper somewhat tremulous.
Odd that a man could face a situation like that with cold
determination and find himself shaky when it was all over. Rock
smiled and blew smoke into the still air. He could see the teams
plodding in the hayfield. The whir of the mower blades mingled with
the watery murmur of the river. A foraging bee hummed in a bluster
of flowers by his feet. Except for these small sounds, the hush of the
plains lay like a blanket, a void in which men and the passions of
men were inconsequential, little worrying organisms agitated briefly
over small matters, like flies on the Great Wall of China.
He sat there a long time. Charlie came back and went into the
bunk room. Rock saw him stretch out on a bed. Good kid—loyal to
his friends and his outfit. What a mess there would have been if a
fight had started. Like the Alamo. Two of them intrenched behind log
walls, and thirty angry men in the open, spitting lead. Alice Snell
must certainly have thought a lot of Doc Martin. Rock could see the
look on Buck Walters’ face when she flung her scornful epithets in
his face. Funny about Doc and Nona Parke and Elmer Duffy. Not so
funny, either. Hearts were caught on the rebound. Alice Snell was
worth a second look. Passionate, willful, beautiful. Her fingers had
clutched his arms with a frenzy of possession, when she pleaded
with him to get away from danger. She was certainly capable of
loving.
Nona came out. She, too, sat down on the edge of the porch near
him. She stared at the haymakers, off down the river, where that
hanging squad had departed, up at the banks where the plains
pitched sharp to the valley floor.
“Isn’t it peaceful?” she said absently.
“Yes, by comparison. Sweet Alice calm her troubled soul?”
“How can you joke about it? I made her lie down. She’s in a
terrible state—all on edge. I didn’t think she was like that.”
“Like what?” Rock inquired.
“I didn’t think she had it in her to feel so much about anything.
She’s heartbroken,” Nona said. “Doc, it appears, meant a lot to her.
She just babbles about him.”
“Everybody seems to know that but you,” Rock told her.
“I don’t understand it,” Nona said slowly. “Doc—oh, well, I guess
he made love to her, same as he did to me.”
“You blame him?” Rock inquired. “She’s attractive. Offhand, I’d say
she loved this rider of yours a heap. You didn’t have any use for him
except in his capacity as a cowpuncher. Sometimes, I’ve noticed, a
man craves affection. If he can’t find it one place he’ll look
elsewhere. Maybe he was in love with you both. You’re funny,
anyhow. You didn’t want him, yourself. But it seems to jar you
because he consoled himself with another girl.”
“It isn’t that,” she replied in a bewildered sort of fashion. “Why
should he lie to me? Why should he quarrel with Elmer Duffy about
me—make an issue of me—if—if—”
“I don’t know. I do know that I may have a man-size quarrel with
Elmer, myself, now, if Buck Walters makes a few more public cracks
about my run-in with Mark. Elmer’s apt to brood over that, and I’m
handy if he concludes it’s up to him to get action over a grievance.
And it’s likely he will.”
“What’ll you do, if he does?” she said anxiously.
“Oh, take it as it comes. There’s something fishy to me about all
this upheaval. Of course I can savvy why Buck Walters wanted to
get your man, Doc. Alice would be reason enough. Buck’s face gave
him away. But I somehow don’t believe that’s the whole answer.
Perhaps both Elmer and Buck are such honest, God-fearing
cattlemen that the very idea of rustling would make them froth at
the mouth simultaneously. But I don’t know.”
“I don’t believe for a single instant that Doc Martin had anything
to do with any rustling whatever,” Nona declared. “I don’t care what
these Burrises said, or anybody.”
“I’m not an awful lot interested in that, now,” Rock remarked
thoughtfully. “It would appear from the way these fellows were
ready to act that there has been rustling. Duffy wouldn’t back a play
like that just to satisfy either his own or Buck Walters’ grudge.
Between the Seventy Seven and the Maltese Cross, ranging around
forty thousand cattle, a few rustled calves by the Goosebill don’t cut
so much figure, except as an excuse for action. No; ‘there’s more in
this than meets the eye,’ as Shakespeare or some other wise gazabo
said once. You have lost calves, yourself.”
“Yes, I know I have, and I can’t afford to. I certainly hate a thief.”
“So do I,” Rock murmured. “Still, I don’t hate you.”
“Me?” she uttered in astonishment. Her head went up imperiously.
“What do you mean?”
“You steal hearts.” Rock said calmly. “You admitted it. You told me
you did, only, of course, you said you didn’t mean to.”

The blood leaped to her cheeks. It was the first time he saw her
momentarily at a loss for words, embarrassed by an imputation.
“It worries me a little,” Rock continued meditatively. “You may
steal mine. Of course, you don’t intend to. You hate to do it, as the
fellow said when he took the town marshal’s gun away from him.
But, on the other hand, you don’t care a boot if you find you’ve got
the darned thing. You’re immune. And mine is an innocent,
inexperienced sort of a heart. It’s useful to me. I’d be mighty
uncomfortable without it. Maybe I’d better pull out while the going is
good.”
“You want to quit now?” she asked. “There won’t be any more
trouble, I think,” she said stiffly. “And I’m just getting used to you. I
hate strange men around. Can’t you think of me as your boss
instead of as a woman? Oh, dear, it’s always like this!”
Her distress was so comical, yet so genuine, that Rock laughed
out loud.
“Good Lord, Nona—everybody calls you Nona, so it comes natural
—I’m the world’s crudest josher, I guess,” he declared. “Say, you
couldn’t drive me off this range now. I promised you, didn’t I, that if
my admiration for you did get powerful strong I wouldn’t annoy you
with it? Don’t you give me credit for fully intending to keep my
word?”
Nona smiled frankly at him and with him.
“You like to tease, don’t you?” she said simply. “You aren’t half so
serious as you look and act.”
“Sometimes I’m even more so,” he drawled lightly.
“You were serious enough a while ago,” she said. Her next words
startled Rock, they were so closely akin to what had been running in
his mind not long before. “If Elmer hadn’t known you, there would
have been a grand battle here. You and Charlie in the bunk house. I
would probably have bought into it from one of the kitchen windows.
I have dad’s old rifle, and I can shoot with it probably as straight as
most men. They wouldn’t have won much from us. Buck Walters and
his cowboys, I don’t think.”
“What makes you think Charlie would have backed me up?” he
asked curiously.
“He did, didn’t he?” she asked. “I know that boy.”
“Weren’t you scared?”
“Of course I was scared,” she admitted. “But that didn’t paralyze
me. It never does. Do you think I’d stand and wring my hands, while
a man was fighting for his life?”
“I see,” Rock nodded. “Sort of united we stand, eh?”
“Well, neither Buck Walters nor anybody else will ever take a man
out of my house and hang him to a cottonwood tree if I can stop it,”
she said hotly. “There is law in this Territory, if it is not very much in
evidence. They don’t have to take it in their own hands in that brutal
way.”
“No,” Rock agreed. “And when they do, there is a reason. I am
rather curious about the real reason. As a matter of fact, speaking of
law, I heard something in Benton which may be news to you. Buck
Walters must have known about it, too, which makes his move seem
all the more hasty. They have organized county machinery. There is
to be an election in about a month for a judge of the superior court,
a sheriff, a treasurer, a clerk, and a board of county commissioners.
There will be no good excuse for Judge Lynch after that.”
“I’m glad,” the girl said seriously. “It’s time we were getting
civilized.”
Rock laughed.
“It will take more than a set of duly elected county officers to
civilize this country the way you mean. Texas is well civilized in that
way, but it is still not so tame that bad men eat out of an officer’s
hand. Organized law isn’t always a guarantee of peace in a country
where it’s a hundred miles between ranches, sometimes. As often as
not, it’s some peaceful citizen instead of a sheriff that unlimbers his
gun to pacify the bad actor. Ten or fifteen years from now—— Oh,
well, what’s on the program as soon as Charlie gets home with his
string?”
“We’ll bring in and brand what few calves still have to be marked,”
she said. “Then I wonder if you’d mind haying for two or three
weeks. Charlie takes a whirl at it for me.”
“I’d do pretty much anything for you because you’re a good game
sport,” Rock said quite casually. “I’m not too proud to shovel hay. I
may have to do it for myself some time. I reckon I have to earn my
wages.”
An odd twinkle showed in Nona’s gray eyes.
“And perhaps you’ll be able to console Alice. She says she will
never go back to the Maltese Cross while Buck Walters runs it.”
“She didn’t have to go there in the first place,” Rock said. “She is
her own mistress, and she has a home in Texas.”
“Well, she’s going to stay here with me for a while,” Nona said,
“until she makes up her mind what to do. So you and Charlie better
be nice to her.”
“Oh, I see,” Rock said. But somehow he didn’t feel comfortable
about that. He wasn’t sure that he cared to be thrown too much in
the company of this yellow-haired girl with the pansy-blue eyes and
the come-hither smile lurking always about her mouth. He had no
intention of stepping into Doc Martin’s shoes a second time.
“I expect I’d better get some dinner on,” Nona said finally. “After
dinner you’d better go with Charlie when he heads for the Maltese
Cross and have him show you where those work horses run. We’ll
need them for this haying business.”
Rock went into the bunk room when Nona departed to cook.
Charlie Shaw’s long form was still draped on a bunk, but he was
merely resting.
“Gosh, I’ll get caught up on sleep when I get home,” he grumbled.
“The man who rides with the Maltese Cross don’t need a bed. He’d
just as well trade it off for a lantern, so he could see to catch his
saddle horse before daylight.”
“We’re going to be hay diggers for a spell, you and me,” Rock
informed him.
“Don’t hurt my feelin’s.” Charlie yawned. “Have a good bunk to
sleep in an’ fancy home grub. Make up for all these hardships in the
winter. Nothin’ to do then but play crib with Nona and take a ride to
town once in a while. Say, there was pretty near something to clean
up around here, wasn’t there? All will be peaceful along the Potomac
now, I guess. Buck was hell-bent to string Doc to a cottonwood
bough. They cleaned up the Burrises last night, so the boys said.”
“Was the Seventy Seven in on that?” Rock inquired.
“No; not even the whole Maltese Cross bunch. Just Buck and a
few of his pets—the hardest nuts in the outfit.”
“Then their word was all that was plastered on Doc. No wonder
Elmer Duffy wasn’t overly eager about the job,” Rock commented.
“Just Buck’s word, so far as I know,” the boy drawled. He turned
on his side and eyed Rock attentively. “The other fellows just
grunted.”
“Yet the whole of two outfits came along to get Doc Martin. And
Elmer took Buck’s word for it.”
“Elmer didn’t love Doc exactly, no more than Buck did,” Charlie
said. “An’ I guess Elmer won’t love you none, by the look of him
when Buck made that crack about you gettin’ his brother. So you’re
the feller that put Mark Duffy’s light out, eh? I was in the Odeon
myself, once, first summer it opened. Some joint. One of the
Seventy Seven men told me about ‘Big’ Duffy’s downfall. But I’d
forgotten your name. He told me. I guess you don’t need to worry
about any of these bad actors troublin’ you much.”
He stared at Rock with a trace of admiration.
“I don’t know, Charlie,” Rock answered. “I can’t help thinking
there was more in this than just jealousy over women, or a few
stolen calves. And I have a hunch you could give me an idea what
the real reason was for Buck being so dead set to get Doc Martin out
of the way.”
“Forget it,” Charlie counseled. “You’re a kind of a mind reader. But
Doc’s dead. Let his troubles stay buried with him. I’d go all the way
with Doc if he was alive and in trouble. He was a white man. I think
myself that this talk about the Burris boys sayin’ Doc was in with
them is pure bunk. But it ain’t our funeral now. Forget it. Buck’s wise
enough to leave sleepin’ dogs lie—when they’re dead. Our job is to
look out for ourselves an’ the TL an’ let the Seventy Seven an’
Maltese Cross skin their own cats.”

Farther Charlie would not go. Nor did Rock try pressing. The boy
knew something. Rock suspected it was something he would like to
know. But Charlie would not tell, and doubtless he had what seemed
to him cogent reasons. Rock conceded that the wisdom of this youth
might be sound, so he let it drop. He lay in a bunk opposite to
Charlie. They smoked and chatted until the hay diggers stabled their
horses for noon, and the half-breed girl called them to dinner.
After that Rock set out with Charlie Shaw to gather in a few work
horses ranging by some springs over toward the Maltese Cross. The
river made a bend toward the south, away below the Parke Ranch.
So they cut across the bench.
Five miles out from home, Charlie, glancing back over his
shoulder, spotted a couple of riders on a rise less than a mile behind
them.
“Funny we didn’t see them,” he remarked. “Musta been in some
low ground somewhere.”
They saw the horsemen sit motionless for half a minute or so,
then drop out of sight in a hollow. A mile farther along Charlie
pointed out the location of the spring, and they parted. Rock jogged
along, keeping to high ground and looking for small bands of horses.
A half circle of the springs brought him on the bunch he wanted. A
short, sharp dash cut seven or eight TL horses off from a band of
broom-tail mares and colts, and he headed them homeward,
thundering down a long, gentle slope toward the river. The work
horses knew the way better than he, for they knew where they were
headed, as mountain cattle know where the roundup grounds lie on
the flat. They ran the bench for two miles and dropped into a swale
that deepened and narrowed to a ravine scarred by spring torrents.
Water holes dotted the dry course of its bed. Small flats spread here
and there. Willows grew in clumps. Patches of high service-berry
brush made thickets.
The sleek brutes ahead of him settled to a sedate trot. Rock
jogged along at their heels, whistling.
Something that felt like the sting of a giant bee struck him on the
head. His horse went down under him, as if pole-axed in midstride,
throwing Rock clear. And, as he fell, he saw two wisps of powder
smoke, blue on the edge of a thicket. His ear had heard two shots,
so close together that they were like one.
He wasn’t hurt. A heavy mat of grass on turf softened the shock
of his fall. He felt no wound beyond that sharp sting on his scalp. His
wits worked as usual. He lay quite still where he fell, his eyes on the
place where the smoke drifted lazily. His gun was in his hand, and he
was searching for movement, although he lay like a man dead. He
could hear the rasping death rattle in his horse’s nostrils. The beast
sprawled on its side a few feet away, a convenient bulwark if he
should need one. He noted thankfully that it lay left side up, the
carbine scabbarded under its stirrup leather unharmed. The
varnished stock pointed toward him invitingly. But he dared make no
move toward it as yet.

Inert as a log, both hands clasped on the butt of his Colt, Rock
waited for the ambush to show. He depended on that. They would
want to be sure. Presently his stratagem and patience were
rewarded. A hatless head took form in the edge of the brush a
matter of thirty yards distant. Still Rock waited. Another face joined
the second. After a time one extended a hand. Rock could see the
gun muzzle trained on his prone body, as his own eye lined the
foresight on a spot slightly below that extended arm.
Rock fired. That lurking figure in the brush must have pulled
trigger in the same breath, for a bullet plowed dirt in the region of
Rock’s breast. But the man spun and staggered clear of the brush,
waving his arms, reeling. He was a fair mark now, and Rock fired
again.
The other had vanished. Rock lay waiting. He was in the open,
true, and the second man secure in tall thickets. But all about him
stood heavy grass. He knew that very little of his body was visible,
so long as he did not move.
“One bird in the hand and another in the brush,” he exulted.
Crimson trickled in a slow stream into one eye and spilled over his
cheek. He wiped it away. That first shot had grazed his scalp. That
troubled him very little. That second assassin, still lurking in the
thicket, troubled him much more. And at that instant he heard the
quick drum of hoofs.
Rock knew precisely how far that thicket of berry brush extended.
Their saddle horses would be tied in that. Whether the second man
was scared, or merely acting on the prudent theory that he who
shoots and rides away will live to shoot another day, did not matter
to Rock. He wanted them both. He leaped for his carbine, snatched
it, and ran for the brush. One downward glance, as he passed,
showed him a dead man. The next second he was in the thicket. A
few quick strides took him out the other side.
Straight for the next brush patch, over an intervening grass flat of
two hundred yards, a sorrel horse was stretching like a hound in full
flight, his rider crouched in the saddle, looking back over one
shoulder.
Rock dropped flat on his stomach, propped his elbows, and drew a
bead. He hated to kill a horse, but he wanted that man alive, if he
could get him. The sorrel ran at a slight angle. Rock could just see
his shoulder. He held for that, low on the body, just ahead of the
cinch. He was a fair shot with a six-shooter, deadly with a rifle. And
he was neither hurried nor excited. His forefinger tightened as
deliberately as if he had been shooting at a tomato can.
The horse went down, as if his feet had been snatched out from
under him in mid-air, which was precisely what Rock had banked on.
His rider, sitting loose, was catapulted in an arc. His body struck the
earth with a thud. And Rock ran for his man. There was no craft in
that sprawl. The fall had stunned him as effectually as if he had
been slung from a train at thirty miles an hour.
He wasn’t unconscious, merely dazed. But Rock had a gun in his
face before he got control of his senses. And, after disarming him,
Rock did exactly what he would have done with a wild steer he
wanted to keep harmless. He hog-tied him, hands behind his back,
one foot drawn tight up to the lashed wrists, with a hair macarte off
the dead horse.
Incidentally, Rock examined the sorrel horse, which bore the
Maltese Cross. Rock didn’t know the man and had never seen him
before. He was none of the riders Rock had seen either at the Cross
round-up, or in the vigilance committee that morning.
Rock stood looking down at the man reflectively, for a time. Then
he took him by the armpits and dragged him over the grass back to
the very thicket where the ambush had been held. He walked
through to take a look at the body on the other side. Rock did not
know him, either. But he took his weapons and a short search of the
thicket presently located a saddled horse securely tied.
This beast also carried a Maltese Cross. Rock took him by the reins
and went back to his prisoner.
CHAPTER XII—STACK DECIDES TO TALK
The crimson stream kept trickling down over Rock’s face. He had no
pain except a burning sensation on the top of his head, but the
crimson flow annoyed him. He finally hit upon the expedient of
stuffing the black silk handkerchief which he habitually wore about
his neck, into the crown of his hat, adding thereto a smaller one
from his pocket. Then he jammed the crown tightly down on his
head to absorb the flow. That done, he rolled himself a cigarette.
Then he stood looking speculatively down at his captive.
“Are you Joe Stack or Bill Hurley?” he inquired.
“Stack,” the man grunted. He stared at Rock out of sullen eyes.
“Then I suppose that was Mr. Hurley that I downed, eh?”
The man assented with a nod. Those were the names of the two
hard citizens Buck Walters kept hanging around the Cross home
ranch, so Charlie Shaw had told him. Rock was not in the least
surprised to find his guess correct. Men who had acquired notches
on their guns in the South were not usually averse to adding more
notches when they drifted North—either for profit or satisfaction.
“Well, you took on a contract,” he said. “And you have fallen down
on it. I am going to tell you a few things, Stack, then I am going to
ask you some questions. You’re a Texan. Did you ever hear of Steve
Holloway who was a U. S. marshal at Abilene for a spell? I expect
you did. He cleaned out a nest of outlaws up in the Childress
country, where I understand you made yourself a reputation. Steve
was my father. Then there is Tom Holloway, who is a captain in the
rangers. ‘Long Tom’ they call him. He’s an uncle. Then there’s Ben
Holloway who owns the Ragged H down on Milk River, not so awful
far from this neck of the woods. He’s a cousin of mine. There are
other Holloways scattered here and there west of the Mississippi.
Most any one of them would go a long way to shoot a skunk,
especially of the two-legged variety. I’m something like that myself.
You were sure hunting big game when you camped on my trail. Did
you know it?”
The man didn’t answer. But the look of apprehension in his eyes
deepened.
“And Buck didn’t tell you? Maybe he didn’t know, himself,” Rock
said. “Now, why did Buck Walters set you to kill me the way he got
Doc Martin killed? Will you answer me that?”
“You got me foul,” Stack muttered. “I tried to get you, an’ you got
me, instead. But I ain’t talkin’.”
“No?” Rock said very softly. “Well, I was raised in an Apache
country, Stack. I expect I can make you talk.”
He turned away with a frown. No use wasting words. All about in
the thicket were dry twigs, dead sticks. He gathered an armful of
these, broke them up into short lengths, and dumped the lot by his
prisoner. He took out his knife and whittled a lot of shavings. Once
he stopped to roll another smoke.
“Don’t you reckon you better talk, Stack?” he suggested.
The man’s mouth shut in a tight line.
Rock lit the fire with the same match he used for his cigarette.
When it began to crackle briskly he laid hold of the boot on Stack’s
free foot and jerked it off. The man’s face went livid. For a second he
struggled in a momentary panic, then lay still, his face gradually
turning ashy, little beads of moisture breaking out on his forehead.
Rock addressed him quite casually.
“I want to know just why Buck Walters is so anxious to have me
killed off. I want to know what sort of skin game he is working on
the Maltese Cross, and how he works it. I want to know why he was
so eager to hang Doc Martin when he thought he had failed at
bushwhacking him. You know why, I am pretty sure. Cough up what
you do know.”
“I don’t know nothin’ except that Buck offered me and Hurley five
hundred dollars to put your light out. That’s all I know.”
“You are lying,” Rock said. “I will jog your memory a little, I think.”
With a jerk he drew the man close to the fire and thrust his foot at
the small, hot blaze. Stack jerked his knee up. Rock put his spurred
foot on that cocked knee, forced it down, and stood on it with all his
weight. The heat made a singeing smell rise from the man’s sock.
His eyes bulged. He set his teeth in his under lip. Rock stood over
him, holding him helpless. Outwardly Rock was hard and merciless,
but inwardly he felt his stomach turning. He hated the thing he had
set his hand to. It was a contest of a sort between his fundamental
humanity, his sense of decency, and the nerve of this cowardly
assassin. And Stack weakened a trifle before Rock felt he could go
no farther with that fiery ordeal.
“Oh!” Stack groaned. “Let up! I’ll tell you.”
Rock kicked the glowing coals aside. His own face was white.
“Spill it all,” he snarled. “I know enough to tab you if you try to
stall.”
For the next ten minutes words tumbled out of Stack in short,
jerky sentences. Here and there Rock put a question.
“An’ that’s all I know,” Stack gasped at last.
“It’s enough—plenty,” Rock said. “I’m tickled to death you waylaid
me to-day.”
“What you goin’ to do with me?” Stack muttered, as Rock stood
over him in brooding silence.
“If I were some people I know you’d never get out of this draw
alive,” Rock said. “You certainly have it coming. I’m not just sure I
ought to turn you loose.”
“All I want is a chance to get a long ways from this country now,”
the man declared.
“I wonder what Buck Walters would do to you if you went to him
and told him I pried all this out of you?”
“I ain’t crazy,” Stack protested. “You turn me loose, an’ neither you
nor Buck Walters’ll ever see me for the cloud of dust I’ll raise foggin’
it to Idaho or Oregon, or some place a long ways from the Marias
River. I know when I got enough.”
“I expect that would be your best move,” Rock agreed.
He bent over Stack and undid the rope. The man sat up, rubbed
his foot gingerly, and drew on his boot.
“Now,” Rock said sternly, “people like you sometimes say one thing
and do another. You may change your mind, once you get hold of a
gun again and get a horse between your legs. You may figure you’d
like to get even with me. I am not letting you go out of sympathy. I
haven’t time to bother with you, or I would take you to Fort Benton
and throw you in the calaboose and land you eventually in the pen.
But I am after Buck Walters—not small fry. It is not going to be
healthy for him nor any of his crowd around here very soon. So, I
will make you an offer and give you a piece of advice. The offer is
that if you will walk out in plain sight on the hill, in about an hour, I
will give you back this horse. The advice is that you mount him,
head south, and keep going.”
Stack rubbed his wrists where the hair macarte had sunk deep in
his flesh.
“That suits me down to the ground,” he said. “I don’t never play in
a losin’ game if I get a chance to draw out. You needn’t worry about
me changin’ my mind. I don’t want none of your game, no more. But
I got stuff at the Maltese Cross I’d like to have.”
“Buck Walters is too clever for a man like you,” Rock declared. “He
would get out of you what has happened before you knew where
you were at. And I don’t want him to know. He’d probably end up by
throwing a bullet into you.”
“Maybe. Only I don’t think he’d be there at the ranch,” Stack
declared.
“What makes you think that? Where would he most likely be.”
“I have only got a hunch,” Stack said slowly. “But I think he’s goin’
North for a spell, with a hand-picked crew.”
Rock considered this gravely.
“Look,” Stack offered. “I ain’t hankerin’ to take a chance with
Buck. I don’t see nothin’ in this country for me no more, nohow.
Can’t you stake me to an extra horse, a bed, an’ some grub? Then I
can light right out.”
“You’ve sure got gall,” Rock said coldly. “To ask me to stake you to
anything after trying to kill me.”
“Well, long as I’m alive I got to eat,” the man retorted. “I got
some money on me, but it might be quite a ways to another job.”
Rock regarded the man for a moment. He was not moved by any
feeling of kindness. Stack was a gunman whose services were for
sale to the highest bidder. He would kill for money, and he would kill
for lack of it. There was nothing of loyalty in his make-up. He would
embark on desperate undertakings without any personal rancor
toward his victims. And he would desert with as little compunction if
the game didn’t seem worth the candle.
Stack had had enough of Rock Holloway. To save his feet from
being toasted, he had divulged information which made northern
Montana no place for him. He had blood money in his pocket. With a
horse under him, a dead running mate behind him, he would leave
for new fields, where his peculiar talents might find suitable
employment. Buck Walters would be a long time finding out what
had become of his two thugs, if this one had a horse, a blanket, and
a little food to start him on his journey.
“You don’t get no extra horse,” said Rock. “I’ll bring you back this
one. A Maltese Cross horse is as good for you to ride out of the
country as any. I’ll stake you to a blanket and a little grub. You can
take it or leave it.”
“You’re the doctor,” Stack agreed indifferently. “I’d like another
cayuse, but if you ain’t got one to spare——” He shrugged his
shoulders in acceptance of those terms.
Rock swung into the saddle and left him. He had all the guns. He
galloped down the ravine after Nona Parke’s work stock, picking
them up where they had stopped to graze, half a mile below. He had
to haze them into the ranch, catch a fresh mount, secure the things
he had promised Stack, and return here.
After that—well, riding fast toward the Marias, with an ache
beginning to make his temples throb, Rock could still smile with
anticipation. It was worth a sore head. He would very soon have a
weird tale to relay to Uncle Bill Sayre in Fort Worth. He would
surprise that estimable banker. And it was not impossible that he
might surprise Buck Walters even more in the immediate future.
CHAPTER XIII—ON THE WARPATH
Rock staved off Nona Parke’s agitated questions when he asked for
food. He robbed his own bed reluctantly, but a promise was a
promise, apart from his desire to have Stack out of the country
between dusk and dawn. The blood on his face and the strange
sight of him riding a Maltese Cross horse stirred Nona to a curious
pitch. But Rock moved fast, told her nothing, and got away again.
He made the round trip in an hour. As he drew up on the brink of
the ravine, Stack walked up to meet him, carrying on his back Rock’s
saddle which he had stripped from the dead horse.
“I reckoned you’d want this,” he said genially.
Rock sat on his own horse, watching the man ride away. Stack
headed south. As far as Rock could see him, he bore straight for Fort
Benton. He would never turn back, Rock felt assured. Stack had shot
his bolt. There was a certain strange relief in that. He marveled at
the queer compound of savagery, cupidity, cunning and callousness
that characterized such a man. They were rare, but they did exist.
Stack admitted that Hurley had shot Doc Martin. He admitted that
he and Hurley were to share five hundred dollars for ambushing
Rock. He didn’t seem to have any emotion about it, except a mild
shame over his failure. He didn’t seem to regard Rock with anything
except a grudging admiration for beating him at his own game.
Owning himself beaten, he withdrew. And, at that, Rock muttered to
himself, Stack had nothing on Buck Walters when it came to vileness
and treachery.
Rock turned his horse and rode homeward, reaching the TL about
supper time. He was tired. His head ached intolerably, now that the
bleeding had ceased. When he took off his hat and removed the
handkerchief compress, he could feel the slash cut by that bullet. A
quarter of an inch lower! By such narrow margins chance operates.
Rock sat on the side of his bed, wondering if he should wash and
bandage that wound. Now he began to fear that it might give him a
good deal of trouble. He hoped not, because, unless he had guessed
wrong, some rapid-fire action lay ahead of him. And while he
pondered thus, Nona walked into the room.
He scarcely remembered how he had accounted to her for the
crimson stains on his face. But her quick glance took in the
discolored handkerchief and the matted brown hair. She stood over
him with a worried look.
“You are hurt,” she said. “What happened?”
“Fellow took a shot at me—one of Buck Walters’ men. Keep that
under your hat,” he warned. “It’s only a scratch.”
She bent over his head and parted the hair with gentle finger tips.
“It isn’t bad,” she murmured. “But it must be painful. And it ought
to be cleaned. I’ll get some stuff and dress it.”
She returned in a minute with a basin, scissors and carbolic acid.
Very deftly she snipped the hair away from about the wound,
cleaned it with a solution that burned like fire, and drew the edges
together with a patch of court-plaster. Then she sat down on the bed
beside Rock and said earnestly:
“Now tell me about it.”
“Nothing much to tell,” Rock demurred.
“You mean you won’t?”
“Not just now,” he said. “It has nothing to do with you, anyway.
Buck seems to want me out of the way. I am quite a bit wiser about
things than I was this morning, but I still have a few guesses
coming. There’s nothing to worry about. Don’t let on to any one that
I have been shot at. I will say a horse fell with me and cut my head.”
“But it does worry me,” she protested. “I feel uneasy. Something’s
got to be done about this, if a man riding for me can’t go anywhere
except in danger of his life.”
“Something is going to be done about it,” Rock assured her.
“Darned quick, too! It isn’t because I am riding for you. It is because
I am supposed to be dangerous, just as Doc was dangerous for
something he knew or guessed. He was foolish enough to tip his
hand to Buck. I am not going to talk. I’m going to get busy. All you
can do is to wish me luck.”
“I do,” she murmured. “I wish the Maltese Cross had never come
into this country.”
“In that case I wouldn’t be here,” he said. “And I’m darned glad I
came.”
“Why?” she asked.
“Oh, lots of reasons.” Rock smiled. “I’ll tell you some of these
days, when the dove of peace spreads her wings across this part of
the world.”
“I wish you’d tell me,” she begged. “I hate mysteries. I’m getting
so I go around here with my heart in my mouth, wondering what
terrible thing will happen next.”
“I don’t think anything more will happen around this ranch,” Rock
declared. “I’m the center of this trouble, and I’m going to take
myself away from here—for a while. But I’ll be back.”
“I’ll be sorry to see you go,” she whispered. “But perhaps it’s best,
if you are going to be ambushed at every turn.”
She looked down at the floor frowningly for a few seconds. Rock
stared at the curve of her neck, the scarlet twist of her lips, the dark
cloud of hair, and a queer breath-taking sensation stirred in him, an
almost uncontrollable impulse to draw her up to him. He shook
himself. Why the devil should a woman have that effect on a man?
And Nona seemed to be unconscious of it—even to be irritated by
the manifestation of a feeling she was the factor in arousing.

Nona got up. She looked at him with such frowning composure that
Rock couldn’t meet those level gray eyes. It seemed to him they
read him through and through.
“Come along to supper. It’s all ready,” she said.
Rock shook his head. “Don’t feel like eating,” he replied. “After a
while I’ll have a cup of coffee, maybe; but not just now. Will Charlie
be back to-night, I wonder?”
“I think so.”
“I’m going to pull out at daylight,” he told her. “If I am gone
before you get up, so long.”
“I’ll be up,” she said briefly and left him.
Charlie Shaw came jingling his spurs across the porch at sundown.
“Did Buck have anything to say to you while you were at camp?”
Rock asked.
“Didn’t see hide nor hair of him,” Charlie replied. “He took one of
the wagons, about half his crew, a bunch of saddle stock, and pulled
his freight as soon as they all got back from that session here this
mornin’. So the boys told me.”
“I thought the spring work was all over,” Rock commented.
“It is.”
“Nobody know where Buck headed for?”
Charlie shook his head.
“I’ll bet a dollar to a doughnut,” Rock said, “that he took with him
only his special pets.”
“You’d win your bet,” Charlie growled. “I didn’t count noses, but
the hard pills were among the missin’. How’d you guess?”
“‘Birds of a feather.’” Rock quoted the old proverb. “I’m leaving
you, myself, in the morning, Charlie.”
“What for?” Charlie inquired.
“Well, for public consumption.” Rock smiled. “I’m pulling out
because I find life here much too exciting. I don’t like vigilance
committees and private wars. Privately, between you and me and
the gatepost, I’ll be back before long. And I’m coming back with
bells on.”
Charlie frowned.
“Kinda hate to see you go,” he said. “But I guess you know your
own business best.”
“Did Doc Martin ever tell you about finding a set of corrals with a
branding chute, tucked away somewhere in the Sweet Grass?”
“Hell!” Charlie exclaimed. “How’d you find that out?”
“Did he tell you where they were?”
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like