Lab11

advertisement
Lab 11
Question 1
Source Code: q1.cpp, image.h, image.cpp
In this question, you have to rewrite a programme of question 2 in lab 08.
However, you must use an object as Image class which have enough variables and
functions to do this task. Moreover, that object also contains a dynamic array to
store the content of image like that question.
Question 2
Source Code: q2.cpp, vector.h, vector.cpp
There is a list of vector operators which you must compute. Each vector operator
is written with the following format:
<vector> <operator> <vector>
where a vector is written as [ a1 a2 … an ] (elements are separated together by
space), and operator may be *, + or -.
For example:
[ 0 1 3 ] * [ 3 1 0 ]
[ 0 1 3 ] - [ 0 1 3 ]
[ 0 1 3 ] + [ 0 1 3 ]
Please write a programme read vectors operators from vector.inp file. After
that, evaluate them and write results into output file vector.out:
Input file: vector.inp
The first line writes an integer N which is the number of vector operators.
Subsequently, each line in N following lines contains a vector operator. All
1
attributes of vectors are integers in -1000…1000. It is known that all these
operators are valid or computable.
Output file: vector.out
For each vector operator in the input, write its result in a line of this output file.
vector.inp
vector.out
3
[ 0 1 3 ] * [ 3 1 0 ]
[ 0 1 3 ] - [ 0 1 3 ]
[ 0 1 3 ] + [ 0 1 3 ]
1
[ 0 0 0 ]
[ 0 2 6 ]
Hints:
 Try to use the new knowledge which have just learned such as friend class
or friend function, or/and overloading operators, …
2
Download