Mercer Book

Remarks by Rick Mercer.

PREFACE:

'Computing Fundamentals with C++' is written for students with no prior programming experience. It is intended for students majoring in computer science, the physical sciences, engineering, or business. A working knowledge of high school mathematics is assumed. Students familiar with another programming language can use this textbook as well. Although programming background provides advantages, C++ and the objects-early approach of this textbook provide a more level playing field. Consequently, coverage of the topics in this textbook should be interesting and challenging to students with some programming experience as well. Above all else this book helps anyone wishing to develop and refine their problem solving and program development skills. C++ is a tool.

o Extensively Tested in the Classroom

The manuscript has been class tested over eight consecutive terms, from Spring 1992 to Summer 1994. There has been a wide range of student abilities and backgrounds. Students supplied many useful comments and suggestions concerning manuscript clarity, organization, lab projects, and examples. This comprehensive field testing and development are unique among most of the books available on this subject.

o A Gentle Objects-Early Approach: Use, Modify, then Implement Object Classes

The book begins by placing the student in the role of a consumer--a user of object classes. While students hone problem-solving and program-development skills, the student learns to use, modify and ultimately, to design and implement their own classes. Experience with several topic organizations has demonstrated that students more easily master the topics when presented in this manner. This approach alleviates the mental "bump" (referred to by some as "the paradigm shift") often encountered when learning the object model.

o A Carefully Chosen Subset of Analysis, Design, and C++

Because students using this textbook might have little or no software development experience, several C++ features and subtleties are not covered. Students concentrate on a more solid subset of this feature rich language. There are many excellent trade books that do provide this information and instructors may cover their favorites at the appropriate time. Some of C++'s trickier topics are delayed until the later chapters. For example, an accompanying string class avoids early coverage of pointers (see Chapter 9 for char * objects). Reliance on the cin and cout objects avoids coverage of C style I/O with the address of operator & (see Appendix F for the printf and scanf functions). Some topics are optional, such as operator overloading, break, and switch. There are a few examples of low-level object-oriented analysis in Chapters 1 and 8, but most program development examples use other accessible analysis tools. One involves determining the input and output. Simple design tools include: input, process, and output algorithms; stepwise refinement; and recognizing and locating beneficial classes that already exist. Student- accessible testing tools include test oracles and branch coverage testing. Pointers and dynamic memory management (Chapter 9) are additional topics or ancillary material in a second course.

o A Carefully Chosen Subset of Object-Oriented Programming

This textbook does not cover inheritance and polymorphism. However, the major object-oriented concept of encapsulation plays an important role throughout. Data is an integral part of any object, as are the functions that manipulate that data. This approach gives students a chance to become accustomed to using objects and designing and implementing individual classes before classification of larger systems. Students have a good grasp of C++ class design and implementation by the end of Chapter 8. Chapters 9, 10, and 11 illustrate encapsulation with examples of safe array classes and a list class that stores any type (class) of element. The C++ class and encapsulation proves to be important during the first course. Implied is their value in the second course. Adapted material from Chapters 3, 5, and 10 allows for inclusion of inheritance and polymorphism in a first course. The Instructor's Manual provides suggestions. The recent addition of templates could prove genericity is as important as inheritance and polymorphism in the first year. Templates at least provide for alternative approach to data structure implementation. To this end, Chapter 10: 'Templates' provides examples of a generic (parameterized) array class, a list class that stores elements of any class (data type), and a generic stack. The C++ template mechanism is an additional topic or ancillary material in a second course.

o Case Studies with the Analysis, Design and ImplementationStategy

A basic pedagogical technique employed in each chapter is the use of case studies. The case studies achieve the following: enforce the importance of problem analysis; provide examples of design that use constructs of recently covered material; and address implementation issues--such as, coding and program testing--to ensure the program implementation meets the specification. This three step strategy provides a positive, digestible model right from the beginning.

o Each Chapter Contains Abundant Self-Check Questions and Exercises

In each chapter, every section contains its own self-check questions (with answers). These questions and answers provide a checklist-like opportunity to review and digest the material just covered. A complete set of exercises (without answers) exists at the conclusion of all chapters. Most chapters include an additional set of exercises at the midpoint.

o Numerous Self-Contained (and tested) Lab Projects

Because the hands-on computer use is a key component to learning program design and implementation, all chapters have lab projects at their close. Most chapters have additional lab projects in the middle. The lab projects--physically located next to related textbook material--were developed and tested over an extensive period of time. Feedback from students in the lab and from other instructors has led to important refinements. This feedback contributed significantly towards developing each lab project as a self-contained lab, free of entanglement.

o Not Tied to a Specific System

In this textbook, there is no bias toward a particular operating system or compiler. All material applies to any computer system with C++. All software has been tested on the following systems: MS-DOS/Turbo C++ versions 3.0 and 3.1; MS-Windows/Borland C++ and Turbo C++ for Windows; MS-Windows/ Microsoft Visual C++ version 1.0 (template classes excluded); Symantec/Macintosh C++; UNIX/Sun C++ (template classes excluded); and UNIX/GNU g++.

o Acknowledgments...

o Annotated Chapter Titles

1. Program Development with Objects (cin, cout, and float objects) 2. C++ Programs (tokens, expressions, statements, int and char objects) 3. Abstractions (function prototypes, member functions and the ifstream, string, and bankAccount classes) 4. Implementations (function definitions and class declarations) 5. Selections (if, if...else, switch) 6. Repetition (while, for, and do while loops) 7. Arrays (built-in C arrays like float x[10]) 8. Class Design and Implementation (private vs public, choosing members...) 9. Pointers (*, &, new, and delete) 10. Templates (a safe generic singly subscripted array class, a generic list) 11. Multi-Dimensional Arrays (a safe generic doubly subscripted array class)

