Add organized the vector into header and implementation files
This commit is contained in:
@ -0,0 +1,7 @@
|
|||||||
|
#include <cmath>
|
||||||
|
#include "Vec3D.h"
|
||||||
|
|
||||||
|
int Vec3D::getLength()
|
||||||
|
{
|
||||||
|
return std::sqrt((x*x + y*y + z*z));
|
||||||
|
}
|
||||||
12
CM2005 Object Oriented Programming/Topic 2/2.6.1/Vec3D.h
Normal file
12
CM2005 Object Oriented Programming/Topic 2/2.6.1/Vec3D.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Vec3D
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int getLength();
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int z;
|
||||||
|
private:
|
||||||
|
int size = 3;
|
||||||
|
};
|
||||||
BIN
CM2005 Object Oriented Programming/Topic 2/2.6.1/a.exe
Normal file
BIN
CM2005 Object Oriented Programming/Topic 2/2.6.1/a.exe
Normal file
Binary file not shown.
27
CM2005 Object Oriented Programming/Topic 2/2.6.1/test.cpp
Normal file
27
CM2005 Object Oriented Programming/Topic 2/2.6.1/test.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
#include "Vec3D.h"
|
||||||
|
|
||||||
|
Vec3D vec1;
|
||||||
|
|
||||||
|
void doSomething()
|
||||||
|
{
|
||||||
|
vec1.x = 10;
|
||||||
|
vec1.y = 12;
|
||||||
|
vec1.z = 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
doSomething();
|
||||||
|
|
||||||
|
//std::cout << vec1.x << std::endl;
|
||||||
|
//std::cout << vec1.size << std::endl;
|
||||||
|
std::vector<Vec3D> coords;
|
||||||
|
coords.push_back(vec1);
|
||||||
|
//std::cout << coords[0].x << std::endl;
|
||||||
|
std::cout << coords[0].getLength() << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user