Adding functions in to C++ code
Hello I have a pythagDistance function and i am unsure how to enter it into my main code. Any ideas would be great. This is my main code:
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 155 156 157 158
|
class point1DClass
{
private:
int x;
public:
point1DClass(); // constructor function
point1DClass(int x);
int getx(); //Accessor function
void setx(int newx); // Mutator function
~point1DClass(); //Destructor function
};
/////////////////////////////////////
//// Member function implementation//
/////////////////////////////////////
point1DClass::point1DClass(int x)
{
setx(newx);
x=0;
}
void point1DClass::setx(int newx)
{
x = newx;
}
int point1DClass::getx()
{
return x;
}
point1DClass::~point1DClass()
{
cout << "Object Going Out of Scope!" << endl;
}
class point2DClass:public point1DClass
{
private:
int y;
public:
point2DClass(); // constructor
point2DClass(int x,int y);
void sety(int newy); // Mutator function
int gety(); //Accessor function
~point2DClass();
};
/////////////////////////////////////
//// Member function implementation///
/////////////////////////////////////
point2DClass::point2DClass(int x, int y)
{
setx(newx);
sety(newy);
y = 0;
}
void point2DClass::sety(int newy)
{
y = newy;
}
int point2DClass::gety()
{
return y;
}
point2DClass::~point2DClass()
{
cout << "Object Going Out of Scope!" << endl;
}
class point3DClass:public point2DClass
{
private:
int z;
public:
point3DClass(); // Constructor function
point3DClass(int x, int y, int z);
//
void setz(int newz); // Mutator function
//
int getz();
~point3DClass();
};
/////////////////////////////////////
//// Member function implementation///
/////////////////////////////////////
point3DClass::point3DClass(int x, int y, int z)
{
setx(newx);
sety(newy;)
setz(newz);
z = 0;
}
void point3DClass::setz(int newz)
{
z = newz;
}
int point3DClass::getz()
{
return z;
}
point3DClass::~point3DClass()
{
cout << " Object Going Out of Scope!" << endl;
}
point3DClass(int newx, int newy, int newz)
{
x=newx;
y=newy;
z=newz;
}
//////////////////////////////////////////////////
//////Main Function Implementation///////////////
///////////////////////////////////////////////////
int main()
{
point1DClass x;// create an object
x.setx (3);
cout << "x co-ordinate: " << x.getx() <<"\n"<<endl;
point2DClass y;
y.sety (4);
cout<<"y co-ordinate:" << y.gety() <<"\n"<<endl;
point3DClass z;
z.setz (8);
cout <<"z co-ordinate:" << z.getz() <<"\n"<<endl;
point3DClass z(1,2,3);
system("pause");
return 0;
}
|
This is my pythagDistance function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
#include <string>
#include<math.h>
using namespace std;
int main(void)
{
int x,y,z;
z=sqrt(x*x +y*y);
cout<<"The Hypotenuse is "<<z<<"\n";
system("pause");
return 0;
}
|
Topic archived. No new replies allowed.