## 9.11.14

### OOP : Excercise-5 : Check Whether the given number is Strange or Not.

Note: Use Inheritance to solve this program.

//check strange number using inheritance
‪#‎include‬<iostream>
using namespace std;
//base class
class strange
{
public:
void setdigit(int d)
{
digit=d;
}
protected:
int digit;
};
//derived class
class number : public strange
{
public:
int i,j,t=1,d;
int devide()
{
while(d!=0)
{
j=d%10;
d=d/10;
for(i=2;i<j;i++)
{
if(j%i==0)
{
t=0;
i=j;
}
}
}
}
int check()
{
if(t==1)
cout<<"this number is strange";
else
cout<<"this number is not strange";
}
};
int main()
{
number nmb;
int a;
cin>>a;
nmb.setdigit(a);
nmb.check();
}

1. #include
#include
using namespace std;
class CheckStrnge
{
public:
int strange (int s)
{
int r,n,p=1,i;
while(s!=0)
{
r=s%10;
n=s/10;
for(i=2 ;i>number;
Str.strange(number);
}

1. incomplete program. submit again

2. Md.Hasmot Ali
ID:201421066
Batch:46th

#‎include‬
using namespace std;
int main()
{
int m,n,number,p=1;
cin>>number;
while(number!=0)
{
m=numbert/10;
n=number%10;
cout<<n<<endl;
digit=m;
for(int i=2;i<n;i++)
{
if (n%i ==0)
{
p=0;
i=n;
}
}
}
if (p==1) cout<<"strange";
else
cout<<"Not strange";
}

1. This is not OOP. Read question carefully

3. ID:201421068
Batch:46th

#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 i=2;i<b;i++)
{
if (b%i ==0)
{
p=0;
i=b;
}
}
}
if (p==1) cout<<"strange";
else
cout<<"Not strange";
}

1. This is not OOP. Read question carefully and submit again.

4. Md. Abdus Salam
ID: 201420341
Batch: 46th

#include

using namespace std;

int determiner ( int Number )
{
if ( Number > 2 )
{
for ( int A = 2 ; A <= ( Number/2 ) ; A++ )
{
if ( Number % A == 0 )
return (0);
}
return (1);
}

}

int main ()
{
int Number;

cout<<" **Strange Number Checker**\n";
cout<<"Enter Number to check :";
cin>>Number;

if ( determiner ( Number ) )
cout<<"It is Strange"<<endl;
else
cout<<"Not Strange"<<endl;

cout<<endl;

}

1. This is not OOP. Change your program and submit again

5. Main Uddin
Batch -46
ID-201421090
#include

using namespace std;

int Prime ( int Num )
{
if ( Num > 2 )
{
for ( int i = 2 ; i <= ( Num/2 ) ; i++ )
{
if ( Num % i == 0 )
return (0);
}
return (1);
}
}

int main ()
{
int Num;

cin>>Num;

if ( Prime ( Num ) )
cout<<"Strange"<<endl;
else
cout<<"Not Strange"<<endl;

cout<<endl;

}

1. correct it. submit it again using OOP(Inheritance)

6. Habibur Rahman
Batch-46
ID-201421091

#include

using namespace std;

int StrangeNumber ( int digit )
{
if ( digit > 2 )
{
for ( int m = 2 ; m <= ( digit/2 ) ; m++ )
{
if ( digit % m == 0 )
return (0);
}
return (1);
}
}

int main ()
{
int digit;

cin>>digit;

if ( StrangeNumber ( digit ) )
cout<<"Strange"<<endl;
else
cout<<"Not Strange"<<endl;

cout<<endl;

}

1. correct it. submit it again using OOP(Inheritance)

7. Md : Jalis Mahmud
Id : 201420762
Batch :46th

#include

using namespace std;

int determiner ( int Number )
{
if ( Number > 2 )
{
for ( int N = 2 ; N <= ( Number/2 ) ; N++ )
{
if ( Number % N == 0 )
return (0);
}
return (1);
}

}

int main ()
{
int Number;

cout<<" **Strange Number Checker**\n";
cout<<"Enter Number to check :";
cin>>Number;

if ( determiner ( Number ) )
cout<<"It is Strange"<<endl;
else
cout<<"Not Strange"<<endl;

cout<<endl;

}

1. submit it again using OOP(Inheritance)

8. MD: Rashed Prodhania
Batch-46th
Id:201420763

#include
using namespace std;
int main()
{
int L,M,digit,p=1;
cin>>digit;
while(digit!=0)
{
L=digit/10;
M=digit%10;
cout<<M<<endl;
digit=L;
for(int i=2;i<b;i++)
{
if (b%i ==0)
{
p=0;
i=M;
}
}
}
// use if else statment
if (p==1) cout<<"This is Strange";
else
cout<<"This is Not Strange";
}

1. submit it again using OOP(Inheritance)

9. Name-Main Uddin
id=201421090
Batch-46
#include
using namespace std;
//base class
class strange
{
public:
void setdigit(int d)
{
digit=d;
}
protected:
int digit;
};
//derived class
class number : public strange
{
public:
int i,j,t,d;
int devide()
{
d=digit;
while(d!=0)
{
j=d%10;
d=d/10;
for(i=2;i>a;
nmb.setdigit(a);
nmb.check();
}

10. Name Main Uddin
id-201421090
Batch-46
#include
using namespace std;
//base class
class strange
{
public:
void setdigit(int d)
{
digit=d;
}
protected:
int digit;
};
//derived class
class number : public strange
{
public:
int i,j,t,d;
int devide()
{
d=digit;
while(d!=0)
{
j=d%10;
d=d/10;
for(i=2;i>a;
nmb.setdigit(a);
nmb.check();
}

1. incomplete program. and plz do not copy from other submission.

11. //Md. Imam Uddin
//CSE 46th Batch
//ID- 201420733

#include
#include
using namespace std;

class prime // Class Declaration

{
int a,b,c; //Varibale Declaration
public:

prime(int n)
{
a=n;
}
void calc() // Object Creation For Class
{
b=1;
{
for(c=2;c<=a/2;c++)
if(a%c==0)
{
b=0;
break;
}
else
{
b=1;
}
}
}

void show()
{
if(b==1)
cout<<"\n"<<" Number is Prime.";
else
cout<<"\n"<<" Number is Not Prime .";
}
};

int main() //Main Function
{
int a;
cout<<"Enter The Number:";
cin>>a;

prime ch(a);

ch.calc(); // Call Member Functions
ch.show();
getch();
return 0;
}

1. foundation for inheritance found. but lots of syntax error. check it and submit again. as like inside the "void calc()" function, there are no { (bracket) after for loop.

12. Name-Main Uddin
id-201421090
Batch-46

Writre a Program to find the Strange Number or not in C++ using Inheritance.

#include
using namespace std;
//base class
class strange
{
public:
void setdigit(int d)
{
digit=d;
}
protected:
int digit;
};
//derived class
class number : public strange
{
public:
int i,j,t,d;
int devide()
{
d=digit;
while(d!=0)
{
j=d%10;
d=d/10;
for(i=2;i>a;
nmb.setdigit(a);
nmb.check();
}

1. do not copy directly

13. strange number
201420674

#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";
}

1. correct it. submit it again using OOP(Inheritance)

14. Name-M.R.Awal Hossain
id-201421092
Batch-46
#include
#include
using namespace std;
class line
{
public:
inline float multi(float M,float N)
{
return(M*N);
}
inline float cube(float M)
{
return(M*M*M);
}
};
int 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();
}

CSE-46(Dip)
ID=201420656

#include
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;
}

16. Dear sir,
http://www.sobujit.blogspot.com/2014/12/write-program-check-whether-given.html

17. #include
using namespace std;
class cheackstrange
{
int num;
public:
cheackstrange();
~cheackstrange();
void view();
};
cheackstrange::cheackstrange()
{
cout<<"Enter the number\n";
cin>>num;
}
cheackstrange::~cheackstrange()
{
//cout<<"Destruction";
}
void cheackstrange::view()
{
int i,j,t=1;
{
while(num!=0)
{
j=num%10;
num=num/10;
for(i=2;i<j;i++)
{
if(j%i==0)
{
t=0;
i=j;
}
}
}
}

if(t==1)
cout<<"\n\nThis Number is strange\n\n";
else
cout<<"\n\nThis Number is Not Strange\n\n";
}

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

18. #include
using namespace std;

int strange(int digit)
{
int d,r;
while(digit!=0)

{
d=digit/10;
r=digit%10;
digit=d;
return r;
}
}

int main()
{
int digit,p=1,re;
cout<<"Enter number to check strange or not : ";
cin>>digit;
cout<<endl;
re=strange(digit);
for(int i=2;i<re;i++)
{
if (re%i ==0)
{
p=0;
i=re;
}
}
if (p==1)
cout<<"Yes!!"<<endl<<"Enter number is strange number"<<endl<<endl;
else
cout<<"Not!!"<<endl<<"Enter number is not a strange number"<<endl;

}

19. sonia ferdusi
45th batch
roll:201410285
#include
using namespace std;
class strange
{
int number;
public:
strange();
~strange();
void view();
};
strange:: strange()
{
cout<<"Enter the value\n";
cin>>number;
}
strange :: ~strange()
{

}
void strange :: view()
{
int b ,temp ,rev=0;
temp=number;
while(temp!=0)
{
b=temp%10;
rev=rev*10+b;
temp /=10;
}
if(rev==number)
cout<<"\nIt is a strange number\n\n";
else
cout<<"\nIt is not a strange number\n\n";

}
int main()
{
strange cp;

cp.view();
return 0;
}

20. //Name : Sumonto Kumer Ghosh
//ID : 201410848
//Batch : 45th

#include

using namespace std;

int Prime ( int Num )
{
if ( Num > 2 )
{
for ( int i = 2 ; i <= ( Num/2 ) ; i++ )
{
if ( Num % i == 0 )
return (0);
}
return (1);
}
}

int main ()
{
int Num;

cin>>Num;

if ( Prime ( Num ) )
cout<<"Strange"<<endl;
else
cout<<"Not Strange"<<endl;

cout<<endl;

}

21. #include
using namespace std;

class Parent
{
protected:
int chk;
public:
void strangeNum(int i){
int temp = i, mod = 0;
while (temp != 0){
mod = temp % 10;
temp = temp / 10;
for (int j = 2; j < mod; j++){
if (mod % j == 0){
chk = 0;
break;
}
}
}
}
};

class Child: public Parent
{
public:
void meth(){
if (chk == 0)
cout << "This is not a strange number.";
else
cout << "This is strange number.";
}
};
int main()
{
int i;
cout << "Enter number --: ";
cin >> i;
Child obj;
obj.strangeNum(i);
obj.meth();
return 0;
}

Comment Here