Learn Object Oriented Programming (OOP) in C++ / সি++ Here
23.11.14
OOP : Excercise-10 : Check palindrome. Use Inheritance
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 using namespace std; class pc { public: void setget(int n) { get=n; } protected: int get; }; class number:public pc { public: int n1,rev=0,rem,n; int devide() { n1=n; while(n>0) { rem=n%10; rev=rev*10+rem; n=n/10; } } int check() { if(n1==rev) cout<<"palindrome number"; else cout<<"not palindrome number"; } }; int main() { number nb; int a; cin>>a; nb.setget(a); nb.check(); };
#include using namespace std; class palindrom { protected: int digit;
public: void setdigit(int n) { digit=n; }
}; class chkpalindrom : public palindrom { public: int a,b,c,sum=0,n;
int calc() { a=n%10; b=n%100; b=b/10; c=n/100; sum=a*100+b*10+c;
} int check() {
if(sum==n) cout<<"\nIt is a pelindrom number\n\n"; else cout<<"\nIt is not a pelindrom number\n\n"; } }; int main() { chkpalindrom cp; int n; cin>>n; cp.setdigit(n); cp.check(); }
nazmul alam 201420674 46th //C++ program : To check whether a given number is palindrome or not #include using namespace std; int main() { int n, num, digit, rev = 0; cout << "Enter a positive number: "; cin >> num; n = num; do { digit = num%10; rev = (rev*10) + digit; num = num/10; }while (num!=0); cout << " The reverse of the number is: " << rev << endl; if (n = = rev) cout << " The number is a palindrome"; else cout << " The number is not a palindrome";
#include using namespace std; class palindrome { public: void setinput(int a) { num=a; } protected: int num; }; class number:public palindrome { public: int i,r,rev=0; int devide() { r=num; while(r!=0) { i=r%10; rev=rev*10+i; r/=10; } }
int check() { if(num==rev) cout<<"It is palindrome"; else cout<<"It is not palindrome"; } }; int main() { number nmb; int s; cin>>s; nmb.setinput(s); nmb.devide(); nmb.check(); }
#include using namespace std; class palindrome { public: void setinput(int a) { num=a; } protected: int num; }; class number:public palindrome { public: int i,r,rev=0; int devide() { r=num; while(r!=0) { i=r%10; rev=rev*10+i; r/=10; } }
int check() { if(num==rev) cout<<"It is palindrome"; else cout<<"It is not palindrome"; } }; int main() { number nmb; int s; cin>>s; nmb.setinput(s); nmb.devide(); nmb.check(); }
#include
ReplyDeleteusing namespace std;
class pc
{
public:
void setget(int n)
{
get=n;
}
protected:
int get;
};
class number:public pc
{
public:
int n1,rev=0,rem,n;
int devide()
{
n1=n;
while(n>0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
}
int check()
{
if(n1==rev)
cout<<"palindrome number";
else
cout<<"not palindrome number";
}
};
int main()
{
number nb;
int a;
cin>>a;
nb.setget(a);
nb.check();
};
noted and found correct
Delete#include
ReplyDeleteusing namespace std;
class palindrome
{
public:
void setinput(int n)
{
num=n;
}
protected:
int num;
};
class number:public palindrome
{
public:
int i,t,rev=0;
int devide()
{
t=num;
while(t!=0)
{
i=t%10;
rev=rev*10+i;
t/=10;
}
}
int check()
{
if(num==rev)
cout<<"palindrome";
else
cout<<"not palindrome";
}
};
int main()
{
number nmb;
int a;
cin>>a;
nmb.setinput(a);
nmb.devide();
nmb.check();
}
Its correct
DeleteThis comment has been removed by the author.
ReplyDeleteplease do not copy.
Delete#include
ReplyDeleteusing namespace std;
class palindrom
{
protected:
int digit;
public:
void setdigit(int n)
{
digit=n;
}
};
class chkpalindrom : public palindrom
{
public:
int a,b,c,sum=0,n;
int calc()
{
a=n%10;
b=n%100;
b=b/10;
c=n/100;
sum=a*100+b*10+c;
}
int check()
{
if(sum==n)
cout<<"\nIt is a pelindrom number\n\n";
else
cout<<"\nIt is not a pelindrom number\n\n";
}
};
int main()
{
chkpalindrom cp;
int n;
cin>>n;
cp.setdigit(n);
cp.check();
}
its correct
DeleteName-Main Uddin
ReplyDeleteID-201421090
Batch-46
#include
using namespace std;
class AUB
{
public:
void IN(int F)
{
IO=F;
}
protected:
int IO;
};
class DIP:public AUB
{
public:
int iX,tNum,SetR;
int LDmain()
{
tNum=IO;
int SetR=0;
while(tNum!=0)
{
iX=tNum%10;
SetR=SetR*10+iX;
tNum/=10;
}
return SetR;
}
int check()
{
SetR=LDmain() ;
if(IO==SetR)
cout<<"palindrome Number";
else
cout<<"not palindrome Number";
}
};
int main()
{
DIP Dnum;
int Y;
cout<<"Enter The Number ";
cin>>Y;
Dnum.IN(Y);
Dnum.LDmain();
Dnum.check();
}
noted
DeleteDear Sir, Please visit:
ReplyDeletehttp://itlearn24.blogspot.com/2014/11/check-whether-given-number-is_29.html
reply and found correct
Deletenazmul alam
ReplyDelete201420674
46th
//C++ program : To check whether a given number is palindrome or not
#include
using namespace std;
int main()
{
int n, num, digit, rev = 0;
cout << "Enter a positive number: ";
cin >> num;
n = num;
do
{
digit = num%10;
rev = (rev*10) + digit;
num = num/10;
}while (num!=0);
cout << " The reverse of the number is: " << rev << endl;
if (n = = rev)
cout << " The number is a palindrome";
else
cout << " The number is not a palindrome";
system("pause");
return 0;
}
Mohammad Ashraful Hasan sobuj
ReplyDeleteCSE-46(Dip)
ID=201420656
#include
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();
}
#include
ReplyDelete#include
using namespace std;
class Circle {
private:
double radius;
string color;
public:
Circle(double r = 1.0, string c = "red") {
radius = r;
color = c;
}
double getRadius()
{
return radius;
}
string getColor()
{
return color;
}
double getArea()
{
return radius*radius*3.1416;
}
};
int main() {
Circle c1(1.2, "blue");
cout << "Radius=" << c1.getRadius() << " Area=" << c1.getArea()
<< " Color=" << c1.getColor() << endl;
Circle c2(3.4);
cout << "Radius=" << c2.getRadius() << " Area=" << c2.getArea()
<< " Color=" << c2.getColor() << endl;
Circle c3;
cout << "Radius=" << c3.getRadius() << " Area=" << c3.getArea()
<< " Color=" << c3.getColor() << endl;
return 0;
}
Md. Zulfikar Ali
ReplyDelete45th Batch
201410524
#include
#include
using namespace std;
class Circle {
private:
double radius;
string color;
public:
Circle(double r = 1.0, string c = "red") {
radius = r;
color = c;
}
double getRadius()
{
return radius;
}
string getColor()
{
return color;
}
double getArea()
{
return radius*radius*3.1416;
}
};
int main() {
Circle c1(1.2, "blue");
cout << "Radius=" << c1.getRadius() << " Area=" << c1.getArea()
<< " Color=" << c1.getColor() << endl;
Circle c2(3.4);
cout << "Radius=" << c2.getRadius() << " Area=" << c2.getArea()
<< " Color=" << c2.getColor() << endl;
Circle c3;
cout << "Radius=" << c3.getRadius() << " Area=" << c3.getArea()
<< " Color=" << c3.getColor() << endl;
return 0;
}
#include
ReplyDelete#include
using namespace std;
class Circle {
private:
double radius;
string color;
public:
Circle(double r = 1.0, string c = "red") {
radius = r;
color = c;
}
double getRadius()
{
return radius;
}
string getColor()
{
return color;
}
double getArea()
{
return radius*radius*3.1416;
}
};
int main() {
Circle c1(1.2, "blue");
cout << "Radius=" << c1.getRadius() << " Area=" << c1.getArea()
<< " Color=" << c1.getColor() << endl;
Circle c2(3.4);
cout << "Radius=" << c2.getRadius() << " Area=" << c2.getArea()
<< " Color=" << c2.getColor() << endl;
Circle c3;
cout << "Radius=" << c3.getRadius() << " Area=" << c3.getArea()
<< " Color=" << c3.getColor() << endl;
return 0;
}
md kashem
ReplyDeleteroll-201410856
#include
using namespace std;
class palindrome
{
public:
void setinput(int a)
{
num=a;
}
protected:
int num;
};
class number:public palindrome
{
public:
int i,r,rev=0;
int devide()
{
r=num;
while(r!=0)
{
i=r%10;
rev=rev*10+i;
r/=10;
}
}
int check()
{
if(num==rev)
cout<<"It is palindrome";
else
cout<<"It is not palindrome";
}
};
int main()
{
number nmb;
int s;
cin>>s;
nmb.setinput(s);
nmb.devide();
nmb.check();
}
md kashem
ReplyDeleteroll-201410856
#include
using namespace std;
class palindrome
{
public:
void setinput(int a)
{
num=a;
}
protected:
int num;
};
class number:public palindrome
{
public:
int i,r,rev=0;
int devide()
{
r=num;
while(r!=0)
{
i=r%10;
rev=rev*10+i;
r/=10;
}
}
int check()
{
if(num==rev)
cout<<"It is palindrome";
else
cout<<"It is not palindrome";
}
};
int main()
{
number nmb;
int s;
cin>>s;
nmb.setinput(s);
nmb.devide();
nmb.check();
}