Return
EML 3002C MECHANICAL ENGINEERING TOOLS: C++ Fall 1997
Van Dommelen
- GOALS
-
To familiarize students with structured and object oriented programming
concepts.
- PREREQUISITES
-
Sophomore standing in Mechanical Engineering.
- INSTRUCTOR
-
Dr. Leon Van Dommelen
http://www.eng.famu.fsu.edu/dommelen.
dommelen@eng.famu.fsu.edu
Contact me.
Office: 3:00-3:50 pm T, 5:40-6:30 pm R or by appointment.
Phone: (850) 487-6324. I tend to forget to check my voice mail.
- TIMES
-
Class: 1:15-2:30 TR 2:45-5:30 W
Final: Wednesday 12/10/97 7:30-9:30 am (if the FSU schedule is correct)
- TEXTBOOK
-
Kris Jamsa, Rescued by ... C++. Jamsa Press, Las Vegas, NV,
1993. ISBN 0-9635851-5-0, $19.95.
- COURSE OUTLINE
-
Below is a tentative list of lectures with topics covered, objectives,
and notes.
- Basics
- Lessons 1, 2, and 3
- The objective is to get the students up
and running. The students are to write and compile a program to
print `Hello World' to the screen (hello/2/). Illustrates
include, main, void, cout grouping, g++
compiler, and syntax errors (hello/1/). Comment on complexity
issues in programming. Star Wars? Make clear why large tasks
require programming languages, since the programming effort during
class must obviously be limited.
- Lessons 4, 5, and 6
- The objective is to get the program to do
useful things. The students modify the program to read in a simple
part's steel weights, and the raw steel price, then compute and
print the material cost of the part (inout/1/). Illustrates
variables, assignment, input, output, comments, operations. The
student add a second material, aluminum, and then examine
precedence and parentheses (inout/2/).
- Lessons 7 and 8
- The program complexity is increased somewhat
to show the need for structured programming. The program is
modified so that it only asks for the steel or aluminum price if
the part contains that material (menu/1/). The students then modify the
program so that it can compute more than one part at a time. After
each part, the program presents a two choice menu: do the next
part or quit. Illustrates if for checking whether the
material is in the part, if...else for the menu selection,
while for looping, for for clearing the screen for the
menu (explain the existence of screen of varying sizes), and the C
true/false representation. (menu/2/).
- Functions
- Lessons 9 and 10
- The program complexity is again
increased to illustrate the desirability for modular
programming. The previous two-part menu is cast as a character
function that returns the choice, so that the code of the main
program becomes more clear. Also, we can clean up the code a bit
by using the menu in two places (function/1/). Next the
computation of the part cost and the printing of error messages is
also moved to separate functions to streamline the program further
(function/2/). Finally the menu is expanded to four choices:
compute a part, change the price of steel, change the price of
aluminum, or quit, the first three performed by functions. The
function for computing the cost of a part takes the prices of
aluminum and steel as its arguments and naturally shows the need
for passing arguments by reference rather than by value
(function/3/).
- Lessons 11, 12, 13, 14, and 15
- Explain scope and
improvements in clarity and robustness due to using local
variables. Some students verify that local variables in the main
program and subroutines with identical names are different
(advfun/1/). Then they make the variable global
(advfun/2/). Mention the runtime library. Let some students
print the date at the start of their program (advfun/3/).
Explain overloading functions. Some students overload the error
message function to print out a value at the end of the message
and use it to protest negative material cost (advfun/4/).
Explain references and default values. Some students convert
their arguments to references and default values (advfun/5/).
The students resynchronize on advfun/5/.
- Arrays, Structures, and Pointers
- Lessons 16, 17, and 18
- Discuss the need to maintain a data
base of parts, instead of a single part. Explain the reductions in
likely errors by grouping related part data together. Information
sheet? The students create a part structure (array/1/). Explain
the advantages of arrays in dealing with variable numbers of
items, or with many items, or with extensive code addressing the
items. The students convert their program to create an array of
the parts structure (array/2/). Discuss zero-terminated character
strings. The students use them for the part names (array/3/).
- Lessons 20 and 31
- Address the question how we can allow the
user to add new parts to the data base interactively. Explain
memory and pointers. The students modify their program to add new
parts in the free-store. Explain pointers to pointers. The
students modify the program so that all parts are created on
demand, into a pointer array.
- Classes
- Lessons 21, 22, and 23
- Now add the requirement that we check
that the part number is 4 digits. Show that we need to search
through the code to find the two places where we input the part
number. Explain classes: the code can be attached to the
structure. Show that this eliminate code duplication as well.
Explain the reduced risk of errors with code reuse (less code used
more). The students convert their structures to objects, with
methods to input the various parameters of the part. (classes/1/).
Discuss the question how easy it would be to port over the parts
code to another program, say keeping a parts inventory. Assuming
that the current program would not be all parts, you have to
search each function whether it is dedicated to parts or has code
related to parts. Since you want to add a new variable, the
number of copies of the part, to the parts structure, you have to
search through all functions for places where the part data may be
initialized or modified and add code for the new data item.
Explain encapsulation. Suppose some programmer simply pokes a
wrong value in the part number? The students bring all part
related code together in the object, using encapsulation,
constructors and destructors. (classes/2/).
- Inheritance As time permits
- Advanced Concepts As time permits.
- METHODS OF INSTRUCTION
-
Lectures, solution of problems on computers, projects.
- STUDENT EVALUATION
- The course grade for this part
of the class will be computed as:
- Group computer programs 30%
- Individual projects 30%
- Examinations 40%
Grading is at the discretion of the instructor.
- IMPORTANT GENERAL REQUIREMENTS
- Please note:
-
Projects are handed in by E-mail.
-
Projects that are not handed in when due cannot be made up.
-
If you are absent from a project, your group may have to proceed with one
member less. You will not receive the group grade for that project.
-
Individual projects must be performed individually.
Unusual similarities in the way things are coded will be taken
as evidence of cheating.
-
Programs should be very neat and well
written and commented or credit will be lost.
-
Students are bound by the honor code of their university. It requires
you to uphold academic integrity and combat academic dishonesty.
Please see your student handbook.
- COMPUTER USE
-
Uses Personal Computers to teach C++ programming.
Up: Return
Author: Leon van Dommelen