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 (Spring, 2021)
Submission deadline:
2021-05-24 23:59
We will implement a simple spreadsheet in this homework, which looks like the
Microsoft Excel. The following figure shows the basic structure of a spreadsheet. The
first row is called the Column Index (A, B, C, D, E, … in the figure), and the first
column is called the Row Index (1, 2, 3, 4, … in the figure). Each cell in this sheet
can be identified by a pair of Row Index and Column Index (The circled cell in this
figure is called B4 because its row index is 4 and column index is B). Each cell in a
spreadsheet can either be a number, a string or Empty. For example, Cell A2, B2, B3
and B4 in following sheet are string cells, Cell A1 and C4 are number cells, and the
others are Empty cells.
As you can imagine, Microsoft Excel is a very large project. But don’t worry, you are
only required implement a very simple spreadsheet in this homework – no GUIs, and
only basic functions (print the formatted sheet, sort the sheet by column, hide/display
rows and columns).
Also, our spreadsheet uses int (starts from 1) for both row and column indexes, here
is an example:
Problem 1. Spreadsheet Cells
The basic structure of our spreadsheet is that, each cell is a SpreadSheetCell object,
and the SpreadSheet class holds a 2-dimensional container of pointers to such cells.
In this sub-problem, we will implement SpreadSheetCell class and its derived classes.
The definition of the base class is:
class SpreadSheetCell
{
public:
SpreadSheetCell();
~SpreadSheetCell();
friend std::ostream& operator<<(std::ostream& os, const SpreadSheetCell& cell);
virtual bool operator<(const SpreadSheetCell& that) const;
CellType GetType() const;
protected:
CellType m_type;
};
This class should be an abstract class (i.e., it cannot be instantiated). It should at least
have these member functions:
- GetType(), returns the type of this cell. The return value is either
CellType::String or CellType::Number
- operator<, the operator used to compare this cell with another cell. The
comparison rules will be specified below.
Also, in order to conveniently print the content of each cell to std::cout (or any
std::ostream, like std::ofstream to print to a file), it is needed to overload the
operator<< of std::ostream. This has been declared for you:
friend std::ostream& operator<<(std::ostream& os, const SpreadSheetCell& cell);
Note that, although this function is declared within class SpreadSheetCell, it is not
a member function of the class. (This means if you define the function outside of your
class, specifying SpreadSheetCell:: for it will be an error.
Since this function is not a member of class SpreadSheetCell, the keyword friend
lets it access private or protected members of your class.
As mentioned before, a non-empty cell either contains strings or numbers (we use
double to store numbers in this homework). So, you need to implement two derived
classes called StringSpreadSheetCell and NumberSpreadSheetCell which inherits
from the base class. Please follow these instructions when implementing the derived
classes:
- String cells can only be constructed with string, and Number cells can only
be constructed with double.
- The GetType() function of StringSpreadSheetCell will return
CellType::String, and NumberSpreadSheetCell will return
CellType::Number.
- Printing contents (when operator<< is called)
For string cells, just print the content.
For number cells, you should print the content number with a precision
of 3 (use std::setprecision(3) when printing it).
* It’s guaranteed that the value in any number cell is between -1000 and
1000.
You should not print anything except the content (i.e., No additional ‘\n’
or spaces).
- Comparison (when operator< is called)
Comparison between number cells will just compare the content value.
Comparison between string cells will compare strings in lexicographical
order.
Number cells are always less than string cells.
*As the parameter of this operator< is a const SpreadSheetCell&, what you may
want to do could be first judge its type by GetType(), then create a pointer to it
and cast to a const pointer of a derived class1
. For example:
if (that.GetType() == CellType::Number)
{
const NumberSpreadSheetCell* ptr = (const NumberSpreadSheetCell*)(&that);
// Then use ptr as a pointer to a NumberSpreadSheetCell.
}
This test function may help you to realize how it works (the comment shows the
expected output and the reason).
void test()
{
std::vector