-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClasses.cpp
More file actions
63 lines (55 loc) · 1.11 KB
/
Classes.cpp
File metadata and controls
63 lines (55 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//Libraries
#include<bits/stdc++.h>
//Class
class V3{
private:
double x, y, z;
double length(){
return(sqrt(x*x+y*y+z*z));
}
public:
//Default constructor which takes no arguments (More generally this will
//be used);
V3(){
x=0.0;y=0.0;z=0.0;
return;
}
//Non-default Constructor of a class.
V3(double dx, double dy, double dz){
x=dx;y=dy;z=dz;
}
//Copy constructor
V3(const V3 &src){
x=src.x;
y=src.y;
z=src.z;
}
//Destructor
~V3(){
if(length()==0.0)
std::cout<<"Zero vector"<<std::endl;
return;
}
//Member Functions
V3 scale(double const factor){
V3 v;
v.x=factor*x;
v.y=factor*y;
v.z=factor*z;
return v;
}
void printLength(){
std::cout<<"The length of the vector is "<<length();
return;
}
V3 sum(V3 const &b){
V3 v;
v.x=x+b.x;
v.y=y+b.y;
v.z=z+b.z;
return v;
}
};
signed main(){
return 0;
}