Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PATRA_Class_test
// C++ training #include <iostream> // 1. Write a template class for a 3D vector that holds (x,y,z) // 2. Define constructors // 3. Write a function to print the vector // 4. overload the operator+(), operator-(), operator*() class Vector { public: Vector (){}; Vector (double xx, double yy, double zz) { x=xx; y=yy; z=zz; } void print () { std::cout << "(" << x << "," << y << "," << z << ")" << std::endl; } Vector operator+(Vector rhs){ return Vector { x+rhs.x, y+rhs.y, z+rhs.z}; } private: double x; double y; double z; }; int main () { // Test your class here Vector v {2,3,4}; Vector w{1,4,3}; Vector n{0,7,5}; Vector a = v+w+n; a.print(); return 0; }
run
|
edit
|
history
|
help
0
DailyExchRate
kth smallest element in a matrix
union of two sorted array
Tower Of Hanoi
pbds
Karibu
map sort
Org
Test 1(2021)
pow implementation