Showing posts with label Cplusplus. Show all posts
Showing posts with label Cplusplus. Show all posts

Function Overloading

Code:
#include<iostream>
#include<conio.h>
#include<stdio.h>


using namespace std;// not discussed yet.
// Prototype, Declaration
int Tax_Amount(int house_Sq);
int Tax_Amount(int house_Sq, int Vehicle_CC);
int Tax_Amount(int house_Sq, int Vehicle_CC, char Comercial);

void main(void)
{
int hsq;
int VCC;
char com;
cout<<"\n\n_________Well Come to CDGK Taxation Department System __________ ";
cout<<"\n\n Plesae Enter House SQ :";
cin>>hsq;
cout<<"\n\n Please Enter Vehicle CC : { Enter 0 for N/A } ";
cin>>VCC;
cout<<"\n\n Are These Property Use as Comercial:  { Press y = yes, n = no } ";
    cin>>com;
   // Function Calling Work:
if(VCC==0 && com=='n')
{
   int tax_Payable = Tax_Amount(hsq);
cout<<" \n\n Dear Customer Your Net Tax Payable Amount is :  "<<tax_Payable;
}
if(VCC>0 && com=='n')
{
   int tax_Payable = Tax_Amount(hsq,VCC);
cout<<" \n\n Dear Customer Your Net Tax Payable Amount is :  "<<tax_Payable;
}
if(VCC>0 && com=='y')
{
   int tax_Payable = Tax_Amount(hsq,VCC,com);
cout<<" \n Dear Customer Your Net Tax Payable Amount is :  "<<tax_Payable;
}

}

//Function Defination

int Tax_Amount(int house_Sq)
{
int Tax=(house_Sq*1000);
return Tax;

}

int Tax_Amount(int house_Sq, int Vehicle_CC)
{
     int Tax=(house_Sq*1000)+(Vehicle_CC*100);
return Tax;

}

int Tax_Amount(int house_Sq, int Vehicle_CC, char Comercial)
{
int Tax=(house_Sq*2000)+(Vehicle_CC*200);
return Tax;
}

Continue Reading

Generate Randam Number

Code:
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<cstdlib>
using namespace std;

int random(int);// Prototype
void main()
{
int a;
cout<<"\n Please enter how many random number you want to generate :";
    cin>>a;
random(a);
getch();

}

int random(int num)
{

if(num<=0)
{
return 0;
}
cout<<"\n ==>> "<<rand();
num--;
random(num);
}
Output:


Continue Reading

C++ Program to Check Whether it is Leap Year or Not

#include<iostream>
#include<conio.h>

using namespace std;

void main()
{
    start:

system("color 0B");

int year;

cout<<"\n\t*>*>*> CHECKING LEAP YEAR <*<*<*\n"<<endl;

cout<<"Enter The Year To Check Wheather it is Leap or Not :";
cin>>year;

if(year%4==0)
{
cout<<"\n\t\t>>> Leap Year <<<"<<endl;
}

else
{
cout<<"\n\t>>> Not Leap Year <<<"<<endl;
}

goto start;

getch();
}
Continue Reading

Simple Insertion Sort technique

void main()
{
int i,j,arr[100],temp=0;

cout<<"###INSERTION SORT###\n\n";

cout<<"Enter The Elements"<<endl;

for(i=0;i<5;i++)
{
cin>>arr[i];
}
cout<<"\n\nEntered Elements are"<<endl;
for(i=0;i<5;i++)
{
cout<<arr[i]<<",";
}
for(i=0;i<5;i++)
{
for(j=0;j<5-i;j++)
{
while(arr[j]<arr[j-1])
{
temp=arr[j-1];
arr[j-1]=arr[j];
arr[j]=temp;
}
}
}
cout<<"\n\nSorted Elements are"<<endl;
for(i=0;i<5;i++)
{
cout<<arr[i]<<",";
}
getch();
}
Continue Reading

