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.
*/




No comments:

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