------Here are some additional notes on this objects-early first course-------

It seems like I should mention two other important classes used in chapters 4, 5, 6, and 7: bank and ATM. The bank class is a collection of bankAccount objects. The ATM class is an automated teller machine interface that communicates with the user. Objects constructed from bank and ATM interact to develop a bank control program over 3 chapters. It involves nested selective and repetitive control structures and lots of calls to member functions. The resulting lab projects, which I am personally fond of, only seem to be appreciated by the CmpSci majors. The service course students, who 'have to' take this course, have been heard to groan at the bank control lab projects.

Chapter 8 first discusses some class design issues. At this point, students have modified classes and seen enough class declarations and member function implementations that class declaration and implementation are no problem. The chapter 8 case study involves low-level OOA: nouns are potential objects, verbs potential operations. The resulting classes: phoneBook, which is a collection of phoneListing objects provide a capstone to the encapsualation feature of OOP, software development, fundamental problem solving concepts, and introduction to a programming language.

Chapters 9 and 10 (pointers and templates) verge on second course material but can be reached within 15 weeks with the aid of a fast pace and decent students. Chapter 11: 'Multi-Dimensional Arrays' can be covered anytime after Chapter 7: 'Arrays'.

Rick Mercer - Penn State Berks

AN ASIDE ABOUT TOO MANY CLASSES

There appears to be a limit to the number of classes any one student can remember. I am hoping inclusion of modified Gradygrams (Booch's module interface diagrams) on the inside jacket will provide the quick summary of operations the students seem to require as documentation. The class declarations in the dot h files in the text proper, in an appendix, and on disk provide more detail with pre- and postcondtions, meaningful parameter names, and the parameter's type. I have yet to try encouraging students to use a class browser. This might help, but our software upgrade is not due until Oct. My feeling is that the browser would be ignored in a first course.


Contributed Outline

DRAFT - David Teague

CS 150: Problem Solving and Programming

Course Description

Problem solving and algorithm development within an object-based programming context. The development of skill in solving problems with modular programs using classes, selection, iteration, and generic classes within the C++ programming language.

4 credit hours (3 lectures and 2 recitation(supervised programming and problem solving), course required for the CS major and the CS minor. It satisfies the Computer Literacy General Education requirement in place of CS 101 (Computer Literacy). Corequisite is MATH 130 or equivalent, offered every semester.

Textbook

Required R. Mercer, Computing Fundamentals with C++, Franklin Beedle and Associates, 1994.

Course Work

Three tests (12.5% of the final grade for each) and a comprehensive final examination (25% of the final grade).

Assignments that are primarily programming, but may also contain some written exercises, are due every week or so for a total of about ten. Assignments earn the remaining 37.5% of the final grade.

Course Outline

Week 1 Administrative. Chapter 1 (Computers). Basic concepts about hardware, software, and the operating system. Program development, input and output objects. The Lab exercises involving doing tutorials and exercises on use of the programming environment: the editor, compiler, program execution, minimal necessary operating system commands. Reading: Chapter 1 of text.

Week 2 Start Chapter 2 (Programs): C++ tokens (identifiers, constants, reserved words, comments), output with cout, input with cin, arithmetic expressions, variables, types of programming errors. Reading: Chapter 2 of text.

Week 3 Finish Chapter 2. Reading: Chapter 2 of text.

Week 4 Chapter 3 (Abstractions: functions abstraction). Learn how to use functions and classes that are already defined; e.g some mathematical functions, a string class, input and output streams. Function prototypes, return value, call by value parameters, member functions with input and output stream classes, string class, first class specification, declaration of class objects. Reading: Chapter 3 of text.

Week 5 Chapter 4 (Implementations). Learn how to implement new functions and gain the ability to read class declarations. Programmer-defined functions: function definitions, call by value versus call by reference, scope of identifiers, local variables. An example class: automated teller machine. Format of a class declaration and thorough examples. Reading: Chapter 4 of text.

Week 6 Chapter 5 (Selections). If, if-else, and switch statements. Logical operators and nested logic. Reading: Chapter 5 of text.

Week 7 Chapter 6 (Repetitions). While, do-while, and for statements. Event-controlled loops and nested while loops. Reading: Chapter 6 of text.

Week 8 Makeup week.

Week 9 Chapter 7 (Arrays). Distinguish between simple data types, structured data types (including arrays and classes), and pointer data types; array variable declaration, subscripting, initialization. An extended example of a stringList class that maintains a set of strings using an array data member (so I would call it stringSet) and showing how to add and remove strings from the set. Sequential search, sorting (selection sort), and binary search all using the stringList class example. Reading: Chapter 7 of text.

Week 10 Chapter 8 (Classes). The details of class implementation: constructors, multiple constructors, member function implementations, public versus private data members, which object's data member does a data member reference reference, function overloading, and default arguments Reading: Chapter 8 of text.

Week 11 Makeup week. Reading:

Week 12 Chapter 9 (Pointers) Pointers and dynamic allocation, passing pointer parameters, char* pointers and null-terminated strings, destructors. Reading: Chapter 9 of the text.

Week 13 Chapter 10 (Templates). A template class (i.e. a generic class) for arrays that does subscript checking, a template class generalization of the stringList class of Chapter 8, multi-dimensional arrays. Reading: Chapter 10 of text.

Week 13 If time presses then continue with Templates. Chapter 11 is is to be done if there is sufficient time. Chapter 11 (Doubly Subscripted Arrays). Doubly subscripted array class. Reading: Chapter 10 of text.

Week 14 Makeup days, Administrative.