Simple Bubble Sort Technique


void main()
{
int i,j,arr[100],temp=0;

cout<<"###BUBBLE SORT###\n\n";

cout<<"Enter The Elements"<<endl;

for(i=0;i<5;i++)
{
cin>>arr[i];
}

cout<<"\n\nEntered Elements are"<<endl;

for(i=0;i<5;i++)
{
cout<<arr[i]<<",";
}
for(i=0;i<5-1;i++)
{
for(j=0;j<5-1-i;j++)
{
while(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}

cout<<"\n\nSorted Elements are"<<endl;

for(i=0;i<5;i++)
{
cout<<arr[i]<<",";
}
getch();
}






Continue Reading

C++ Program for Fibonaci

#include<iostream>

using namespace std;

int fibonaci(int);
void main()

{
int i,n;

cout<<"Enter the No:";
cin>>n;

for(i=1;i<=n;i++)
{
cout<<fibonaci(i)<<" , ";
}

system("pause");
getchar();
}


int fibonaci(int a)
{

if(a==0)
{
return 0;
}
if(a==1)
{
return 1;
}
return fibonaci(a-1)+fibonaci(a-2);


}
Continue Reading

lenght of Given String


code:

#include<iostream>
#include<conio.h>
#include<stdio.h>

using namespace std;

void main()
{
       char str[100];
       int lenth=0;
       cout<<"enter string : ";
       cin.get(str,100);
       for(int i=0;str[i]!='\0';i++)

       {
              lenth++;
       }
       cout<<"the length of string  :"<<lenth;
     
  getch();
}


output:



Continue Reading

To Calculate the Frequency of given string

Code:
#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;

void main()
{
       char str[100], ch;
   int i, fre= 0;

   cout<<"Enter a string: ";
   gets(str);

   cout<<"Enter a character to find the frequency:";
   cin>>ch;

   for(i = 0; str[i] != '\0'; ++i)
   {
       if(ch == str[i])
           ++fre;
   }
cout<<"frequency of  "<<str<<"is:"<<fre;

   getch

Output:


Continue Reading

C++ Program To Create Your Own Header File

//Code .Cpp

#include<iostream>
#include"header.h" //Initialize header file which is created by any name

using namespace std;

void main()
{
int a=12,b=24,i=23,j=34,k=32,l=24,x=55,y=43;
int sum=0,sub=0,mul=0,div=0;

sum=add(a,b);
sub=subs(i,j);
mul=mull(k,l);
div=divv(x,y);
cout<<"Calculation\n\n";
cout<<"Sum is            :"<<sum<<endl;
cout<<"Subtracrion is    :"<<sub<<endl;
cout<<"Multiplication is :"<<mul<<endl;
cout<<"division is       :"<<div<<endl;

system("pause");
getchar();
}

//Code .header,h

#include<stdlib.h>

int add(int a,int b)
{
return a+b;
}
int subs(int i,int j)
{
return i-j;
}
int mull(int k,int l)
{
return k*l;
}
int divv(int x,int y)
{
return x/y;
}

Continue Reading

Using arrays of char and pointers to char

#include <iostream>
using namespace std;
int main()
{
cout << "Demonstrating arrays of char "
<< "and pointers to char.\n"
<< endl;
char text[] = "Good morning!",
name[] = "Bill!";
char *cPtr = "Hello "; // Let cPtr point
// to "Hello ".
cout << cPtr << name << '\n'
<< text << endl;
cout << "The text \"" << text
<< "\" starts at address " << (void*)text
<< endl;
cout << text + 6 // What happens now?
<< endl;
cPtr = name; // Let cPtr point to name, i.e. *cPtr
// is equivalent to name[0]
cout << "This is the " << *cPtr << " of " << cPtr
<< endl;
*cPtr = 'k';
cout << "Bill can not " << cPtr << "!\n" << endl;
return 0;
}
Continue Reading