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();
}
//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();
}
#include
ReplyDelete#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);
}
incomplete program. submit again
DeleteMd.Hasmot Ali
ReplyDeleteID: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";
}
This is not OOP. Read question carefully
DeleteID:201421068
ReplyDeleteBatch: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";
}
This is not OOP. Read question carefully and submit again.
DeleteMd. Abdus Salam
ReplyDeleteID: 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;
}
This is not OOP. Change your program and submit again
DeleteMain Uddin
ReplyDeleteBatch -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;
}
correct it. submit it again using OOP(Inheritance)
DeleteHabibur Rahman
ReplyDeleteBatch-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;
}
correct it. submit it again using OOP(Inheritance)
DeleteMd : Jalis Mahmud
ReplyDeleteId : 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;
}
submit it again using OOP(Inheritance)
DeleteMD: Rashed Prodhania
ReplyDeleteBatch-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";
}
submit it again using OOP(Inheritance)
DeleteName-Main Uddin
ReplyDeleteid=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();
}
do not copy
DeleteName Main Uddin
ReplyDeleteid-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();
}
incomplete program. and plz do not copy from other submission.
Delete//Md. Imam Uddin
ReplyDelete//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;
}
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.
DeleteName-Main Uddin
ReplyDeleteid-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();
}
do not copy directly
Deletestrange number
ReplyDelete201420674
#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";
}
correct it. submit it again using OOP(Inheritance)
DeleteName-M.R.Awal Hossain
ReplyDeleteid-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();
}
noted
DeleteMohammad Ashraful Hasan sobuj
ReplyDeleteCSE-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;
}
Dear sir,
ReplyDeleteplease see the my blog...
http://www.sobujit.blogspot.com/2014/12/write-program-check-whether-given.html
#include
ReplyDeleteusing 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;
}
#include
ReplyDeleteusing 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;
}
sonia ferdusi
ReplyDelete45th 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;
}
//Name : Sumonto Kumer Ghosh
ReplyDelete//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;
}
#include
ReplyDeleteusing 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;
}
#include
ReplyDeleteMD.SAHIDULLAH
ID.201930055
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";
}
#include
ReplyDeleteFARJANA KAMAL KONOK
#201930701
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";
}
https://drive.google.com/file/d/128skuIc8lLDQgjumQGD1Op36MltnUKpm/view?usp=sharing
ReplyDeleteFARJANA KAMAL KONOK
ReplyDelete201930701
using namespace std;
int largestPrimeFactor(int n)
{
int max = -1;
while (n % 2 == 0) {
max = 2;
n >>= 1; // equivalent to n /= 2
}
for (int i = 3; i <= sqrt(n); i += 2) {
while (n % i == 0) {
max = i;
n = n / i;
}
}
if (n > 2)
max = n;
return max;
}
bool checkUnusual(int n)
{
int factor = largestPrimeFactor(n);
)
if (factor > sqrt(n)) {
return true;
}
else {
return false;
}
}
int main()
{
int n = 14;
if (checkUnusual(n)) {
cout << "YES"
<< "\n";
}
else {
cout << "NO"
<< "\n";
}
return 0;
}
//Using Inheritance
ReplyDelete//Nayem Hossain
//202010023
//Batch 63
#include
using namespace std;
class A
{
public:
int num;
int number()
{
cout<<"Enter your number for check: "<>num;
}
};
class B : public A
{
public:
int st()
{
int i,a,b,p=1;
while(num!=0)
{
a=num/10;
b=num%10;
cout<<b<<endl;
num=a;
for( i=2;i<b;i++)
{
if (b%i ==0)
{
p=0;
i=b;
}
}
}
if (p==1) cout<<"strange";
else
cout<<"Not strange";
}
};
int main()
{
B obj;
obj.number ();
obj.st();
return 0;
}
//Using Inheritance
ReplyDelete//Nayem Hossain
//202010023
//Batch 63
#include
using namespace std;
class A
{
public:
int num;
int number()
{
cout<<"Enter your number for check: "<>num;
}
};
class B : public A
{
public:
int st()
{
int i,a,b,p=1;
while(num!=0)
{
a=num/10;
b=num%10;
cout<<b<<endl;
num=a;
for( i=2;i<b;i++)
{
if (b%i ==0)
{
p=0;
i=b;
}
}
}
if (p==1) cout<<"strange";
else
cout<<"Not strange";
}
};
int main()
{
B obj;
obj.number ();
obj.st();
return 0;
}
\\Taslima akter
ReplyDelete\\id:202010462
\\Bathch :63
#include
using namespace std;
int main()
{
int a,b,number,p=1;
cin>>number;
while(number =0)
{
a=number/10;
b=number %10;
cout<<n<<endl ;
digit=a;
for(int i=2;i<n;i++)
{
if(n%i==0)
{
p=0;
i=n;
}
}
}
if(p==1)
cout<<"strange ";
else
cout<<"not strange";
}
//Murrshida akter
ReplyDelete// id:202010463
// bathch:63
#include
using namespace std;
int main()
{
int m,n,num,p=1;
cin>>num;
while(num=0)
{
m=num/10;
n=num%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 ";
}