Powered by Blogger.

Saturday, January 19, 2013

print the series....

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
clrscr();
int i;
float z;

for(i=0;i<8;i++)
{
z=pow(2,i);

//for(i=0;i<8;i++)
printf(" 1/%3.f\n",z);
}
getch();
}

Hex,Oct equivalent

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
    clrscr();
    int hex;
    int oct=024;
    int un=-455;
    printf("enter the no. for hexadecimal no.");
    scanf("%d",&hex);
    printf("\nThe Hexadecimal equivalent is:%x",hex);
    printf("\nthe octal no: %o",oct);
    printf("\nthe ..... %u",un);
    getch();
    }

Print The Respective ASCII Values

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


void main()
{
clrscr();
char a;
printf("Enter the ascii character:\n");
scanf("%c",&a);
printf("%d",a);
getch();
}

Area Of Traingle

#include<conio.h>
#include<iostream.h>
#include<math.h>
void main()
{
clrscr();
float a,b,c,s,area;
cout<<"enter the side of a, b &c:\n";
cin>>a>>b>>c;
cout<<"a="<<a<<"\n"<<"b="<<b<<"c="<<c<<endl;
if((a>=(b+c))||(b>=(a+c))||(c>=(a+b)))
cout<<"invalid data selected";
else
{
    s=(a+b+c)/2;
    area=sqrt(s*(s-a)*(s-b)*(s-c));
    cout<<"Area of Traingle is:"<<area;

}
getch();
}

Surface Area Of Rectangle

#include<iostream.h>
#include<conio.h>
void surface(int x, int y, int z=5);
void volume(int x,int y, int z=5);
void volume(int r);
#include<math.h>
void main()
{
clrscr();
float l,b,h;
cout<<"enter the length breadth and height of the rectangle\n";
cin>>l>>b>>h;
surface(l,b,h);
volume(l,b,h);

cout<<"enter the length and breadth of rectangle";

cin>>l>>b;
surface(l,b);
volume(l,b);
cout<<"enter the radius of rectangle";
cin>>l  ;
volume(l);
getch();
}
void surface(int x,int y ,int z)
{
       int surface=2*((x*y)+(x*z)+(y*z));

cout<<"surface area of rectangle is:"<<surface<<endl;
}
void volume(int x,int y,int z)
{        int volume;
     volume=x*y*z;

    cout<<"volume of rectangle is:"<<volume<<endl;
}
void volume(int r)
{
    int volume=(((4/3)*3.14)*pow(r,3));
    cout<<"volume of sphere"<<volume<<endl;
    }

Bisection(Numerical Method)

#include <stdio.h>
#include <conio.h>
#include <math.h>
#define EPS 0.000001
#define F(x) x*x+x-2

void bim(float *a,float *b,float *root, int *s,int *count);
main(){
       int s, count;
       float a,b,root;
       printf("\nSolution By Bisection Method");
       printf("\nInput starting value:\n");
       scanf("%f%f",&a,&b);
       bim(&a,&b,&root,&s,&count);
       if (s==0){
                 printf("\n Starting points do not bracket any root or they bracket an even number of roots\n ");
                 }
                 else{
                      printf("nRoot=%f\n",root);
                      printf("F(root)=%f\n",F(root));
                      printf("\n Iterations=%d\n",count);
                      }
                      getch();
                      }
      
void bim(float *a,float *b,float *root,int *s, int *count){
          float x0,x1,x2,f0,f1,f2;
          x1=*a;
          x0=*b;
          f1=F(x1);
          f2=F(x2);
          if(f1*f2>0){
                      *s=0;
                      return;
                      }
          else{
               *count=0;
               begin:
                     x0=(x1+x2)/2;
                     f0=F(x0);
                     if(f0==0){
                               *s=1;
                               *root=x0;
                               return;
                               }
                     if(f1*f0<0){
                                 x2=x0;
                                 }
                     else{
                          x1=x0;
                          f1=f0;
                          }
                     if(fabs((x2-x1)/x2)<EPS){
                                              *s=1;
                                              *root=(x1+x2)/2.0;
                                              return;
                                              }
                     else{
                          *count=*count+1;
                          goto begin;
                          }
                          }
                      
                          }
                                             

Define a class to represent a bank account. Include the following members:



Data Members
1 Name of the depositor
2 Account Number
3 Type of account
4 Balance amount in the account

Member function
1 To assign initial values
2 To deposit an amount
3 To withdraw an amount after checking the balance
4 To display name and Balance

write a main program to test the program.
Code for Program for Banking Application in C++ Programming
/* visit :http://cplusplusprogamming.blogspot.com/ for more info about progamming

------------
***Progam***
------------

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

class bank
{
char name[20];
int acno;
char actype[20];
int bal;
public :
void opbal(void);
void deposit(void);
void withdraw(void);
void display(void);
};

void bank :: opbal(void)
{
cout<<endl<<endl;
cout<<"Enter Name :-";
cin>>name;
cout<<"Enter A/c no. :-";
cin>>acno;
cout<<"Enter A/c Type :-";
cin>>actype;
cout<<"Enter Opening Balance:-";
cin>>bal;
}

void bank :: deposit(void)
{
cout<<"Enter Deposit amount :-";
int deposit=0;
cin>>deposit;
deposit=deposit+bal;
cout<<"\nDeposit Balance = "<<deposit;
bal=deposit;
}

void bank :: withdraw(void)
{
int withdraw;
cout<<"\nBalance Amount = "<<bal;
cout<<"\nEnter Withdraw Amount :-";
cin>>withdraw;
bal=bal-withdraw;
cout<<"After Withdraw Balance is "<<bal;
}

void bank :: display(void)
{
cout<<endl<<endl<<endl;
cout<<setw(50)<<"DETAILS"<<endl;
cout<<setw(50)<<"name "<<name<<endl;
cout<<setw(50)<<"A/c. No. "<<acno<<endl;
cout<<setw(50)<<"A/c Type "<<actype<<endl;
cout<<setw(50)<<"Balance "<<bal<<endl;
}

void main()
{
clrscr();
bank o1;
int choice;
do
{
cout<<"\n\nChoice List\n\n";
cout<<"1) To assign Initial Value\n";
cout<<"2) To Deposit\n";
cout<<"3) To Withdraw\n";
cout<<"4) To Display All Details\n";
cout<<"5) EXIT\n";
cout<<"Enter your choice :-";
cin>>choice;
switch(choice)
{
case 1: o1.opbal();
break;
case 2: o1.deposit();
break;
case 3: o1.withdraw();
break;
case 4: o1.display();
break;
case 5: goto end;
}
}while(1);
end:
}