Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stdio.h>
- using namespace std;
- class Vector {
- int x, y;
- public:
- Vector();
- Vector(int _x, int _y);
- Vector operator+(Vector u);
- Vector operator-(Vector u);
- Vector operator*(int t);
- Vector operator/(int t);
- void scan() {
- cin >> x >> y;
- }
- void print() {
- cout << "(" << x <<", " << y << ")" << endl;
- }
- int getX() {
- return x;
- }
- int getY() {
- return y;
- }
- void setX(int _x) {
- x = _x;
- }
- void setY(int _y) {
- y = _y;
- }
- };
- int cross(Vector u, Vector v);
- Vector::Vector() {
- /// TODO:
- }
- Vector::Vector(int _x, int _y) {
- /// TODO:
- }
- Vector Vector::operator+(Vector u) {
- /// TODO:
- }
- Vector Vector::operator-(Vector u) {
- /// TODO:
- }
- Vector Vector::operator*(int t) {
- /// TODO:
- }
- Vector Vector::operator/(int t) {
- /// TODO:
- }
- int cross(Vector u, Vector v) {
- /// TODO:
- }
- int updateScore(Vector u, int x, int y, char error[]) {
- if(u.getX() != x || u.getY() !=y) {
- cout <<"! "<<error<<" !"<< endl;
- return 0;
- }
- return 1;
- }
- int grader() {
- int score = 0;
- cout << "DEFAULT CONSTRUCTOR:\n";
- Vector u, v;
- cout << "By default u and v both are set to (0, 0)"<<endl;
- u.print();
- v.print();
- score += updateScore(u, 0, 0, "Problem with default constructor");
- score += updateScore(v, 0, 0, "Problem with default constructor");
- cout << "press any key!";
- getchar();
- cout << "\n\n";
- cout << "PARAMETERIZED CONSTRUCTOR:\n";
- Vector du(4, 2);
- Vector dv(2, 0);
- du.print();
- dv.print();
- score += updateScore(du, 4, 2, "Problem with parameterized constructor");
- score += updateScore(dv, 2, 0, "Problem with parameterized constructor");
- cout << "press any key!";
- getchar();
- cout << "\n\n";
- cout << "+ OPERATOR:\n";
- cout << "Setting the new value of u to (10, 2)"<<endl;
- u.setX(10); u.setY(2);
- cout << "New value of u"<<endl;
- u.print();
- u = u + du;
- cout << "u vector is increased by another vector du(4, 2)"<<endl;
- u.print();
- score += updateScore(u, 14, 4, "Problem with +operator")*3;
- cout << "press any key!";
- getchar();
- cout << "\n\n";
- cout << "- OPERATOR:\n";
- cout << "Setting the new value of v to (6, 8)"<<endl;
- v.setX(6); v.setY(8);
- v.print();
- v = v - dv;
- cout << "v vector is decreased by another vector dv(2, 0)"<<endl;
- v.print();
- score += updateScore(v, 4, 8, "Problem with -operator")*2;
- cout << "press any key!";
- getchar();
- cout << "\n\n";
- cout << "CROSS PRODUCT:\n";
- cout << "value of cross product of vector u and v"<<endl;
- int c = cross(u, v);
- cout << c << endl;
- score += updateScore(Vector(96, 0), c, 0, "Problem with cross product");
- cout << "value of cross product of vector v and u"<<endl;
- c = cross(v, u);
- cout << c << endl;
- score += updateScore(Vector(-96, 0), c, 0, "Problem with cross product");
- cout << "press any key!";
- getchar();
- cout << "\n\n";
- cout << "*OPERATOR:\n";
- cout << "u vector is scaled up by a scaler 3"<<endl;
- u = u * 3;
- u.print();
- score += updateScore(u, 42, 12, "Problem with *operator")*2;
- cout << "press any key!";
- getchar();
- cout << "\n\n";
- cout << "/OPERATOR:\n";
- cout << "v vector is scaled down by a scaler 2"<<endl;
- v = v / 2;
- v.print();
- score += updateScore(v, 2, 4, "Problem with /operator")*2;
- cout << "press any key!";
- getchar();
- cout << "\n\n";
- return score;
- }
- void report() {
- Vector u, v;
- cout << "REPORT:\n";
- int id;
- cout << "Your student ID: ";
- cin >> id;
- u.setX((id%13)*2);
- u.setY((id%23)*2);
- v.setX((id%29)*2);
- v.setY((id%11)*2);
- cout << "New value of u and v set according to your input"<<endl;
- u.print();
- v.print();
- cout << "area of parallelogram formed by point (0, 0), (u.x, u.y) and (v.x, v.y)!"<<endl;
- double area = cross(u, v);
- cout << area << endl;
- cout << "4'th point of parallelogram formed by point (0, 0), (u.x, u.y) and (v.x, v.y)!!"<<endl;
- Vector w = u + v;
- w.print();
- cout << "Can you determine the intersecting points of the arcs of the parallelogram!!!"<<endl;
- /// TODO:
- w.print();
- return;
- }
- void test() {
- Vector u(4, 6), v(-2, 4), w;
- w = u + v;
- w.print();
- w = u - v;
- w.print();
- w = u / 2;
- w.print();
- w = v * 2;
- w.print();
- cout << cross(u, v) << endl;
- u.setX(20);
- u.print();
- cout << v.getX() << " " << v.getY() << endl;
- return;
- }
- int main() {
- test();
- report();
- cout<< "Your score of the assignment: " << grader() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement