Advertisement
kaysar

Untitled

Jun 4th, 2017
755
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.85 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdio.h>
  3. using namespace std;
  4.  
  5.  
  6. class Vector {
  7.     int x, y;
  8. public:
  9.     Vector();
  10.     Vector(int _x, int _y);
  11.     Vector operator+(Vector u);
  12.     Vector operator-(Vector u);
  13.     Vector operator*(int t);
  14.     Vector operator/(int t);
  15.  
  16.     void scan() {
  17.         cin >> x >> y;
  18.     }
  19.     void print() {
  20.         cout << "(" << x <<", " << y << ")" << endl;
  21.     }
  22.     int getX() {
  23.         return x;
  24.     }
  25.     int getY() {
  26.         return y;
  27.     }
  28.     void setX(int _x) {
  29.         x = _x;
  30.     }
  31.     void setY(int _y) {
  32.         y = _y;
  33.     }
  34. };
  35.  
  36. int cross(Vector u, Vector v);
  37.  
  38. Vector::Vector() {
  39.     /// TODO:
  40. }
  41.  
  42. Vector::Vector(int _x, int _y) {
  43.     /// TODO:
  44. }
  45.  
  46. Vector Vector::operator+(Vector u) {
  47.     /// TODO:
  48. }
  49.  
  50. Vector Vector::operator-(Vector u) {
  51.     /// TODO:
  52. }
  53.  
  54. Vector Vector::operator*(int t) {
  55.     /// TODO:
  56. }
  57.  
  58. Vector Vector::operator/(int t) {
  59.     /// TODO:
  60. }
  61.  
  62. int cross(Vector u, Vector v) {
  63.     /// TODO:
  64. }
  65.  
  66.  
  67. int updateScore(Vector u, int x, int y, char error[]) {
  68.     if(u.getX() != x || u.getY() !=y) {
  69.         cout <<"! "<<error<<" !"<< endl;
  70.         return 0;
  71.     }
  72.     return 1;
  73. }
  74.  
  75. int grader() {
  76.     int score = 0;
  77.     cout << "DEFAULT CONSTRUCTOR:\n";
  78.     Vector u, v;
  79.     cout << "By default u and v both are set to (0, 0)"<<endl;
  80.     u.print();
  81.     v.print();
  82.     score += updateScore(u, 0, 0, "Problem with default constructor");
  83.     score += updateScore(v, 0, 0, "Problem with default constructor");
  84.     cout << "press any key!";
  85.     getchar();
  86.     cout << "\n\n";
  87.  
  88.  
  89.     cout << "PARAMETERIZED CONSTRUCTOR:\n";
  90.     Vector du(4, 2);
  91.     Vector dv(2, 0);
  92.     du.print();
  93.     dv.print();
  94.     score += updateScore(du, 4, 2, "Problem with parameterized constructor");
  95.     score += updateScore(dv, 2, 0, "Problem with parameterized constructor");
  96.     cout << "press any key!";
  97.     getchar();
  98.     cout << "\n\n";
  99.  
  100.  
  101.     cout << "+ OPERATOR:\n";
  102.     cout << "Setting the new value of u to (10, 2)"<<endl;
  103.     u.setX(10); u.setY(2);
  104.     cout << "New value of u"<<endl;
  105.     u.print();
  106.     u = u + du;
  107.     cout << "u vector is increased by another vector du(4, 2)"<<endl;
  108.     u.print();
  109.     score += updateScore(u, 14, 4, "Problem with +operator")*3;
  110.     cout << "press any key!";
  111.     getchar();
  112.     cout << "\n\n";
  113.  
  114.  
  115.     cout << "- OPERATOR:\n";
  116.     cout << "Setting the new value of v to (6, 8)"<<endl;
  117.     v.setX(6); v.setY(8);
  118.     v.print();
  119.     v = v - dv;
  120.     cout << "v vector is decreased by another vector dv(2, 0)"<<endl;
  121.     v.print();
  122.     score += updateScore(v, 4, 8, "Problem with -operator")*2;
  123.     cout << "press any key!";
  124.     getchar();
  125.     cout << "\n\n";
  126.  
  127.  
  128.     cout << "CROSS PRODUCT:\n";
  129.     cout << "value of cross product of vector u and v"<<endl;
  130.     int c = cross(u, v);
  131.     cout << c << endl;
  132.     score += updateScore(Vector(96, 0), c, 0, "Problem with cross product");
  133.     cout << "value of cross product of vector v and u"<<endl;
  134.     c = cross(v, u);
  135.     cout << c << endl;
  136.     score += updateScore(Vector(-96, 0), c, 0, "Problem with cross product");
  137.     cout << "press any key!";
  138.     getchar();
  139.     cout << "\n\n";
  140.  
  141.  
  142.     cout << "*OPERATOR:\n";
  143.     cout << "u vector is scaled up by a scaler 3"<<endl;
  144.     u = u * 3;
  145.     u.print();
  146.     score += updateScore(u, 42, 12, "Problem with *operator")*2;
  147.     cout << "press any key!";
  148.     getchar();
  149.     cout << "\n\n";
  150.  
  151.  
  152.     cout << "/OPERATOR:\n";
  153.     cout << "v vector is scaled down by a scaler 2"<<endl;
  154.     v = v / 2;
  155.     v.print();
  156.     score += updateScore(v, 2, 4, "Problem with /operator")*2;
  157.     cout << "press any key!";
  158.     getchar();
  159.     cout << "\n\n";
  160.  
  161.  
  162.     return score;
  163. }
  164.  
  165.  
  166. void report() {
  167.     Vector u, v;
  168.  
  169.     cout << "REPORT:\n";
  170.     int id;
  171.     cout << "Your student ID: ";
  172.     cin >> id;
  173.     u.setX((id%13)*2);
  174.     u.setY((id%23)*2);
  175.     v.setX((id%29)*2);
  176.     v.setY((id%11)*2);
  177.  
  178.     cout << "New value of u and v set according to your input"<<endl;
  179.     u.print();
  180.     v.print();
  181.  
  182.     cout << "area of parallelogram formed by point (0, 0), (u.x, u.y) and (v.x, v.y)!"<<endl;
  183.     double area = cross(u, v);
  184.     cout << area << endl;
  185.  
  186.     cout << "4'th point of parallelogram formed by point (0, 0), (u.x, u.y) and (v.x, v.y)!!"<<endl;
  187.     Vector w = u + v;
  188.     w.print();
  189.  
  190.     cout << "Can you determine the intersecting points of the arcs of the parallelogram!!!"<<endl;
  191.     /// TODO:
  192.     w.print();
  193.  
  194.     return;
  195. }
  196.  
  197.  
  198. void test() {
  199.     Vector u(4, 6), v(-2, 4), w;
  200.     w = u + v;
  201.     w.print();
  202.     w = u - v;
  203.     w.print();
  204.     w = u / 2;
  205.     w.print();
  206.     w = v * 2;
  207.     w.print();
  208.     cout << cross(u, v) << endl;
  209.     u.setX(20);
  210.     u.print();
  211.     cout << v.getX() << " " << v.getY() << endl;
  212.     return;
  213. }
  214.  
  215. int main() {
  216.     test();
  217.     report();
  218.     cout<< "Your score of the assignment: " << grader() << endl;
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement