首页 > > 详细

programming留学生讲解、辅导C/C++程序语言、讲解C/C++设计讲解R语言编程|讲解R语言编程

Important message on plagiarism
The single most important point for you to realize before the beginning of your studies
at ShanghaiTech is the meaning of “plagiarism”:
Plagiarism is the practice of taking someone else's work or ideas and passing them off
as one's own. It is the misrepresentation of the work of another as your own. It is
academic theft; a serious infraction of a University honor code, and the latter is your
responsibility to uphold. Instances of plagiarism or any other cheating will be reported
to the university leadership, and will have serious consequences. Avoiding any form of
plagiarism is in your own interest. If you plagiarize and it is unveiled at a later stage
only, it will not only reflect badly on the university, but also on your image/career
opportunities.
Plagiarism is academic misconduct, and we take it very serious at ShanghaiTech. In the
past we have had lots of problems related to plagiarism especially with newly arriving
students, so it is important to get this right upfront:
You may…
• … discuss with your peers about course material.
• … discuss generally about the programming language, some features, or abstract lines
of code. As long as it is not directly related to any homework, but formulated in a
general, abstract way, such discussion is acceptable.
• … share test cases with each other.
• … help each other with setting up the development environment etc.
You may not …
• … read, possess, copy or submit the solution code of anyone else (including people
outside this course or university)!
• … receive direct help from someone else (i.e. a direct communication of some lines
of code, no matter if it is visual, verbal, or written)!
• … give direct help to someone else. Helping one of your peers by letting him read
your code or communicating even just part of the solution in written or in verbal form
will have equal consequences.
• … gain access to another one’s account, no matter if with or without permission.
• … give your account access to another student. It is your responsibility to keep your
account safe, always log out, and choose a safe password. Do not just share access to
your computer with other students without prior lock-‐out and disabling of automatic
login functionality. Do not just leave your computer on without a lock even if it is just
for the sake of a 5-‐minute break.
• … work in teams. You may meet to discuss generally about the material, but any work
on the homework is to be done individually and in privacy. Remember, you may not
allow anyone to even just read your source code.
With the Internet, "paste", and "share" are easy operations. Don’t think that it is easy to
hide and that we will not find you, we have just as easy to use, fully automatic and
intelligent tools that will identify any potential cases of plagiarism. And do not think
that being the original author will make any difference. Sharing an original solution
with others is just as unethical as using someone else’s work.
CS100 Homework 6 (Fall, 2019)
This homework focuses on use of STL containers and class templates, virtual classes
and polymorphism, as well as code structuring.
Percentage of this homework over the whole score: 11%
Submission deadline: 2019-12-1 23:59
General Note for Homework 6
In this homework, you may need to write large classes with lots of member variables
or functions. In addition to getting the correct answer, an additional requirement for
this homework is to make your codes well organized. It is achieved by putting
different classes into different files, splitting the header files(*.h or *.hpp) and
source files(*.cpp), and linking them together correctly using #include lines. Your
header files should contain correct include guards. Please do not use #pragma once,
as some compilers may not recognize it.
In other words, you may need to submit multiple files, each functioning as a part of
your whole project. For each part of code, we will specify which file it should be put
into. Violating the specification may result in point deduction or cause errors.
Problem 1: A Template Set
 Basic Concepts
A set is a collection of distinct objects. By “distinct”, we mean that there are no
duplicate objects in a set. An example of a set of integers, similar to what you have all
learned in mathematics, is represented as {3, -1, 2147483647, 0}. However, we want
our set to be more versatile, and therefore we are making it a template class. In
general, the declaration of the set class looks like:
template
class CustomSet {};
The reason we name it CustomSet instead of Set is that “Set” may be identified as a
keyword by some editors.
For the objects in your CustomSet, it is recommended to store them in an STL
container, either a vector or a list, at your free choice.
We have provided the declarations and descriptions of all functions you need to
implement. See below or see the skeleton code we provided:
template
class CustomSet
{
public:
// Constructors and destructor:
CustomSet();
// Default constructor
CustomSet(const CustomSet& other);
// Copy constructor. Should construct a copy of "other".
CustomSet(T arr[], int size);
// Constructor using an array.
// Note that if there are duplicates in the array, you should ignore them.
// And then the size of your "CustomSet" will be different from the "size" given!
~CustomSet();
// Destructor. Pay attention to memory leaks!
// Other member functions:
int size();
// Returns the size of the set.
bool add(const T& item);
// If "item" is already in the set, return false.
// Otherwise, add it to the set and return true.
T* find(const T& item);
// If an object in the set equals "item", return a pointer to it.
// If "item" is not found, return nullptr(NULL).
bool erase(const T& item);
// If "item" is not in the set, return false.
// Otherwise, erase it from the set and return true.
CustomSet intersection(const CustomSet& other);
// This function returns the intersection of two sets (*this and other).
// In other words, the set of all objects that is in both *this and other.
// If there is no intersection, just return an empty set.
void sortSet();
// This function sorts the objects in the set in ascending order.
// Directly using (std::)sort is enough, if you are using an STL container.
void printSet();
// This function prints the set, seperating elements by { , , , }.
// For example, Assume you've added 2, 4, -2, and 800 to the set, in this order.
// This function will print: "{2, 4, -2, 800}\n"
// Note that there are spaces between a comma(,) and the next object.
// Print a newline at the end. (indicated by the '\n' above)
// Operators:
CustomSet operator+ (const T& item);
CustomSet operator+ (const CustomSet& that);
CustomSet& operator+= (const T& item);
CustomSet& operator+= (const CustomSet& that);
// The operator+ and operator += are overloaded.
// They can be understood intuitively, or consider this:
// A set "plus" an item means adding in the item.
// A set "plus" a set means taking the union of two sets.
// However, the difference between + and += is not written here.
// Try to figure out on your own!
CustomSet operator- (const T& item);
CustomSet operator- (const CustomSet& that);
CustomSet& operator-= (const T& item);
CustomSet& operator-= (const CustomSet& that);
// The operator- and operator -= are overloaded.
// They can be understood intuitively, or consider this:
// A set "minus" an item means erasing the item.
// A set A "minus" a set B means subtracting B from A, or namely, A\B.
// However, the difference between - and -= is not written here.
// Try to figure out on your own!
CustomSet

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!