首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
C++语言程序调试、辅导C++编程、讲解data留学生程序 解析Haskell程序|讲解留学生Processing
项目预算:
开发周期:
发布时间:
要求地区:
Homework 3 : C++ class inheritance
CIS111&EIE111 2021 Spring
1. Overview
The mechanism of C++ inheritance can represent the is-a relationships between concepts. The advantage of the inheritance mechanism include
avoiding repeated code, and useful behavior like polymorphic inheritance. The above picture shows an example of inheritance between concepts,
which is found from the web
[1]
In this homework, we will design the classes of the data storage family and show their inheritance relationships. Some of them are addressed in
homework 2 without mentioning their inheritance relationships.
The knowledge of chapters 13 and later in the textbook [1] will be helpful.
2. Designing a family of classes
2.1 The inheritance relationships
There are different data structures. Sometimes, a user does not care about the the sequential order of putting in an taking out data items, then we
can use some data structures like Bag. When a user care about sequential order of data, then Stacks and queues will be helpful. The above
picture shows a possible design of the classes, where each round-corner rectangle is a class, and an arrow points from a base class to a derived
class.
2.2 The provided code
Three C++ files are provided with this homework:
storage.h : the declarations of classes.
storage.cpp : the definitions of methods of the classes.
hmk3.cpp : the main function, which should test all the methods of the classes.
The comments and code in these files should provide detailed descriptions of the classes. A video explaining the code should also be provided
with this assignment. If you find some error of the provided code, or want to change some lines for some reason, clearly document your change as
comments in the code file, and mention your changes in the readme file.
2.3 Brief Descriptions of the classes
The classes shown on the above picture are described here.
Storage : It represent the fundamental features of a storage where data items can be put in or taken out. It is like the math concept of "Bag". All
the other classes are descendant of Storage , which means that all these classes can be used by a user to simply put int and take out data items.
Storage should a genuine abstract base class (GABC), which means it contains some pure virtual function (its prototype ends with = 0 ).
In the picture, all the classes at the leaf nodes are concrete (actual classes), which means all of their methods are defined and their objects can be
declared and created. Another concrete class is Array . Although it is possible to design an abstract class which is common ancestor of Array
and CircleArr, here wo let Array be the direct base class of CircleArr , to show that it is possible to have inheritance relationship between
concrete classes.
The other classes are GABC. They declare some methods without definitions. They work as some interface agreement.
The provided code only consider some most fundamental operations of classes, like:
- the array classes have the index operator [] .
- the stack classes have the push and pop operations.
- the queue classes have the enqueue and dequeue operations.
You can add more code to implement more operations.
Tasks of the homework
Provide the missing code (method definitions) in the file storage.cpp .
Add a method bool find(Item n) into the class Storage . It returns true if the Item n is found in the storage. Provide the missing
definitions of find in all the concrete descendant classes of Storage .
Design 3 public useful methods in some classes. Provide code for them.
Add more code in the main function in hmk3.cpp to test all the public methods of the classes.
Test the polymorphic inheritance behavior of the enqueue and dequeue operations of the queue classes.
Test the polymorphic inheritance behavior of the push and pop operations of the stack classes.
Test the polymorphic inheritance behavior of the [] operator of the array classes
Compile and run your program.
Fill the scores.xlxs file to report the results of your homework.
Submission
Deadline: June 5 11:00pm 2021
At most 3 students can form a group to do the homework together.
Clearly mention the names and classes of the group members at the top of the file scores.txt .
Only one member of the group need to submit the files
The other members can do nothing or to submit a readme.txt to confirm the names of group members
Submit the files at Moodle.
Only the source code (.cpp and .h), scores.xlxs , and a readme.txt should be submitted. If you want to add some screen shots and
images, you can replace readme.txt with readme.doc .
References
[1] "C++ Primer Plus", Stephen Prata, edition 6, ISBN:978-0321-77640-2, Pearson.
Appendix: A. Some design questions
We may face some questions that are difficult to answer when we try to express similarity between classes using the inheritance mechanism of
C++. Some of these questions are discussed below.
A.1 What is the type of a data item?
Ideally, we can record different types of data using the same code of classes. There are at least two possible choices to do so:
1. Design class templates, or use function templates, so that a data type can be represented as a variable.
2. Using C's solution void * to represent the undecided data type.
Choice of data type in this homework: In this homework, to simplify the work, let's focus on the inheritance mechanism, and do not require more
complex ways of handling general data types. Instead, we consider all data items are double . With the following statement in the program, we
can replace double with some other data type when we want to represent other types of data items.
typedef double Item;
This solution is simple, but the program requires recompilation.
A.2 Should we include a special field storage in the base class Storage ?
Conceptually, there is some storage representing all the data saved in the class, which is a common feature of all the derived classes in the family.
We could design a special member storage whose type is some template data type, or void * . There are some hard related questions: How to
declare such a member? What is its type?
To make the tasks simpler, this homework adopt the following policy:
In a base class, if the type of a data field is not decided, do not mention the data field. Only mention the methods that can access the data
field. Let a derived class add some data field with specific data type, and implement/overwrite the inherited methods to handle the data fields.
A.3 The different Node types in the single-linked list and double-linked list
We know that a node in a single linked node lacks a field prev , which is the address of the previous node in the list, comparing with a node in a
double-linked list. If we introduce How to properly deal with the similarity and difference between the two types of Nodes? One challenge is that if
two different node types are expressed, then the function prototypes will be different making the inheritance relationships between the two List
class difficult to describe.
There are possible solutions for this:
One way to deal with the different Node types is to use the template mechanism, designing some class templates where the Node type is a
type variable.
Another way is to introduce inheritance between two Node types. We can declare them as two classes with inheritance relationship. C++ also
allow inheritance between two structure ( struct ) types.
Choice of this homework:
Do not mention the Node type in the methods of the two List classes. Users do not need to know the existence of Nodes.
The two Lists are siblings derived from an abstract List class; they each have a private/protected Node type, and do not inherit the Node type
from each other.
Appendix B: Some rules of designing classes of inheritance
If some derived class (D) will define or override some inherited methods, then the method should be declared in the declaration of D.
Otherwise, compilation error.
For a class C, if one of its methods (inherited or self-declared) does not have a definition (inherited or self-defined), then C is abstract, and
cannot have on object. However. a pointer to C or reference to C is allowed.
C x; // not allowed
C* xp; // ok
C& xr; // tricky, can only appear as some member of a class of parameter type
If a method is declared in a class but does not have a definition provided by the class, the prototype of the method should have a suffix = 0 .
void function_no_def(void) = 0; // pure abstract function
Otherwise, compilation error, compiler will require a definition of a regular method
If a method declared in a Base class but will be implemented or overrode by by a derived class, it should be declared as virtual to support
polymorphic inheritance.
1. https://all-learning.com/understanding-the-concept-of-inheritance-in-c/ ↩
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!