fork(1) download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. const double EPSILON(1e-12);
  8.  
  9. // function prototypes
  10.  
  11. // ENTER FUNCTION PROTOTYPE FOR read_vector HERE.
  12. void read_vector(const double & prompt, double & x, double & y);
  13.  
  14. // ENTER FUNCTION PROTOTYPE FOR vector_length HERE.
  15. double vector_length (double x, double y);
  16.  
  17. // ENTER FUNCTION PROTOTYPE FOR write_vector HERE.
  18. void write_vector(const double & prompt, double & x, double & y);
  19.  
  20. // ENTER FUNCTION PROTOTYPE FOR vector_add HERE.
  21. void vector_add (double & x1, double & y1, double & x2, double & y2, double & x3, double & y3);
  22.  
  23. // ENTER FUNCTION PROTOTYPE FOR vector_subtract HERE.
  24. void vector_subtract (double & x1, double & y1, double & x2, double & y2, double & x3, double & y3);
  25.  
  26. // ENTER FUNCTION PROTOTYPE FOR scalar_mult HERE.
  27. void scalar_mult (double & x1, double & y1, double & s, double & x2, double & y2);
  28.  
  29. // ENTER FUNCTION PROTOTYPE FOR normalize HERE.
  30. void normalize (double & x, double & y);
  31.  
  32. // ENTER FUNCTION PROTOTYPE FOR perpendicular HERE.
  33. void perpendicular (double & x1, double & y1, double & x2, double & y2);
  34.  
  35. // *** DO NOT CHANGE ANY CODE IN THE MAIN FUNCTION.
  36. int main()
  37. {
  38. double u1, v1; // coordinates of first vector
  39. double u2, v2; // coordinates of second vector
  40. double u3, v3;
  41. double scalar;
  42.  
  43. read_vector("Enter first vector (2 floats): ", u1, v1);
  44. read_vector("Enter second vector (2 floats): ", u2, v2);
  45.  
  46. cout << "Enter scalar multiplier: ";
  47. cin >> scalar;
  48. cout << endl;
  49.  
  50. write_vector("First vector: ", u1, v1);
  51. write_vector("Second vector: ", u2, v2);
  52.  
  53. cout << endl;
  54.  
  55. vector_add(u1, v1, u2, v2, u3, v3);
  56. write_vector("Vector add: ", u3, v3);
  57.  
  58. vector_subtract(u1, v1, u2, v2, u3, v3);
  59. write_vector("Vector subtract: ", u3, v3);
  60.  
  61. scalar_mult(u1, v1, scalar, u3, v3);
  62. write_vector("Scalar multiplier: ", u3, v3);
  63.  
  64. cout << endl;
  65.  
  66. write_vector("First vector: ", u1, v1);
  67. write_vector("Second vector: ", u2, v2);
  68. perpendicular(u1, v1, u2, v2);
  69.  
  70. return(0);
  71. }
  72.  
  73. // DEFINE FUNCTION read_vector HERE.
  74.  
  75. void read_vector(const double & prompt, double & x, double & y)
  76. {
  77.  
  78. cout << prompt;
  79. cin >> x >> y;
  80. }
  81.  
  82. // DEFINE FUNCTION vector_length HERE.
  83.  
  84. double vector_length (double x, double y)
  85. {
  86. double v_length = sqrt(pow(x, 2) + pow(y, 2));
  87. return (v_length);
  88. }
  89.  
  90.  
  91. // DEFINE FUNCTION write_vector HERE.
  92.  
  93. void write_vector(const double & prompt, double & x, double & y)
  94. {
  95. cout << "(" << x << ", " << y << ") has length" << vector_length(x,y) << endl;
  96. }
  97.  
  98.  
  99. // DEFINE FUNCTION vector_add HERE.
  100.  
  101. void vector_add (double & x1, double & y1, double & x2, double & y2, double & x3, double & y3)
  102. {
  103. x3 = x1 + x2;
  104. y3 = y1 + y2;
  105. }
  106.  
  107. // DEFINE FUNCTION vector_subtract HERE.
  108.  
  109. void vector_subtract (double & x1, double & y1, double & x2, double & y2, double & x3, double & y3)
  110. {
  111. x3 = x1 - x2;
  112. y3 = y1 - y2;
  113. }
  114.  
  115. // DEFINE FUNCTION scalar_mult HERE.
  116.  
  117. void scalar_mult (double & x1, double & y1, double & s, double & x2, double & y2)
  118. {
  119. x2 = s * x1;
  120. y2 = s * y1;
  121. }
  122.  
  123. // DEFINE FUNCTION normalize HERE.
  124. void normalize (double & x, double & y)
  125. {
  126.  
  127. }
  128.  
  129. // DEFINE FUNCTION perpendicular HERE.
  130.  
  131. void perpendicular (double & x1, double & y1, double & x2, double & y2)
  132. {
  133.  
  134. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:43:58: error: invalid initialization of reference of type ‘const double&’ from expression of type ‘const char*’
     read_vector("Enter first vector (2 floats): ", u1, v1);
                                                          ^
prog.cpp:12:6: error: in passing argument 1 of ‘void read_vector(const double&, double&, double&)’
 void read_vector(const double & prompt, double & x, double & y);
      ^
prog.cpp:44:59: error: invalid initialization of reference of type ‘const double&’ from expression of type ‘const char*’
     read_vector("Enter second vector (2 floats): ", u2, v2);
                                                           ^
prog.cpp:12:6: error: in passing argument 1 of ‘void read_vector(const double&, double&, double&)’
 void read_vector(const double & prompt, double & x, double & y);
      ^
prog.cpp:50:42: error: invalid initialization of reference of type ‘const double&’ from expression of type ‘const char*’
     write_vector("First vector: ", u1, v1);
                                          ^
prog.cpp:18:6: error: in passing argument 1 of ‘void write_vector(const double&, double&, double&)’
 void write_vector(const double & prompt, double & x, double & y);
      ^
prog.cpp:51:43: error: invalid initialization of reference of type ‘const double&’ from expression of type ‘const char*’
     write_vector("Second vector: ", u2, v2);
                                           ^
prog.cpp:18:6: error: in passing argument 1 of ‘void write_vector(const double&, double&, double&)’
 void write_vector(const double & prompt, double & x, double & y);
      ^
prog.cpp:56:40: error: invalid initialization of reference of type ‘const double&’ from expression of type ‘const char*’
     write_vector("Vector add: ", u3, v3);
                                        ^
prog.cpp:18:6: error: in passing argument 1 of ‘void write_vector(const double&, double&, double&)’
 void write_vector(const double & prompt, double & x, double & y);
      ^
prog.cpp:59:45: error: invalid initialization of reference of type ‘const double&’ from expression of type ‘const char*’
     write_vector("Vector subtract: ", u3, v3);
                                             ^
prog.cpp:18:6: error: in passing argument 1 of ‘void write_vector(const double&, double&, double&)’
 void write_vector(const double & prompt, double & x, double & y);
      ^
prog.cpp:62:47: error: invalid initialization of reference of type ‘const double&’ from expression of type ‘const char*’
     write_vector("Scalar multiplier: ", u3, v3);
                                               ^
prog.cpp:18:6: error: in passing argument 1 of ‘void write_vector(const double&, double&, double&)’
 void write_vector(const double & prompt, double & x, double & y);
      ^
prog.cpp:66:42: error: invalid initialization of reference of type ‘const double&’ from expression of type ‘const char*’
     write_vector("First vector: ", u1, v1);
                                          ^
prog.cpp:18:6: error: in passing argument 1 of ‘void write_vector(const double&, double&, double&)’
 void write_vector(const double & prompt, double & x, double & y);
      ^
prog.cpp:67:43: error: invalid initialization of reference of type ‘const double&’ from expression of type ‘const char*’
     write_vector("Second vector: ", u2, v2);
                                           ^
prog.cpp:18:6: error: in passing argument 1 of ‘void write_vector(const double&, double&, double&)’
 void write_vector(const double & prompt, double & x, double & y);
      ^
stdout
Standard output is empty