19.11.14

OOP : Excercise-8 : Check whether the given number is palindrome or not. Use individual member function to take input, output and display. Use Inheritance

Check whether the given number is palindrome or not. Use individual member function to take input, output and display. Use Inheritance or Constructor.

//Program using Constructor
#include<iostream>
using namespace std;
class checkpelindrom
{
int num;
public:
checkpelindrom();
~checkpelindrom();
void view();
};
checkpelindrom :: checkpelindrom()
{
cout<<"Enter the number\n";
cin>>num;
}
checkpelindrom :: ~checkpelindrom()
{
//cout<<"\n\nDestruction";
}
void checkpelindrom :: view()
{
int a ,temp ,rev=0;
temp=num;
while(temp!=0)
{
a=temp%10;
rev=rev*10+a;
temp /=10;
}
if(rev==num)
cout<<"\nIt is a pelindrom number\n\n";
else
cout<<"\nIt is not a pelindrom number\n\n";

}
int main()
{
checkpelindrom cp;
cp.view();
return 0;

}

27 comments:

  1. #include
    using namespace std;
    class checkpelindrom
    {
    int n;
    public:
    checkpelindrom();
    ~checkpelindrom();
    void show();
    };
    checkpelindrom :: checkpelindrom()
    {
    cout<<"constructing"<>n;
    a=n%10;
    b=n%100;
    b=b/10;
    c=n/100;
    sum=a*100+b*10+c;

    if(sum==n)
    cout<<"pelindrom\n\n";
    else
    cout<<"not pelindrom\n\n";

    }


    int main()
    {
    checkpelindrom cp;
    cp.show();
    return 0;
    }

    ReplyDelete
    Replies
    1. noted. try to solve the same problem using inheritence

      Delete
  2. #include
    using namespace std;
    class checkpelindrom
    {
    int n;
    public:
    checkpelindrom();
    ~checkpelindrom();
    void show();
    };
    checkpelindrom :: checkpelindrom()
    {
    cout<<"constructing"<>n;
    temp=n;
    while(temp!=0)
    {
    rem=temp%10;
    reverse=reverse*10+rem;
    temp/=10;
    }
    /* Checking if number entered by user and it's reverse number is equal. */
    if(reverse==n)
    cout<<" a palindrome\n";
    else
    cout<< "not a palindrome\n";

    }


    int main()
    {
    checkpelindrom cp;
    cp.show();
    return 0;
    }

    ReplyDelete
  3. #include
    using namespace std;
    class checkpelindrom
    {
    int num;
    public:
    checkpelindrom();
    ~checkpelindrom();
    void view();
    };
    checkpelindrom :: checkpelindrom()
    {
    cout<<"Enter the number\n";
    cin>>num;
    }
    checkpelindrom :: ~checkpelindrom()
    {
    //cout<<"\n\nDestruction";
    }
    void checkpelindrom :: view()
    {
    int a ,temp ,rev=0;
    temp=num;
    while(temp!=0)
    {
    a=temp%10;
    rev=rev*10+a;
    temp /=10;
    }
    if(rev==num)
    cout<<"\nIt is a pelindrom number\n\n";
    else
    cout<<"\nIt is not a pelindrom number\n\n";

    }
    int main()
    {
    checkpelindrom cp;
    cp.view();
    return 0;
    }

    ReplyDelete
    Replies
    1. noted. you did not changed anything. at least you can change the variable name and sequence from other persons. try to change something which is not similar to other person then compile and paste it here again.

      Delete
  4. #include
    using namespace std;
    class pc
    {
    int n,n1,rev=0,rem;
    public:
    pc();
    ~pc();
    void show();
    };
    pc::pc()
    {
    cin>>n;
    }
    pc::~pc()
    {
    cout<<"destruction";
    }
    void pc::show()
    {
    n1=n;
    while(n>0){
    rem=n%10;
    rev=rev*10+rem;
    n=n/10;
    }
    if(n1==rev)
    cout<<"pelindrome\n";
    else
    cout<<"not pelindrome\n";
    }
    int main()
    {
    pc pp;
    pp.show();
    }

    ReplyDelete
  5. ‪#‎include‬
    using namespace std;
    class palindrome
    {
    public:
    int num;
    palindrome();
    ~palindrome();
    void check();
    };
    palindrome::palindrome()
    {
    cin>>num;
    }
    palindrome::~palindrome()
    {
    cout<<"Destructing";
    }
    void palindrome::check()
    {
    int i, rev=0, temp;
    temp=num;
    while(temp!=0)
    {
    i = temp%10;
    rev = rev*10+i ;
    temp /= 10;
    }
    if(num==rev)
    {
    cout<<"It is a Palindrome";
    }
    else
    {
    cout<<"It is not a palindrome";
    }
    }
    int main()
    {
    palindrome pal;
    pal.check();
    }

    ReplyDelete
    Replies
    1. submit another comments after solve the same problem for string palindrome. you will get help at our c programming blog.

      Delete
  6. #include
    using namespace std;
    class checkpalindrome
    {
    public:
    int num;
    checkpalindrome();
    ~checkpalindrome();
    void check();
    };
    checkpalindrome::checkpalindrome()
    {
    cin>>num;
    }
    checkpalindrome::~checkpalindrome()
    {
    cout<<"/constructing";
    }
    void checkpalindrome::check()
    {
    int i, rev=0, temp;
    temp=num;
    while(temp!=0)
    {
    i = temp%10;
    rev = rev*10+i ;
    temp /= 10;
    }
    if(num==rev)
    {
    cout<<"It is a Palindrome number";
    }
    else
    {
    cout<<"It is not a palindrome number";
    }
    }

    int main()
    {
    checkpalindrome cpal;
    cpal.check();

    }

    ReplyDelete
    Replies
    1. noted. solve it using string palindrome. try to make some difference from others. at least variable name, sequence, syntax etc. as like you may use do-while instead of while.

      Delete
  7. sanchita das
    201420941

    #include
    using namespace std;
    int main()
    {
    int num,i,f,r,sum=0,temp;
    cout<<"Enter a number:";
    cin>>num;
    temp=num;
    while (num)
    {
    i=1,f=1;
    r=num%10;
    while(i<=r)
    {
    f=f*1;
    i++;
    }
    sum=sum+f;
    num=num/10;
    }
    if(sum==temp)
    cout<<temp<<"is not a strange number";
    else
    cout<<temp<<"is a strange number";
    return 0;
    }

    ReplyDelete
    Replies
    1. This program is correct but not appropriate for this question. Use inheritance or constructor and submit again.

      Delete
    2. You solved for strange number but in question i have asked for palindrome. check question properly

      Delete
  8. nazmul alam
    201420674
    strange number
    #include
    using namespace std;
    int main ()
    {
    int a,b,digit,p=1;
    cin>>digit;
    while(digit!=0)
    {
    a=digit/10;
    b=digit%10;
    cout<<b<<endl;
    digit=a;

    for(int j=2; j<b; j++)
    {
    if(b%j==0)
    {p=0;
    j=b;
    }}}
    if(p==1) cout<<"stange";
    else
    cout<<" not stange";
    }

    ReplyDelete
    Replies
    1. Its not correct answer for this question. please post carefully.

      Delete
  9. Name-M.H.Awal Hossain
    ID-201421092
    Bstch-46

    #include
    using namespace std;
    class DSE
    {
    public:
    void IN(int I)
    {
    Dnmb=I;
    }
    protected:
    int Dnmb;
    };
    class PR:public DSE
    {
    public:
    int X,Num,R;
    int Divmain()
    {
    Num=Dnmb;
    int R=0;
    while(Num!=0)
    {
    X=Num%10;
    R=R*10+X;
    Num/=10;
    }
    return R;
    }

    int check()
    {
    R=Divmain() ;
    if(Dnmb==R)
    cout<<"palindrome NO.";
    else
    cout<<"not palindrome NO.";
    }
    };
    int main()
    {
    PR REV;
    int Y;
    cout<<"Enter The Number ";
    cin>>Y;
    REV.IN(Y);
    REV.Divmain();
    REV.check();
    }

    ReplyDelete
  10. Dear sir, Please check my blog.
    http://itlearn24.blogspot.com/2014/11/check-whether-given-number-is_29.html

    ReplyDelete
  11. Name-Main Uddin
    ID-201421090
    Batch-46

    #include
    using namespace std;
    class AUB
    {
    public:
    void Logic(int X)
    {
    digit=X;
    }
    protected:
    int digit;
    };
    class CSE:public AUB
    {
    public:
    int X,Number,N;
    int DivFind()
    {
    Number=digit;
    int N=0;
    while(Number!=0)
    {
    X=Number%10;
    N=N*10+X;
    Number/=10;
    }
    return N;
    }

    int check()
    {
    N=DivFind() ;
    if(digit==N)
    cout<<"Number is palindrome";
    else
    cout<<" Number is not palindrome";
    }
    };
    int main()
    {
    CSE Credit;
    int q;
    cout<<"Entry Number : ";
    cin>>q;
    Credit.Logic(q);
    Credit.DivFind();
    Credit.check();
    }

    ReplyDelete
  12. Md abul kashem
    ID 201410856
    45th

    //split the digit using constructor
    #include
    using namespace std;
    class split
    {
    int xx;
    public:
    split();
    ~split();
    void display();
    };

    split :: split()
    {
    cout<<"please Enter a value : ";
    cin>>xx;
    }

    split :: ~split()
    {
    cout<<"Releasing Memory";
    }
    void split::display()
    {
    int a,b;
    while (xx!=0)
    {
    a=xx/10;
    b=xx%10;
    cout<<b<<endl;
    xx=a;
    }
    }
    int main()
    {
    split sh;
    sh.display();
    return 0;
    }

    ReplyDelete
  13. //Md abul kashem
    //ID 201410856
    // 45th


    //program to split digit using inheritence
    #include
    using namespace std;
    class split
    {
    public:
    void getvalue(int t)
    {
    xx=t;
    //cout<>s;
    sh.getvalue(s);
    sh.display();
    }

    ReplyDelete
  14. Excellent information and thanks for posting this here! Please keep sharing more information like this further in future. You can find more information on C++ Tutorials in the following link.

    Learn Cpp online

    ReplyDelete

Comment Here