Coding Mechanics
Tuesday, October 16, 2012
Use of COUNT function in Oracle
There might be situation like you want to delete some records from the table if the count is greater than 0.
Query :
DELETE from SAMPLETABLE where SAMPLEFIELD = 'XYZ' and (select count(SAMPLEFIELD) from SAMPLETABLE where SAMPLEFIELD = 'XYZ') > 0;
Wednesday, February 8, 2012
Make Protected variable of Base class Public using derived class object
class Base
{
protected:
int baseVairable;
};
class Derived:public Base
{
public:
Base::baseVairable;
};
int main(int argc, _TCHAR* argv[])
{
Derived d;
d.baseVairable = 20;
cout<<"Printing Base variable :"<<d.baseVairable;
return 0;
}
Factorial Program in C/C++
long Factorial(int number)
{
if (number <= 0 )
return 0;
if(number == 1 )
return 1;
else
return number * Factorial(number - 1);
}
Template member function inside template class is possible in C++
class X {
public:
void Print()
{
cout<<endl<<"Executing X class Print function";
}
};
template <class T>
class Test
{
T a;
public:
template <class T> void Print(T b)
{
cout<<endl<<"Executing Test class Print function";
b.Print();
}
};
How to print ASCII values in C/C++ using for loop
for(unsigned int i = 0 ; i< 256;i++ )
{
cout<<i<<" "<<(char)i;
if(i%4 == 0 )
cout<<endl;
}
Tuesday, February 7, 2012
String Reverse Function in C/C++
Logic used :
Swap First and Last characters.
{
size_t size = strlen(pStr);
if(size)
{
char pTemp;
for(int i = 0,j = size-1, k = size/2; i < k ; i++,j--)
{
pTemp = pStr[i];
pStr[i] = pStr[j];
pStr[j] = pTemp;
}
}
}
Subscribe to:
Posts (Atom)