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

19 comments:

  1. #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();
    };

    ReplyDelete
  2. #include
    using 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();
    }

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. #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();
    }

    ReplyDelete
  5. Name-Main Uddin
    ID-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();
    }

    ReplyDelete
  6. Dear Sir, Please visit:
    http://itlearn24.blogspot.com/2014/11/check-whether-given-number-is_29.html

    ReplyDelete
  7. 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";

    system("pause");
    return 0;
    }

    ReplyDelete
  8. Mohammad Ashraful Hasan sobuj
    CSE-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();
    }

    ReplyDelete
  9. #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;
    }

    ReplyDelete
  10. Md. Zulfikar Ali
    45th 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;
    }

    ReplyDelete
  11. #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;
    }

    ReplyDelete
  12. md kashem
    roll-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();
    }

    ReplyDelete
  13. md kashem
    roll-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();
    }

    ReplyDelete

Comment Here