Lab Manual C++ Chapter4
User Manual:
Open the PDF directly: View PDF
.
Page Count: 16
| Download | |
| Open PDF In Browser | View PDF |
Lab 4.1 Enumeration Classes— Classy Rocks
Project 4.1 More Classy Rocks— Continuation of Lab 4.1
NOTES TO THE INSTRUCTOR
This lab and project are intended to demonstrate the “correct” way to build the new data type R o c k
considered in Lab Exercise 2.2 and Project 2.2, namely, using a class. The lab exercise begins the design
and building of the first part of this class, and the project continues the development. Both are intended to
provide a review of (or perhaps a first look at) how to build a class in C++ and to illustrate how class
objects are self-contained. Rather than pass enumeration values around to various functions for processing,
enumeration-class objects operate on themselves with built-in operations. In particular, input and output
operations are developed for the R ock class in the lab exercise; the relational operators < and == and the
increment operator ++ are overloaded for the R ock class in the project.
Notes:
1. Parts 4 and 5 of the lab exercise deal with overloading the output operator «
There are two ways to do this:
and the input operator >>.
•
Define a function member d i s p l a y () and then have o p e r a t o r « () call it; and define a
function member r e a d () and then have o p e r a t o r > > () call it.
•
Make o p e r a t o r < < () a n d o p e r a t o r > > () friend functions of class Rock.
You should tell students which method you want them to use. The first is consistent with OOP and with
the idea of inheritance and polymorphism considered later in the text and is the method used in the lab
exercise. The second involves less typing and shows students how the friend mechanism is used (which
isn’t really consistent with the spirit of objective-oriented programming and can be easily overused).
2. Either or both of Parts 6 and 7 of the lab exercise may be omitted if you think the lab exercise is too
long.
3. Because the first part of the project is a continuation of the lab exercise, you may want to have the
students keep the lab handout to use in the project and then hand it in with the project handout, the final
R ock files, and the driver program. The project’s application could then be handed in at a later date.
4. The application in Project 4.1 requires an operation to increment a R o ck value so that loops can be
written that range over the different R ock values. There are two ways to do this:
•
Use a n e x t () function as in Lab & Project 2.2. In this approach, one need only modify this
function to make it a function member of the R ock class.
•
Overload the increment operator ++ for class Rock.
You should tell students which method you want them to use—the first clearly is simpler, but the
second is another illustration of operator overloading. In Project 4.1’s description, the second procedure
is used.
5. Lab Exercise 4.1 uses the driver program r o c k t e s t e r . c p p to test the R o c k class as it is being
developed. The application in Project 4.1 uses the data file R o c k f i l e . t x t (which is the same as the
file used in Project 2.2). These files can be downloaded from the website whose URL is given in the
preface.
51
Lab 4.1 Enumeration Classes—Classy Rocks
Course Info:
Name:
_____________________________________
__________________________________
Lab 4.1 Classy Rocks
B ackground: In Lab 2.2 we explored using C++’s enumerated types to
implement a R ock type. There were several limitations to this approach. A
major one is that if we wanted to use a R o c k , operations had to be
implemented by passing the rock value to each application. Moreover, Cstyle enumerations do not support overloading arithmetic operators such as
+, - , ++,
and so on.
Objective: This lab exercise will focus on implementing a rock type using
a C++ class. In the course of developing this rock class, we will learn how
to give various capabilities to our rocks:
•
They will be able to construct themselves, so we can build new rocks. These can either have default
values or be created with explicitly supplied values.
•
We want to be able to display rocks using the standard output streams such as c o u t, which means
that we will need to overload the output operator <<.
•
We want to be able to read a rock from an input stream such as c i n , which means that we will
need to overload the input operator >>.
•
Rocks should be able to tell us about their kind and texture.
A p p ro ach : C++ classes package data and operations together and thus provide an excellent way to
implement ADTs. If we create a Rock class, then we are making smart rocks that know how to do things,
i.e., the operations are part of a R ock object. As you create your Rock class, you will test it incrementally
using a program called rocktester.cpp. If you are working in a Unix environment, a Makefile is
helpful with compiling and linking. You should get a copy of these files using the procedure specified by
your instructor. (They can be downloaded from the website whose URL is given in the preface.)
As you progressively develop your Rock class, you will also be modifying the rocktester.cpp
program and learning about building test drivers for your classes. If you need more information about
classes, see Chapter 4 of the text ADTs, Data Structures, and Problem Solving with C++, 2E.
When you have completed Lab 4.1, your next task will be to continue with Project 4.1, which will add
relational operators to your R ock class and an increment operator. This will produce a class that is fairly
rich in operations, almost as if it were part of the C++ language.
Step 1: Begin Developing Class Rock
Class Declaration:
The form of a class declaration for the Rock type is:
class Rock
{
public:
// Put declarations of things that should be available outside the
// class here — in particular, prototypes of public function members.
private:
// Put declarations of things that should not be available outside
// the class here — in particular, declarations of data members.
};
53
Lab 4.1 Enumeration Classes— Classy Rocks
1.1 Create a R o c k .h header/interface file. A header file informs users about what the class can
do—and is thus often called an interface file—and the corresponding implementation file contains the
actual code that carries out the class’ operations—i.e., it shows how they work. Implementations can
be delivered in either source code or object code so that, if desired, one can keep the implementation
secret while publishing the interface. You will be making the source code for your implementation
available.
Check here when finished____
1.2 Now start with the enumerated type used for modeling rocks in Lab 2.2 and Project 2.2, but change
its name to RockName:
enum RockName {BASALT, DOLOMITE, GRANITE, GYPSUM, LIMESTONE, MARBLE,
OBSIDIAN, QUARTZITE, SANDSTONE, SHALE, ROCK_OVERFLOW};
First, try putting this RockName declaration in the public section of the c l a s s Rock.
Check here when finished____
1.3 Now put a private section in your class that contains a single data member myName of type
RockName.
Check here when finished
WARNING:
MAY NOT WORK
AS YOU EXPECT
1.4 Now load r o c k t e s t e r . c p p and compile it. Describe
what happens in the space below.
Error(s) that result are caused by the compiler encountering the identifier GRANITE in the last output
statement of Part 0, but it can’t find a declaration of it. The problem is that the declaration of the
enumerated data type RockName is inside the declaration of class R ock, which means that its scope
extends only to the curly brace at the close of this declaration.
To refer to this type outside the class or to the enumerators listed in it, one must qualify them so that
the compiler knows where to look for this declaration. Adding the qualifier R ock to GRANITE so that
it reads R o c k : : GRANITE in r o c k t e s t e r . cpp should get rid of the problem. Do this and then
recompile and execute. What happens?
What you have seen is that if we put an enumeration type definition inside the public part of a class,
we have to qualify each enumerator (as well as the type name) with the class name each time it is used
outside the class declaration. This is somewhat of a nuisance, right? So, to avoid this inconvenience,
we will:
•
Move the enumerated type in R o c k . h ahead of the class definition
•
Remove the R o c k : : qualifier in r o c k t e s t e r . c p p
Now recompile and execute the program to check that everything is okay.
Check here when finished____
54
Lab 4.1 Enumeration Classes—Classy Rocks
So the program currently uses two types:
1) RockName, the enumerated type defining the names of rocks, e.g. BASALT, DOLOMITE,
GRANITE, GYPSUM, etc.; and
2) Rock, the name of a class that includes a variable of type RockName. You might think of
RockName as a type of something that is inside a Rock object:
sample
myName
GRANITE
Step 2: Defending Against Redundant Definitions
Comment out (using / / at their beginning) or remove the lines labeled " BEGIN PART 1" and " END
PART 1 " in rocktester.cpp. (Note that they come earlier in the source code than those for Part 0.)
Then save and recompile the program.
You may get a plethora of error messages. But if you scan them, you should see some that indicate that
there is more than one definition of enum Rockname and also multiple definitions of the class Rock.
Find one of these and record it below.
Perhaps you didn’t notice it, but we included Rock.h twice. C++’s preprocessor, being very literal, did
just what we told it to do. The result is that the type RockName is defined twice, as is the class Rock. The
compiler was confused and complained. While we would not do this intentionally, it can happen very easily
when programs become complex. We might have a program that uses two classes, both of which include
Rock.h, and it thus gets included twice in our program.
2 . ) We need a mechanism to ensure that only a single copy of a header is included.
You can do this for R o c k . h by wrapping it in the following preprocessor code (called a
conditional compilation directive):
ttifndef ROCK
#define ROCK
... //put header code here
#endif
The first time that Rock.h is encountered, ROCK has not been defined, so it is defined (to be
1) and the code that follows Rock.h is included. The second time Rock.h is encountered,
ROCK has already been defined and so the code is skipped.
Note: It is common practice (but not mandatory) to use the name of the class in all caps in the
directive.
This mechanism is rather clumsy, but it works well enough. Add these defensive preprocessor
statements to your Rock.h file and then recompile and execute rocktester.cpp.
• If you get errors, make sure that you have entered the directives exactly as shown above (e.g., #
is the first character on each line, and they do not end with semicolons).
• Then comment out or remove the duplicate #include ”Rock.h " directive in
rocktester.cpp. It isno longer needed.
Check here when finished _ _
55
Lab 4 .1 Enumeration Classes—Classy Rocks
Step 3: Creating R ock’s Constructors
Normally, when we declare a new variable, we have to initialize it. Usually this is done by providing
initializers in the declarations of the variable; for example,
int i = 10;
//or
int x(10);
double x [3] = {1.0,2.0,3.0};
Without initializers, memory locations will be allocated for the variables, but the values in them may not be
meaningful.
Variables whose type is a class—called objects—should always be initialized so they form legitimate
objects of that type. C++ accomplishes this by calling a special function called a constructor. There are
several kinds of constructors, but two main types are of interest to us right now;
• default constructor:
ClassName() ;
• explicit-value constructor:
ClassName ( p a r a m e t e r - l i s t ) ;
These are the first function members to be added to your Rock class:
• A default constructor so that users can make declarations like the following:
Rock sample;
//default constructor
The default constructor should initialize the myName data member to some rock value, e.g.,
BASALT.
• An explicit-value constructor so that users of the class can make declarations like the following:
Rock rockVal(GRANITE);
//explicit-value constructor
This constructor should initialize the myName data member to the specified rock name (GRANITE).
Note: An alternative is to use only an explicit-value constructor with a default argument for the parameter.
Then if the user doesn’t supply a value, the default argument will be used. (See Section 4.5 in the text for
details.)
3.1 Add prototypes and documentation for these two constructors to your Rock class. Then test them
by commenting out or removing the lines labeled " BEGIN PART 2 " and " END PART 2 " in
rocktester.cpp and then compiling the program (but not linking—i.e., use the -c switch if you
are using g++).
Check here when it compiles without errors___ _
3.2 Now create an implementation file Rock, cpp with suitable opening documentation. Put the
definitions of the constructors in it. Remember that the names o f function members must be qualified in
their definitions:
ClassName:: functionName{
. . .)
3.3 Now compile and link rocktester .cpp and Rock, cpp and execute the resulting binary
executable.
Check here when it executes correctly____
Note: Later, fo r efficiency, we will inline simple functions like these constructors and put their definitions
in the header file below the class declaration. M ining a function has the effect o f replacing each call
to that function with the actual code of the function definition.
Step 4: Adding an Output Operation
One operation that we usually add soon after the constructors is an output operation so that we can use it to
check the implementations of the other operations. We will do this in two steps:
•
•
First add a display () function member in the usual way.
Then overload the output operator <<.
56
Lab 4.1 Enumeration Classes—Classy Rocks
4.1 Adding a d i s p la y ( ) Function Member
Write a function member d i s p l a y () with signature ( o s t r e a m &) and return type v o i d to output
a R o ck object. Put its prototype in the class. Make it a const function, since it does not change any
data member. To do this, append the keyword c o n s t to the function heading in both the prototype
and its definition.
fu n c tio n _ h e a d in g c o n s t
Put the definition of d i s p l a y () in the implementation file R o c k . cpp. You should be able to reuse
the code that you wrote in Project 2.2 to output rock enumerators with minor modifications.
When you have completed your d i s p l a y ! ) function member, you should test it. Comment out or
remove the lines labeled "BEGIN PART 3" and "END PART 3 * in r o c k t e s t e r . cp p . Then
compile R o c k . c p p and r o c k t e s t e r . c p p , link them, and execute the resulting binary executable.
Record below the values output for:
sample________________
rockVal ________________
4.2 Overloading the Output Operator «
Using d i s p l a y () to output a R o c k value works fine. But we do have to call it using the dot
operator as in
s a m p le .d is p la y (c o u t);
which breaks up the usual chain of << operations. What we’d really prefer is that output for the R ock
type be no different than output for any other type. To accomplish this we need to overload the output
operator. This is a little tricky, so we will proceed slowly.
First add a prototype for a nonmember function for the o p e r a t o r « () function in R o c k . h after
the end o f the class declaration. Because it is not a member function (as noted on the next page), do
not add a prototype for it inside the class R ock and do not qualify its name with the class name.
The function o p e r a t o r < < () should have:
•
Return type o s t r e a m &—a reference to an output stream so that the output can be chained
•
Signature ( o s t r e a m &, c o n s t R ock &)
So the prototype has the form
o s tre a m & o p e r a t o r « ( o s t r e a m
& o u t,
c o n s t R ock & r o c k V a l ) ;
The actual function body should do two things:
1) It should call the d i s p l a y () function member of its R ock parameter, and
2) It should return the o s t r e a m for chaining.
Add this definition to R o c k .c p p and then test that it works. To test it, comment out or remove the
lines labeled "BEGIN PART 4" and "END PART 4" in r o c k t e s t e r . c p p . Compile your
modified R o c k .c p p and r o c k t e s t e r . c p p files, link, and execute.
You should have gotten the same output as in step 4. Did you?_____________
57
Lab 4.1 Enumeration Classes—Classy Rocks
Step 5: Adding an Input Operation
Overloading the input operator >> is not significantly different from overloading the output operator <<.
5.1 First, add a function member read () with a parameter of type istream & to your Rock class.
Note that it cannot be a const function because it must modify the value of the myName data member
of class Rock. Again, you should be able to reuse the code that you wrote in Project 2.2 to input rock
enumerators with minor modifications.
5.2 Add a prototype and definition of operator>> () in much the same manner as you did for the
output operator. Note that it should have
• Return type istream &—a reference to an input stream so that the input can be chained
• Signature (istream &, Rock &)
Then test that it works by commenting out or removing the lines labeled " BEGIN PART 5" and
"END
PART
5 ” in rocktester .cpp. Compile your modified Rock.cpp and
rocktester.cpp files, link, and execute.
Record in the following table, the output produced for the given inputs:
Input for first R o c k
Input for second R o c k
BASALT
marble
Granite
gypSUM
feldspar
_____________________
O utput for first R o c k
O utput for second R o c k
99
A Quick Review o f Binary Operators in C++_____________________________________________
Let’s begin by quickly reviewing how C++ binary operators work. Suppose we have a binary
operator A. If operatorA ( a ,b ) is a member function of some class C, then the compiler will
interpret an expression of the form a A b (where a is of type C) as
a. operatorA(b)
Thus if we make operator« () a function member of class Rock, an expression of the form
cout << rockVal will be interpreted as
cout.operator<<(rockVal)
which confuses the compiler because the statement implies that operator<< () is a function
member of the class ostream and would have only one parameter—a Rock parameter. But, of
course, ostream does not have such a function, because we are trying to define such a function!
So this is the reason that neither operator« () noroperator»() can be a member
function o f a user-defined class.____________________________________ ____________________
58
Lab 4.1 Enumeration Classes—Classy Rocks
Step 6: Adding a k in d () Operation
In Lab 2.2 we added a kind () function that returns one of the strings “igneous,” “metamorphic,” or
“sedimentary,” depending on the kind of rock determined as follows:
•
Basalt, granite, and obsidian are igneous.
•
Marble, and quartzite are metamorphic.
•
Dolomite, limestone, gypsum, sandstone, and shale are sedimentary.
6 . Add a kind () function member to the Rock class. You can use the code developed in Lab 2.2 as
a starting point. To test if it works correctly, comment out or remove the lines labeled " BEGIN PART
6" and " END PART 6 " in rocktester.cpp, and then recompile, link, and execute.
Record in the following table the output produced for the given inputs:
R o c k Input
K ind o f R o c k
BASALT
Marble
Shale
Feldspar
Step 7: Adding a t e x t u r e () Operation
Mj |
66]
. Now add a function member called texture () that returns one of the strings “coarse,”
“intermediate,” or “fine” that indicates the texture of the rock, determined as follows:
•
•
•
Dolomite, granite, gypsum, limestone, and sandstone are coarse in texture
Basalt and quartzite are intermediate in texture, and
Obsidian, marble, and shale are fine in texture
To test if it works correctly, comment out or remove the lines "BEGIN PART 7 "and "END PART
7" from rocktester.cpp, and then recompile, link, and execute.
Record in the following table the output produced for the given inputs:
R o c k Input
T exture o f R o c k
BASALT
Marble
shale
feldspar
You have finished! Hand in:
1) the lab exercise with answers filled in
2) a listing of your final program and library files
3) a demonstration that everything compiled, linked, and ran correctly
4) a sample run of your program
59
Project 4.1 More Classy Rocks—Continuation of Lab 4.1
Name:
Course Info:
Project 4.1 More Classy Rocks— Continuation of Lab 4.1
Objective: Your Rock class now has quite a few capabilities. In this
project you will first continue the development of the class by adding
additional operations to it. These operations are:
• An accessor name () that returns the name of the rock stored in
myName
• Relational operators < and ==
Once these are added and tested, you will then use your class in a modified version of the bar-chart
program in Project 2.2.
Adding More Operations to the Rock Class
Step 8: Adding an Accessor to Rock
You want to add an accessor function called name () to class Rock that returns the value (of type
RockName) stored in the myName member. Should it be a const function? Why?
Once you have it written, test it by adding statements between the lines
labeled "B EG IN
PART
8" and "END
PART
8" in
r o c k t e s t e r . c p p like those in Part 7 to enter some R o c k values,
access and output the value stored in their m yN am e member (via
n a m e O ). Then recompile, link, and execute R o c k , c p p
and
r o c k t e s t e r . cp p . Record in the following table the output produced
for the given inputs:
Rock Input
WARNING:
MAY NOT WORK
AS YOU EXPECT
Name of Rock
BASALT
Marble
shale
feldspar
When you added the name () function, it returned a RockName value, but outputting this value produced
a number and not a name. We have overloaded the output operator to work with a Rock object, but we also
need to overload it for RockName values. The obvious solution is to modify the overloading created in
Project 2.2 and add its prototype to Rock.h (below the class declaration) and its definition to Rock. cpp.
Do this now and test it. You shouldn’t have to make any changes in rocktester.cpp.
Check here when it executes correctly____
61
Project 4.1 More Classy Rocks—Continuation of Lab 4.1
Step 9: Overloading the relational operators < and == for R ock
Your objective now is to add the relational operators < and ==, where x < y for R o ck objects means that
the value in myName of * precedes the value in myName of y in the enumeration declaration.
Unlike the output operator o p e r a t o r << ( ) and the input operator o p e r a t o r » ( ), the relational
operators o p e r a t o r < () and o p e r a t o r = = () can be function members of R ock. However, making
them member functions introduces an asymmetry in a relation which is intrinsically symmetric. We can
make a comparison like
s a m p le == GRANITE
but we cannot make the reverse expression
GRANITE == sample
Thus, it seems best to make these operators nonmember functions.
Overload o p e r a t o r < () and o p e r a t o r = = () to compare two R o ck objects. Each should have two
constant reference parameters of type R o ck and return one of the b o o l values t r u e or f a l s e . Your
parameters will look, for example, like c o n s t R ock & a R o c k l.
When you have finished overloading the operators, you should test them by commenting out or removing
the lines " BEGIN PART 9 ' ' a n d "END PART 9" in r o c k t e s t e r . cpp. Then recompile R o c k .c p p
and r o c k t e s t e r . cp p , link, and execute.
Check here when the relational operators execute correctly
Step 10: What’s Going On Here?
So far you’ve compared R o c k s —for example, r o c k l < ro c k 2 .
You might want to compare a R ock object with a RockNam e—for
example, r o c k < GRANITE. To see what happens when you try
this, do the following:
WARNING:
MAY NOT WORK
AS YOU EXPECT
1) Comment out or remove the lines labeled "BEGIN PART 10" and "END PART 10" in
r o c k t e s t e r . cpp.
2) Recompile and link R o c k . c p p and r o c k t e s t e r . c p p and execute the resulting binary executable.
3) Describe any errors you encounter in this part o f the program.
What? No problems! Why is that?
The compiler appears to have done some work for you. What has happened is similar to what happens
when numbers of different types are compared. For example, in the mixed-type expression
d o u b le _ v a lu e < i n t_ v a lu e
the i n t value gets converted {promoted) to a d o u b le value so that two d o u b le values are compared:
d o u b le _ v a lu e < in t_ v a lu e _ c o n v e r te d _ to _ d o u b le
To see this process in operation do the following:
1) Insert an output statement like c o u t «
constructor.
"R ock C o n s t r u c t o r \ n " ; in your explicit-value
2) Recompile and link R o c k . c p p and r o c k t e s t e r . c p p and execute the program.
3) Describe below your conclusion about how a RockName value gets converted to a R ock object.
62
Project 4.1 More Classy Rocks—Continuation of Lab 4.1
Application of your Rock Class
—
Bar-Graph Generator
Now that you have a tested R ock class with quite a few capabilities, it’s time to use it in an application: a
bar-graph generator program like that in Project 2.2. You will run the program with the same data file,
R o c k f i l e .t x t that was used there. You should get a copy of this file using the procedure specified by
your instructor. (It can be downloaded from the website whose URL is given in the preface.)
Program Requirements
Write a program that uses your newly developed R o ck type. You will use the file R o c k f i l e . t x t for
input, which contains a random collection of rocks. The program you write should do the following:
1. Declare an integer array c o u n t [ ] whose indices are integers and all of whose elements are initialized
to 0.
2. Read names of rocks from the file R o c k F i l e . t x t , and for each rock, increment the appropriate
element of c o u n t [ ] by 1; for example, if the rock is B a s a l t , then c o u n t [BASALT] should be
incremented by 1. [Note that RockName values can be used as indices because each is associated with a
nonnegative integer.]
3. Display the elements of c o u n t as a histogram (bar graph) something like the following:
BASALT
XXXXXXXXXXXXXXX (15)
DOLOMITE
GRANITE
GYPSUM
LIMESTONE
MARBLE
OBSIDIAN
QUARTZITE
SANDSTONE
SHALE
XXXXX (5)
XXXXXXXXXXXX (12)
XXX (3)
XXXXXXXXXXXXXXXXXXXXXXXXXX (26)
XXXXXXXXXXXXXX (14)
XXXXXXX (7)
(0)
XX (2)
X (1)
where the length of each bar (the number of X’s) and the number in parentheses indicate the number of
times a rock with that name was found in the file.
But there are a couple of things to note:
(1) Objects of type R ock cannot be used as indices of an array because they are not integers. They are
R ock objects. In particular they cannot be used as indices for the array c o u n t.
R o c k N a m e enumerators can be used as indices because they are simply synonyms for integers. So
you can use the values returned by the accessor function name () as an index in expressions of
the form:
c o u n t[r o c k V a l. nam e()]
(2) You need an operation to increment R ock values so you can run loops over the range of R ock
values:
R ock r ;
f o r ( r = BASALT; r < ROCK_OVERFLOW; in c r e m e n t r t o n e x t r o c k )
{ ...
}
Note: The assignment of a RockName value to a R ock variable works for the same reason as the
comparison of a RockName value with a R ock value.
63
Project 4.1 More Classy Rocks—Continuation of Lab 4.1
One way to increment in the f or-loop would be to modify the n e x t () function from Lab 2.2
and Project 2.2 to make it a member function of the Rock class.
Rock r;
for (r = BASALT; r < ROCK_OVERFLOW; r = r.nextO)
{ ...
}
Another way, and the one you are to use, is to overload the ++ increment operator for class Rock
so you can write loops like:
Rock r;
for (r = BASALT; r < ROCK_OVERFLOW; ++r)
{ ...
}
To do this you need to overload o p e r a t o r + + () for class Rock. You need overload only the prefix
operator unless your instructor tells you to do both.
To overload the ++ operator, you distinguish between prefix ++ and postfix ++ as follows:
•
operator++() with no parameters is the prefix operator.
•
operator++ (int) with one int parameter is the postfix operator; no name need be
given to the int parameter because it is not actually used in the definition.
Now you ’re ready to go—do the following:
•
Add a prototype for o p e r a t o r + + () to the R ock class that has no parameters and that will
return a R ock value. This function should be a member function because it works “internally.”
•
The definition of o p e r a t o r + + () should be put in the R o c k . c p p file. This is accomplished in
two steps:
1. In the function heading, qualify its name as we do with all member functions.
2. Use statements like those in the definition of the n e x t () function from Lab 2.2 to find the
successor of the data member myName, but change the value of myName to the successor
value before you r e t u r n it.
Hand in the items listed on the grade sheet.
Project 4.1 More Classy Rocks—Continuation of Lab 4.1
Name:
Course Info:
Project 4.1 Grade Sheet
Hand in:
1.
This project handout with the answers filled in
2.
Printouts showing:
a. Listings of Rock.h and Rock.cpp
Note: Be sure your header file has complete opening documentation and
complete documentation of functions.
b. A demonstration that the class library and driver program compile and link okay
c. A sample run of the driver program
3.
Printouts showing:
a. A listing of the bar-graph program
b A demonstration that the class library and this program compile and link okay
c. A sample run of the bar-graph program from the application with the data file R o c k F i l e . t x t
Attach this erade sheet to vour printouts.
Category
Points Possible
Class Rock .......................................................................... (85)
Correctness of new operations........................................45
Structure/efficiency of functions.................................... 10
Opening documentation of Rock . h ...............................5
Specifications of functions............................................. 15
Style/readability...............................................................10
Driver program: Sample run—adequate testing................. 20
Subtotal..................................................................................105
Application program:............................................................. (75)
Correctness...................................................................... 40
Structure/efficiency.........................................................10
Documentation.................................................................10
Style/readability............................................................... 5
Sample run ......................................................................10
Subtotal.................................................................................. 75
Total........................................................................................180
65
Points Received
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.5 Linearized : No Tagged PDF : Yes Page Count : 16 Producer : ABBYY FineReader 12 Create Date : 2015:01:26 21:53:25Z Modify Date : 2015:01:26 21:53:25ZEXIF Metadata provided by EXIF.tools