The single most important point for you to realize before the beginning of your studies at ShanghaiTech
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:
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.
In this homework, you are required to do some simple Object-oriented programs with C++ programming language.
This homework contains 3 individual programs.
To encourage debugging locally and not on the OJ output (which is not right for practical programming), the OJ will not be available from the date the homework is released. It will gradually open until the submission deadline passes, and the schedule is:
In this Problem, we provide a base class named DataAnalyser. In this class, we’ve already implemented the constructor, destructor, and a virtual function called calculate, as shown below.
class DataAnalyser { public: DataAnalyser() {}; virtual ~DataAnalyser() {}; virtual float calculate(float* data, size_t size) { std::cout << "ERROR: Try to access virtual function in base class\n"; return ERRORCODE; }; };A virtual function which takes 2 parameters, the first one, data, is an array that need to be calculated, and the second one, size, is the size of the array, returns the calculated result.
You are required to implement 5 classes called MaximumAnalyser, MinimumAnalyser,AverageAnalyser, MedianAnalyser and StdDevAnalyser inherits from the given DataAnalyser (i.e. They are child classesof DataAnalyser), you need to overload the function calculate in these child classes.
Let
Then,
Here is the formula to calculate the standard deviation of data:
Let
Then,
where is the average number of data.
To make you debug easier, we provide a some useful codes for you, you can modify it as you want. The following codes should be added to your main function, so, DO NOT submit them to OJ.
/* You can change these numbers to whatever you want*/ float arr[] = {0.3, -100, 1, 2, 5, 6, 9, 12, 2}; DataAnalyser* foo = new MinimumAnalyser(); /* it can be any of the required 5 child classes */ std::cout << foo->calculate(arr, 9) << std::endl; /* should be -100 in this case */ delete foo;When submitting it to online judge, you need to submit the base class and 5 child classes you write, If you add additional includes, classes, functions, variables or definitions, please also submit them to OJ.
DO NOT submit the main() function, or compile errors will occur.
Description
Assume you are one of TAs of CS999. Oneday, Homework?? was released. It was a huge project which contains m different student informations, like name, email, or scores for each problem, etc. After the deadline, you need to collect all n students’ information and send the report to professor.C++ programming language代写
line contains information: these lines only contain bar-separators (“|”), informations (e.g. 100, GeZiWang, 1.233, OOP), and whitespaces (” “). There are at least one whitespaces between each “information” and “bar-separators”, and numbers are left-aligned.
separate-line: these lines only contain bar-separators (“|”) and minus signs (“-“). The “|”s should be aligned with other lines.
std::string provides you an operator <, so you will not need to write your own string comparison.
If you want to swap student a and student b, you should swap the whole row, not only the given column, otherwise the informations will be messed up.
e.g. if the data is
b 12
a 123
a 123
b 12
std::sort may be very useful for this requirement.
Hint: you can store all the informations as strings, instead of using multiple types.
For instance, the following report is the structured report of report shown above (sorting by col 0).C++ programming language代写
/——————————–\
| Honoka | 43253 | 65789 | 87912 |
|——–|——-|——-|——-|
| Kotori | 1.7 | foo | 44 |
|——–|——-|——-|——-|
| Umi | 20 | aa | 43 |
\——————————–/
and give the structured one. We also provide a template for you (as shown).
class ReportParser { public: // The constructor ReportParser(int numStudents, int numInfos); // The destructor ~ReportParser(); // read & write functions void readReport(); void writeStructuredReport(int sortOption); // Add your own functions and variables here private: // Add your own functions and variables here };Some functions are provided for you.
Submission
When submitting it to online judge, you should submit all your code except main(). If you add additionalincludes, classes, functions, variables or definitions, please also submit them to OJ.
DO NOT submit the main() function, or compile errors will occur.
Description
In this problem, you are required to implement a simple lookup table. This is, users has some variable , and a function f(x), they want to know what’s the result of . A simple idea is, we precalculate for all s, butthat’s not possible for a continuous function. But we can use sampling to discrete it, and use a vector to store these discrete (x, y) points.
i.e. values of f(x)=x2which start from 0, ends at 5 and increments by 1 can be stored as
x | 0 | 1 | 2 | 3 | 4 | 5
–|—|—|—|—|—-|—
y | 0 | 1 | 4 | 9 | 16 | 25
In the beginning (class constructor), we will give the start position x0, end position xn, and an increment . You need to calculate the f(x) value ranges from x=x0 to x=x0 with an increment dx
Then, users may input some arguments that they want to find the value of f(x).
For example, for f(x) , if some user input a number 2, you will output a number 4 because 22=4.
That is, if someone try to find , but there are no stored in your database. The two s which have least difference with is and , then the value of is given by the following formula:
For example, if someone tries to lookup 2.3 in the database shown above, then, we can get by the following formula:
We provide a pure virtual base class for you to do this job, you need to complete 3 classes inherits from this base class. The base class is like this:
class LookupTable { public: // constructor, start: start position; end: end position; increment: the increment "dx" // You should calculate the value in range [start, end], with increment "increment" LookupTable(double start, double end, double increment); // virtual destructor virtual ~LookupTable() = 0; // get the value f(x) of the given x virtual double getValue(double x) = 0; };Get the value of , where is the given argument double x. You need to return the value by searching in your database.
Your job is to implement 3 child classes (inherit from LookupTable) named SquareLookupTable, SinLookupTable, and LogLookupTable.
// is the same as
Requirements
Submission