Cube and Power without built-in functions Cpp / C++

This Cpp program is for using the Math functions without the Math.h class. This is a part of Mumbai University MCA Colleges C++ / CPP Programs MCA. 


The below program performs the operations of finding cube and power of a number without the built-in math functions. The Functions for the same are created by the programmer.

#include<iostream.h>
#include<conio.h>
#include<process.h>

class Math_1
{
int cu,num,base,pow,res;
public :
Math_1(){}
Math_1(int n)
{
num=n;
}
Math_1(int b,int p)
{
base=b;
pow=p;
}
~Math_1(){}
void cube();
void power();
};

void Math_1 :: cube()
{
cu=num*num*num;
cout<<endl;
cout<<"Cube of "<<num<<" : "<<cu;
}

void Math_1 :: power()
{

for(int i=0;i<pow;i++)
res=res*base;
cout<<endl;
cout<<"Result : "<<res;
}

void main()
{
int num,b,p,ch;
clrscr();
cout<<"1. Cube"<<endl;
cout<<"2. Power"<<endl<<endl;
cout<<"3. End";
while(1)
{
cout<<"\n\nEnter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter Number : ";
cin>>num;
Math_1 m1(num);
m1.cube();
break;

case 2:
cout<<"Enter Base : ";
cin>>b;
cout<<"Enter Power : ";
cin>>p;
Math_1 m2(b,p);
m2.power();
break;

default :
cout<<"Please Enter Right Choice.";
exit(0);

}
}
getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs and Simple Programs. Happy Programming and Studying.

No comments:

Post a Comment