Sunday, December 7, 2014

Write a program Check Perfect Number using Inheritence

#include<iostream>
using namespace std;

class perfect
{
public:
   void setelement(int value)
    {
        element =value;
    }
    protected: int element;
};

class chkelement: public perfect
{
public:
    int sum=0;
    void getperfect()
    {
     for(int i=1;i<element;i++)
    {
    if(element%i==0)
    {
    sum+=i;
    }
    }
    }

int chksum()
{
if (element==sum)
cout<<"Yes!!"<<endl<<"the element is perfect number"<<endl<<endl;
else
cout<<"Not!!"<<endl<<"the element is not a perfect number"<<endl;
}
};


int main()
{
chknelement per;
int value;
cout<<"the element to check perfect or not : ";
cin>>value;
per.setelement(value);
per.getperfect();
per.chksum();
return 0;
}

Search an element in an Array of 20 integer values. (i) Use one Constructor to get input on variable and array. (ii) Use one Constructor to Search the Array. (iii) Use a member function to display the result. (iv) Use Destructor in any suitable position.

#include
using namespace std;
class earray-search
{
public:
int elmt=0,x[20],inp,i;
earray();
~earray();
void proved();
};
earray::earray()
{
cout<<"the elements:"<>x[i];
}
earray::~earray()
{
cout<<"destructing"<>inp;
for(i=0;i<20;i++)
{
if(x[i]==inp)
{
cout<<"found"<<endl;
elmt=1;
break;
}
}
if(elmt==0)
cout<<"Not found"<<endl;
}
int main()
{
search-earray sa;
sa.proved();
}

Write a c++ program to count number of character in a given string

#include<iostream>
#include<string>
using namespace std;

int character (values v)
{
int charnum=v.size();
for(char i=0; i<v.size(); i++)
{
if(v.Location(i)== ' ')
{
charnum--;
}
if(v.Location(i)== '.')
  {
charnum--;
}
}
cout<<"Enter values has "<<charnum <<" Characters:"<<end;
}


int main()
{
values v;
char i;
cout<<"the type of a values: " ;
cin >> v
getline(v);
character(v);
return 0;
}

Write a c++ program to check whether the given number is odd or even


#include<iostream>
using namespace std;



void Even-Odd(int v)
{
if(v%2==0)
cout<<"the number is Even";
else
cout<<" the number is Odd";
}

int main()
{
int v;
cout<<"the number is check Even or Odd";
cin>>v;
Even-Odd(v);
Return 0;
}

Write a program of function to Sum of all even elements from an Array. The initial value of the array must take from main ( ) as input

#include <iostream>
    using namespace std;

    class evensum
    {
    public:
        void setvalue(int v)
        {
            value =v;
        }
        protected: int value;

    };

class mysum: public evensum
{
public:
    void getsum()
    {
    int temperature,i,a[100],sum=0;
    temperature=value;
    cout<<"Enter "<<temperature<< " values:  ";
    for(i=0;i<temperature; i++)
    {
    cin>>a[i];
    }
    for (i=0;i<temperature;i++)
    {
    if (a[i]%2==0)
    {
    sum+=a[i];
    }
    }
    cout<<"Sum of even values is : "<<sum<<endl;
    }
};
    int  main()
    {
    findsum xy;
    int v;
    cout<<"Enter size of the array: ";
    cin>>v;
    xy.setvalue(v);
    xy.getsum();
    return 0;
    }

Write a program Check whether the given number is palindrome or not. Use individual/separate member function to take input, output and display according to logic. Use Inheritance

#include<iostream>
using namespace std;
class palindrome
{
public:
void setvalue(int v)
{
value=v;
}
protected:
int value;
};
class value:public palindrome
{
public:
int i,t,rev=0;
int devide()
{
t=value;
while(t!=0)
{
i=t%10;
rev=rev*10+i;
t/=10;
}
}

int check()
{
if(value==rev)
cout<<"palindrome";
else
cout<<"not palindrome";
}
};
int main()
{
value v;
int x;
cin>>x;
v.setinput(x);
v.devide();
v.check();
}

Write a program Check Whether the given number is Strange or Not.

#include<iostream>
using namespace std;
int main ()
{
int X,Y,D,prime num=1;
cin>>D;
while(D!=0)
{
X=D/10;
Y=D%10;
cout<<Y<<endl;
D=X;

for(int j=2; j<Y; j++)
{
if(Y%j==0)
{prime num=0;
j=Y;
}
}
}
if(prime num==1) cout<<"stange";
else
cout<<" not stange";
return 0;
}

Write a C++ program to find area of triangle, circle,and rectangle using function overloading

#include<iostream>
using namespace std;

const float pi=3.14;
float area(float n,float b,float h)
float area(float x,float y,float z)
{
float ar;
ar=x*y*z;
cout<<"The area of Triangle : "<<ar<<endl<<endl;
}
float area(float n)
{
float ar;
ar=pi*n*n;
cout<<"The area of Circle : "<<ar<<endl<<endl;
}
float area(float l,float w)
{
float ar;
ar=m*w;
cout<<"The area of Rectangle :"<<ar<<endl;
}
int main()
{
float y,z,n,l,w;

cout<<"Enter the Base & Hieght of Triangle : ";
cin>>y>>z;
area(0.5,y,z);

cout<<"Enter the radius of circle :";
cin>>n;
area(n);


cout<<"Enter the Lenght & width of Rectangle: ";
cin>>l>>w;
area(l,w);
return 0;
}

Write a C++ program using class to calculate simple interest amount use default value for rate.

# include
# include
class bank
{
private:
float p;
float r;
float t;
float si;
float amount;
public:
void read ( )
{
cout <<" Principle Amount : ";
cin>>p ;
cout<<" Rate of Interest : ";
cin>>r;
cout <<" Number of years : ";
cin>>t;
si= (p *r*t) /100;
amount = si + p;
}
void show( )
{
cout<<"\n Principle Amount: "<<p;
cout <<"\n Rate of Interest: "<<r;
cout <<"\n Number of years: "<<t;
cout <<"\n Interest : "<<si;
cout <<"\n Total Amount : "<<amount;
}
};
void main ( )
{
clrscr ( );
bank b ;
b.read ( );
b.show ( );
getch();
}

write a program calculate square and cube of given number using inline function

#include
#include
class line
{
public:
inline float multi(float a,float b)
{
return(a*b);
}
inline float cube(float a)
{
return(a*a*a);
}
};
void main()
{
line obj;
float a1,b1;
clrscr();
cout<<"\n Enter Two Value ";
cin>>a1>>b1;
cout<<" Multiplication is :"<<obj.multi(a1,b1)<<endl;
cout<<" Cube of val1 is :"<<obj.cube(a1)<<endl;
cout<<" Cube of val2 is :"<<obj.cube(b1)<<endl;
getch();
}

Write a program performing as calculator which allows all Arithmetic Operators with operands as input

#include<iostream>
using namespace std;
main ()
{
int a,b,result;
string arithmatic;
cout<<"the first value:";
cin>>a;
cout<<"the second value:";
cin>>b;
cout<<"apply some artimatic operations /, *, + or - :";
cin>>arithmatic;
if (arithmatic="/" )
result=a/b;
cout<<"a / b ="<<result;
if (arithmatic = "*")
result=a*b;
cout<<"a * b ="<<result;
if (arithmatic = "+")
result = a + b;
cout<<"a+b ="<<result;
if (arithmatic = "-")
result = a-b;
cout<<"a-b ="<<result;
else
cout<<"how is that? enter the value use arithmatic operations!";

return 0;
}

WELLCOME

Welcome to my blog.