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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#include <iostream>
using namespace std;
//class
class Vector2D
{
protected:
int x,y;
public:
Vector2D();
Vector2D(int&,int&);
~Vector2D();
//override
void printdot();
void printcross();
};
Vector2D::Vector2D()
{
x=y=0;
}
Vector2D::Vector2D(int& a,int& b) : x(a),y(b) // constructor another form of initializing
{
}
Vector2D::~Vector2D() //destructor
{
}
void Vector2D::printdot()
{
cout << "The dot product is ";
}
void Vector2D::printcross()
{
cout << "The cross product is " << "<";
}
class Vector3D:public Vector2D //inheriting all the traits from the mother. this child acts like his mother.
{
private:
int z;
public:
Vector3D(int &, int &, int&);
~Vector3D();
void dotprod(Vector3D);
void crossprod();
};
Vector3D::Vector3D(int &x, int &y, int&z) : Vector2D(x,y)
{
cout << "Values for your Vectors: <" << x << ", " << y << ", " << z << ">" << endl;
}
Vector3D::~Vector3D()
{
}
void Vector3D::dotprod(Vector3D obj)
{
int scalar;
printdot();
scalar = x + obj.y;
cout << scalar;
}
void Vector3D::crossprod()
{
int component1,component2,component3;
printcross();
}
//non member functions
void heading();
void userinput(int& a,int& b,int& c,int& d,int& e,int& f);
//main
int main()
{
int a,b,c,d,e,f;
heading();
int repeat = 1;
do{
userinput(a,b,c,d,e,f);
Vector3D objV(a,b,c);
Vector3D objS(d,e,f);
objV.dotprod(objS);
cout << endl;
cout << "Are you finished? Press 0 to quit, if you want to continue press any number: ";
cin >> repeat;
}while(repeat != 0);
return 0;
}
void heading()
{
cout << "This program will calculate the dot product and cross product of your inputs <a,b,c>, <d,e,f>" << endl;
}
void userinput(int& a_,int& b_,int& c_,int& d_,int& e_,int& f_)
{
int a,b,c,d,e,f;
cout << "Enter a: ";
cin >> a_;
cout << "Enter b: ";
cin >> b_;
cout << "Enter c: ";
cin >> c_;
cout << "Enter d: ";
cin >> d_;
cout << "Enter e: ";
cin >> e_;
cout << "Enter f: ";
cin >> f_;
}
|