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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
#include <iostream>
#include <math.h>
using namespace std;
#ifndef TRIGNO_H
#define TRIGNO_H
class trig
{
protected:
const float PI;
float* angle;
public:
trig() : PI(3.14159265)
{
angle = new float;
*angle = 0.0F;
}
trig(float a) : PI(3.14159265)
{
angle = new float;
*angle = a;
}
trig(const trig& t) : PI(3.14159265)
{
angle = new float(*t.angle);
}
trig& operator=(const trig& t)
{
*angle = *t.angle;
return *this;
}
void get_trig();
void display_trig() const;
};
#endif
void trig :: get_trig()
{
cout<<"Enter Angle Value : ";
cin>>*angle;
}
void trig :: display_trig() const
{
cout<<*angle<<endl;
}
#ifndef NUMBER_H
#define NUMBER_H
class number
{
protected:
int *num;
public:
void vertfunc()
{ }
number()
{
num = new int;
*num = 0;
}
number(int n)
{
num = new int;
*num = n;
}
void get();
number(const number& n)
{
num = new int(*n.num);
}
number& operator=(const number& n)
{
*num = *n.num;
return *this;
}
void print() const;
int* getnum()
{return num;}
~number() {
delete num;
}
};
#endif
void number :: get()
{
cout<<"Please, Enter the number : ";
cin>>*num;
}
void number :: print() const
{
cout<<*num<<endl;
}
#ifndef CALCULATOR_H
#define CALCULATOR_H
class calculator : public number,public trig
{
public:
calculator() : number(),trig() {}
calculator(float a) : number(),trig(a) {}
calculator(int n,float a) : trig(a),number(n) {}
calculator(const calculator& c1) : number(*c1.num),trig(*c1.angle)
{}
calculator& operator=(const calculator& c1)
{
*num = *c1.num;
*angle = *c1.angle;
return *this;
}
calculator operator+(const calculator&);
calculator operator-(const calculator&);
calculator operator*(const calculator&);
calculator operator/(const calculator&);
void sinTheta() const;
void cosTheta() const;
void tanTheta() const;
void sinInverse() const;
void cosInverse() const;
void tanInverse() const;
void vertfunc(){}
int factorial();
float square() const;
float cube() const;
float sqroot();
float power(float* x, float* y);
float logarithm();
float natural_log();
~calculator() {
}
};
#endif
calculator calculator :: operator+(const calculator& c1)
{
return calculator((*num) + (*c1.num),*angle);
}
calculator calculator :: operator-(const calculator& c1)
{
return calculator(*angle,(*num) - (*c1.num));
}
calculator calculator :: operator*(const calculator& c1)
{
return calculator(*angle,(*num) * (*c1.num) );
}
calculator calculator :: operator/(const calculator& c1)
{
return calculator(*angle,(*num) / (*c1.num));
}
void calculator :: sinTheta() const
{
float deg = *angle * 180.0F/PI;
float ans = sin(deg);
cout<<"sin("<<deg<<") : "<<ans<<endl;
}
void calculator :: cosTheta() const
{
float deg = *angle * 180.0F/PI;
float ans = cos(deg);
cout<<"cos("<<deg<<") : "<<ans<<endl;
}
void calculator :: tanTheta() const
{
float deg = *angle * 180.0/PI;
float ans = tan(deg);
cout<<"tan("<<deg<<") : "<<ans<<endl;
}
void calculator :: sinInverse() const
{
float ans = asin(*angle) * 180.0 * PI;
cout<<"sin Inverse("<<*angle<<") : "<<ans<<endl;
}
void calculator :: cosInverse() const
{
float ans = acos(*angle) * 180.0 * PI;
cout<<"sin Inverse("<<*angle<<") : "<<ans<<endl;
}
void calculator :: tanInverse() const
{
float ans = atan(*angle) * 180.0 * PI;
cout<<"sin Inverse("<<*angle<<") : "<<ans<<endl;
}
int calculator :: factorial()
{
for(int i=*num-1; i>0; i--)
*num *= i;
return *num;
}
float calculator :: square() const
{
return (*angle) * (*angle);
}
float calculator :: cube() const
{
return (*angle) * (*angle) * (*angle);
}
float calculator :: sqroot()
{
float sq = sqrt(*angle);
return sq;
}
int main()
{
calculator c1,c2,c3;
c1.get();
c2.get();
c3 = c1 + c2;
c3.print();
std::getchar();
std::getchar();
}
|