Friday, January 23, 2009

C++ USEFUL PROGRAMS

c++ programs

1) // To SORT AN ARRAY USING POINTERS //

#include
#include

void main()
{
clrscr();
int size;
float *ptr,ar[50];
cout<<"\nEnter the total no. of elements (0-50) : ";
cin>>size;
if(size>50)
{
return;
}
for(int i=0;i{
cout<<"\nEnter the element "<cin>>ar;
}
for(i=0;i{
cout<<"\nElement "<}
getch();
//SORTING
 
ptr=ar;
float temp=0;
for(i=0;i{
for(int j=i;jif(*(ptr+j)>*(ptr+j+1))
{
temp=*(ptr+j);
*(ptr+j)=*(ptr+j+1);
*(ptr+j+1)=temp;
}
}
cout<<"\nThe sorted array is";

for(i=0;i{
cout<<"\nElement "<}
delete ptr; // delete
 OPERATOR
getch();

}
// OUTPUT //

Enter the total no. of element:5
Enter the element:11,23,18,9,32
The sorted array is 9,11,18,23,32


// PROGRAM TO GENERATE FIBONACCI SERIES USING CONS

// PROGRAM TO GENERATE FIBONACCI SERIES USING CONSTRUCTORs




#include
#include

class fibonacci
{
int p,c,n;

public:
fibonacci()
{
p=0;
c=1;
n=p+c;
}

void generate(int k);
};

void fibonacci :: generate(int k)
{
cout<
while(n<=k)
{
cout<p=c;
c=n;
n=p+c;
}
}


main()
{
fibonacci f;
clrscr();
cout<<"enter the limit:";
int k;
cin>>k;

cout<<"the fibonacci series is as follows:"<f.generate(k);
getch();

return(0);

}



OUTPUT:

enter the limit:50
the fibonacci series is as follows:
o
1
1
 
2
3
5
8
13
21
34


// To find the area of triangle,circle,square using the concept of function overloading//
#include
#include
#include
#define pi 3.142
class cal
{
private:
float r,l,br,a,b,c;
public:
float area(float );
float area(float , float );
float area(float , float ,float );
};
float cal::area(float r)
{
return pi*r*r;
}
float cal::area(float l,float br)
{
return l*br;
}
float cal::area(float a,float b,float c)
{
float s=(a+b+c)/2;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
int main()
{
cal cu;
float r,l,br,a,b,c;
clrscr();
cout<<"\nEnter the radius of the circle in metre:";
cin>>r;
cout<<"\nEnter the length & breadth of square in metre:";
cin>>l>>br;
cout<<"\nEnter the three sides of the triangle in metre:";
cin>>a>>b>>c;
cout<<"\nThe area of:\n\nThe circle is:"<cout<< "\n\nThe square is:"<cout<<"\n\nThe triangle is:"<getch();
return 0;
}
/***************OUTPUT***************/
/*
Enter the radius of the circle in metre:5.2
Enter the length & breadth of square in metre:4 4
Enter the three sides of the triangle in metre:2.4 4.5 5.3
The area of:
The circle is:84.959671 sq.m
The square is:16 sq.m
The triangle is:5.374907 sq.m

*/


access bank account

#include
#include
#include
class account
{
private:
char name[20];
int accno;
float bal,deb,cred;
public:
account()
{
bal=deb=cred=0;
}
void get()
{
cout<<"\nEnter your name:";
cin>>name;
cout<<"\nEnter your account no:";
cin>>accno;
cout<<"\nEnter your balance amount:Rs.";
cin>>bal;
}
void debit();
void credit();
void balance();
void display();
};
void account::debit()
{
char c;
cout<<"\nDo you want to withdraw some amount?Enter Y or N:";
cin>>c;
if(c=='Y'||c=='y')
{
cout<<"\nEnter the amount you are withdrawing:Rs.";
cin>>deb;
}
else
deb=0;
cout<<"\nThankyou.\n";
}
void account::credit()
{
char c;
cout<<"\nDo you want to deposit some amount?Enter Y or N:";
cin>>c;
if(c=='Y'||c=='y')
{
cout<<"\nEnter the amount you are depositing:Rs.";
cin>>cred;
}
else
cred=0;
cout<<"\nThankyou again.\n";
}
void account::balance()
{
bal=bal+cred-deb;
}
void account::display()
{
cout<int l=strlen(name);
for(int i=1;i<=6-l+4;i++)
cout<<" ";
cout<<"Rs."<cout<<" \tRs."<}
int main()
{
account ac;
clrscr();
ac.get();
ac.debit();
ac.credit();
ac.balance();
cout<<"\n/////////////////////ACCOUNT DETAILS//////////////////////\n\n";
cout<<"ACC NO. NAME CREDIT \t DEBIT";
cout<<" \t\t BALANCE";
ac.display();
cout<<"\n\nThankyou.Visit again.";
getch();
return 0;
}


output

/************OUTPUT*****************/
/*
Enter your name:Sourav Ganguly
Enter your account no:458
Enter your balance amount:Rs.40000
Do you want to withdraw some amount?Enter Y or N:Y
Enter the amount you are withdrawing:Rs.2100
Thankyou.
Do you want to deposit some amount?Enter Y or N:Y
Enter the amount you are depositing:Rs.6500
Thankyou again.

/////////////////////ACCOUNT DETAILS///////////////////////

ACC NO. NAME CREDIT DEBIT BALANCE
458. ANUBHAV Rs.6500 Rs.2100 Rs.44400
Thankyou.Visit again.
*/




C++ Programs

int myArray[N]; //where N is a constant 
int mySum = 0; 
... 
for (int arrayIndex1 = 0; arrayIndex1 <> 
{ 
cin >> myArray[arrayIndex1]; 
} 
... 
for (int int arrayIndex2 = 0; arrayIndex2 <> 
{ 
mySum +=myArray[arrayIndex2]; 
} 
... 

 

I had problems in making it when I was in first year.

int numer;
getche==number;
if (number ==1); printf("one");
if(number==100) printf("one hundred");
like that u can make it, but this approach will be very lenghty & bogus.

 

/* PROGRAM TO CONVERT THE NUMREIC FIGURES INTO THE WORDS */

#include
#include

void toWords(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six",
"seven","eight"," Nine"," ten"," eleven"," twelve"," thirteen",
"fourteen","fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty",
"sixty","seventy"," eighty"," ninety"};

void main()
{
long n;
clrscr();
printf("ENTER ANY 9 DIGIT NO.-> ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
toWords((n/10000000),"crore");
toWords(((n/100000)%100),"lakh");
toWords(((n/1000)%100),"thousand");
toWords(((n/100)%10),"hundred");
toWords((n%100)," ");
}
getch();
}


void toWords(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}

 

#include
#include
#include

void main()
{
char inp[20],revinp[20],flag=0;
clrscr();
int len=0,i=0,j=0;
printf("enter any word");
gets(inp);
len=strlen(inp);
for(i=len-1;i>=0;i--)
{
revinp[j]=inp;
j++;
}
revinp[j]='\0';

puts(inp);
printf("\n");
puts(revinp);
for(i=0;i
{
if(inp!=revinp)
{
flag=1;
printf("the word is not palendrom");
break;
}

}
if(flag==0)
printf("the entered word is palendrome");


getch();

}

 

#include
#include

void toWords(long,char[]);
char *one[]={"","one ","two ","three ","four ","five ","six ",
"seven ","eight ","Nine ","ten ","eleven ","twelve ","thirteen ",
"fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "};
char *ten[]={"","","twenty ","thirty ","forty ","fifty ",
"sixty ","seventy ","eighty ","ninety "};

void main()
{
long n;
clrscr();
printf("ENTER ANY 9 DIGIT NO.-> ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
toWords((n/10000000),"crore ");
toWords(((n/100000)%100),"lakh ");
toWords(((n/1000)%100),"thousand ");
toWords(((n/100)%10),"hundred ");
toWords((n%100),"");
}
getch();
}


void toWords(long n,char ch[])
{
(n>19)?printf("%s%s",ten[n/10],one[n%10]):printf("%s",one[n]);
if(n)printf("%s",ch);
}

3G S

JAIL BREAK

iPHONE

BILL GATES

StEvE JoBs

steve jobs

STEVE JOBS

Steve Jobs

Love Country

SD

Burroughs

Lift

Joseph Johnson

Apple Rainbow

Apple Blue

Apple Laser Printer