Find Least Multiple Number in C++ with constructor
#include<iostream>
using namespace std;
class lcm
{
public:
lcm()
{
int num1,num2, lcm;
cout<<"Enter the number:";
cin>>num1>>num2;
lcm=num1*num2;
while(num1!=num2)
{
if(num1>num2)
{
num1=num1-num2;
}
else
{
num2=num2-num1;
}
}
cout<<"LCM="<<lcm/num1;
}
};
int main()
{
lcm obj;
return 0;
}
using namespace std;
class lcm
{
public:
lcm()
{
int num1,num2, lcm;
cout<<"Enter the number:";
cin>>num1>>num2;
lcm=num1*num2;
while(num1!=num2)
{
if(num1>num2)
{
num1=num1-num2;
}
else
{
num2=num2-num1;
}
}
cout<<"LCM="<<lcm/num1;
}
};
int main()
{
lcm obj;
return 0;
}
Find large number in c++ with constructor
#include<iostream>
using namespace std;
class lar
{
public:
lar()
{
int a,b,c;
cout<<"Enter the number: ";
cin>>a>>b>>c;
if(a>b)
{
if(a>c)
{
cout<< " A is largest number.";
}
else
{
cout<< " C is largest number.";
}
}
else if(b>c)
{
cout<< " B is largest number.";
}
else
{
cout<< " C is largest number.";
}
}
};
int main()
{
lar obj;
return 0;
}
How to find Palindromic number in C++ with Friend Function
#include<iostream>
using namespace std;
class pal
{
int num1,num2,t_num,sum=0;
public:
friend void Palindrome();
};
void Palindrome()
{
pal obj;
cout<<"Enter the number:";
cin>>obj.num1;
obj.num2=obj.num1;
do
{
obj.t_num=obj.num1%10;
obj.sum=(obj.sum*10)+obj.t_num;
obj.num1/=10;
}while(obj.num1>0);
if(obj.sum==obj.num2)
{
cout<<"Palindrome.";
}
else
{
cout<<" Not Palindrome.";
}
}
int main()
{
Palindrome();
return 0;
}
How to find An Armstrong number in C++ with Constructor
#include<iostream>
using namespace std;
class ars
{
public:
ars()
{
int num1,num2,t_num,sum=0;
cout<<"Enter the number:";
cin>>num1;
num2=num1;
do
{
t_num=num1%10;
sum+=(t_num*t_num*t_num);
num1/=10;
}while(num1>0);
if(sum==num2)
{
cout<<"Armstrong:";
}
else
{
cout<<" Not Armstrong :";
}
}
};
int main()
{
ars obj;
return 0;
}
/*Write a program using constructor and destructor to find how many customer of a bank is a not a student and cut him or her 10% service charges every month.
Hints-****if customer monthly transaction limit is bellow 20000 then he or she is a student.
****take monthly limit as a input then check whether he or she is a student or not.
****then take balance input and if he or she is not a student cut him or her 10 % service charge and show final balance.
****inputs will be in constructor and calculations and outputs will be in destructor...*/
#include <iostream>
using namespace std;
class cls
{
int dpst,limit;
public:
cls()
{
cout << "Enter Monthly Limit : ";
cin >> limit;
cout << "Enter Deposit : ";
cin >> dpst;
}
~cls()
{
if(limit<20000)
{
cout << "Balance is = " << dpst;
}
else
{
dpst -= ((dpst*10)/100);
cout << "Balance is = " << dpst;
}
}
};
int main()
{
cls obj;
return 0;
}
No comments:
Post a Comment