/*q.N 3.Write a program to add complex numbers of two different classes using friend class */
#include<iostream.h>
#include<conio.h>
class mula;
class aalu;
class gajar
{
private:
float realp,imagp;
public:
void getdata();
//void show();
friend class mula;
};
void gajar::getdata()
{
cout<<"\nFor First Class \n";
cout<<"\nEnter Real Part : ";
cin>>realp;
cout<<"\nEnter Imaginary Part : ";
cin>>imagp;
}
class aalu
{
private:
float realp,imagp;
public:
void getdata();
//void show();
friend class mula;
};
void aalu::getdata()
{
cout<<"\nFor Second Class \n";
cout<<"\nEnter Real Part : ";
cin>>realp;
cout<<"\nEnter Imaginary Part : ";
cin>>imagp;
}
class mula
{
private:
float realp,imagp;
public:
void add(gajar &g1,aalu &a1);
void display();
};
void mula::add(gajar &g1,aalu &a1)
{
realp=g1.realp+a1.realp;
imagp=g1.imagp+a1.imagp;
}
void mula::display()
{
cout<<"\n*****************************\n";
cout<<"\nThe Added Values Are : \n";
cout<<"\n"<<realp<<" + i"<<imagp<<endl;
}
int main()
{
mula m;
aalu a;
gajar g;
a.getdata();
g.getdata();
m.add(g,a);
m.display();
getch();
return 0;
}
Tuesday, February 5, 2013
swapping
/* Q.N 2. Write a program for swapping private data of two classes using friendly function and call by raference . */
#include<iostream.h>
#include<conio.h>
class class_2;
class class_1
{
private:
int x;
public:
void getdata();
void display();
friend void swap(class_1 &,class_2 &);
};
void class_1::getdata()
{
cout<<"\nEnter A Value For X : ";
cin>>x;
}
void class_1::display()
{
cout<<"\nThe Value Of X : "<<x;
}
class class_2
{
private:
int y;
public:
void getdata();
void display();
friend void swap(class_1 &,class_2 &);
};
void class_2::getdata()
{
cout<<"\nEnter A Value For Y : ";
cin>>y;
}
void class_2::display()
{
cout<<"\nThe Value Of Y : "<<y;
}
void swap(class_1 &a,class_2 &b)
{
int temp;
temp=a.x;
a.x=b.y;
b.y=temp;
}
int main()
{
class_1 p;
class_2 q;
p.getdata();
q.getdata();
cout<<"\n*******************************\n";
cout<<"\nThe Values Before Swapping :\n";
p.display();
q.display();
swap(p,q);
cout<<"\n*******************************\n";
cout<<"\nThe Values After Swapping :\n";
p.display();
q.display();
getch();
return 0;
}
#include<iostream.h>
#include<conio.h>
class class_2;
class class_1
{
private:
int x;
public:
void getdata();
void display();
friend void swap(class_1 &,class_2 &);
};
void class_1::getdata()
{
cout<<"\nEnter A Value For X : ";
cin>>x;
}
void class_1::display()
{
cout<<"\nThe Value Of X : "<<x;
}
class class_2
{
private:
int y;
public:
void getdata();
void display();
friend void swap(class_1 &,class_2 &);
};
void class_2::getdata()
{
cout<<"\nEnter A Value For Y : ";
cin>>y;
}
void class_2::display()
{
cout<<"\nThe Value Of Y : "<<y;
}
void swap(class_1 &a,class_2 &b)
{
int temp;
temp=a.x;
a.x=b.y;
b.y=temp;
}
int main()
{
class_1 p;
class_2 q;
p.getdata();
q.getdata();
cout<<"\n*******************************\n";
cout<<"\nThe Values Before Swapping :\n";
p.display();
q.display();
swap(p,q);
cout<<"\n*******************************\n";
cout<<"\nThe Values After Swapping :\n";
p.display();
q.display();
getch();
return 0;
}
friend function
/* Q.N 1. Write a program using friend function to add numerical values of three objects of different classes */
#include<iostream.h>
#include<conio.h>
class class_2;
class class_3;
class class_1
{
private:
int x;
public:
void getdata();
friend void add(class_1,class_2,class_3);
};
void class_1::getdata()
{
cout<<"\nEnter A Value For X : ";
cin>>x;
}
class class_2
{
private:
int y;
public:
void getdata();
friend void add(class_1,class_2,class_3);
};
void class_2::getdata()
{
cout<<"\nEnter A Value For Y : ";
cin>>y;
}
class class_3
{
private:
int z;
public:
void getdata();
friend void add(class_1,class_2,class_3);
};
void class_3::getdata()
{
cout<<"\nEnter A Value For Z : ";
cin>>z;
}
void add(class_1 a,class_2 b,class_3 c)
{
int sum;
sum=(a.x+b.y+c.z);
cout<<"\n**********************************\n";
cout<<"\nThe Sum Of Given Three Integer : "<<sum<<endl;
}
int main()
{
class_1 p;
class_2 q;
class_3 r;
p.getdata();
q.getdata();
r.getdata();
add(p,q,r);
getch();
return 0;
}
#include<iostream.h>
#include<conio.h>
class class_2;
class class_3;
class class_1
{
private:
int x;
public:
void getdata();
friend void add(class_1,class_2,class_3);
};
void class_1::getdata()
{
cout<<"\nEnter A Value For X : ";
cin>>x;
}
class class_2
{
private:
int y;
public:
void getdata();
friend void add(class_1,class_2,class_3);
};
void class_2::getdata()
{
cout<<"\nEnter A Value For Y : ";
cin>>y;
}
class class_3
{
private:
int z;
public:
void getdata();
friend void add(class_1,class_2,class_3);
};
void class_3::getdata()
{
cout<<"\nEnter A Value For Z : ";
cin>>z;
}
void add(class_1 a,class_2 b,class_3 c)
{
int sum;
sum=(a.x+b.y+c.z);
cout<<"\n**********************************\n";
cout<<"\nThe Sum Of Given Three Integer : "<<sum<<endl;
}
int main()
{
class_1 p;
class_2 q;
class_3 r;
p.getdata();
q.getdata();
r.getdata();
add(p,q,r);
getch();
return 0;
}
Transpose With Pointer
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class matrix
{
int **mat,**t,r,c;
public:
void getmat();
void transpose();
void display();
};
void matrix::getmat()
{
cout<<"\nEnter the size of Matrix : ";
cout<<"\nRow : ";
cin>>r;
cout<<"\nColumn : ";
cin>>c;
mat=new int *[r];
for(int i=0;i<r;i++)
mat[i]=new int [c];
cout<<"\nEnter Your Matrix :\n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<"\nEnter Element ["<<i+1<<"]["<<j+1<<"] : ";
cin>>mat[i][j];
}
}
}
void matrix::display()
{
cout<<"\nThe Original Matrix : \n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<mat[i][j]<<"\t";
}
cout<<endl;
}
}
void matrix::transpose()
{
t=new int *[c];
for(int i=0;i<c;i++)
t[i]=new int [r];
cout<<"\nThe Transpose Matrix : \n";
for(int i=0;i<c;i++)
{
for(int j=0;j<r;j++)
{
t[i][j]=mat[j][i];
cout<<t[i][j]<<"\t";
}
cout<<endl;
}
}
int main()
{
matrix M;
M.getmat();
M.display();
M.transpose();
getch();
return 0;
}
#include<conio.h>
#include<stdlib.h>
class matrix
{
int **mat,**t,r,c;
public:
void getmat();
void transpose();
void display();
};
void matrix::getmat()
{
cout<<"\nEnter the size of Matrix : ";
cout<<"\nRow : ";
cin>>r;
cout<<"\nColumn : ";
cin>>c;
mat=new int *[r];
for(int i=0;i<r;i++)
mat[i]=new int [c];
cout<<"\nEnter Your Matrix :\n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<"\nEnter Element ["<<i+1<<"]["<<j+1<<"] : ";
cin>>mat[i][j];
}
}
}
void matrix::display()
{
cout<<"\nThe Original Matrix : \n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<mat[i][j]<<"\t";
}
cout<<endl;
}
}
void matrix::transpose()
{
t=new int *[c];
for(int i=0;i<c;i++)
t[i]=new int [r];
cout<<"\nThe Transpose Matrix : \n";
for(int i=0;i<c;i++)
{
for(int j=0;j<r;j++)
{
t[i][j]=mat[j][i];
cout<<t[i][j]<<"\t";
}
cout<<endl;
}
}
int main()
{
matrix M;
M.getmat();
M.display();
M.transpose();
getch();
return 0;
}
Transpose Matrix
#include<iostream.h>
#include<conio.h>
class matrix
{
int mat[10][10],t[10][10],r,c;
public:
void getmat();
void transpose();
void display();
};
void matrix::getmat()
{
cout<<"\nEnter the size of Matrix : ";
cout<<"\nRow : ";
cin>>r;
cout<<"\nColumn : ";
cin>>c;
cout<<"\nEnter Your Matrix :\n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<"\nEnter Element of ["<<i+1<<"]["<<j+1<<"] : ";
cin>>mat[i][j];
}
}
}
void matrix::display()
{
cout<<"\nThe Original Matrix : \n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<mat[i][j]<<"\t";
}
cout<<endl;
}
}
void matrix::transpose()
{
cout<<"\nThe Transpose Matrix : \n";
for(int i=0;i<c;i++)
{
for(int j=0;j<r;j++)
{
t[i][j]=mat[j][i];
cout<<t[i][j]<<"\t";
}
cout<<endl;
}
}
int main()
{
matrix M;
M.getmat();
M.display();
M.transpose();
getch();
return 0;
}
#include<conio.h>
class matrix
{
int mat[10][10],t[10][10],r,c;
public:
void getmat();
void transpose();
void display();
};
void matrix::getmat()
{
cout<<"\nEnter the size of Matrix : ";
cout<<"\nRow : ";
cin>>r;
cout<<"\nColumn : ";
cin>>c;
cout<<"\nEnter Your Matrix :\n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<"\nEnter Element of ["<<i+1<<"]["<<j+1<<"] : ";
cin>>mat[i][j];
}
}
}
void matrix::display()
{
cout<<"\nThe Original Matrix : \n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<mat[i][j]<<"\t";
}
cout<<endl;
}
}
void matrix::transpose()
{
cout<<"\nThe Transpose Matrix : \n";
for(int i=0;i<c;i++)
{
for(int j=0;j<r;j++)
{
t[i][j]=mat[j][i];
cout<<t[i][j]<<"\t";
}
cout<<endl;
}
}
int main()
{
matrix M;
M.getmat();
M.display();
M.transpose();
getch();
return 0;
}
calculating the interest
/* Q.N 4. Write a program to create that calculates the interest of any number */
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class interest
{
int year;
float rate,amount;
public:
void getval();
void calcint();
};
void interest::getval()
{
cout<<"Enter Principal Amount : "<<endl;
cin>>amount;
cout<<"\nEnter Rate and Time in Year : "<<endl;
cin>>rate>>year;
}
void interest::calcint()
{
float inter=(amount*year*rate/100);
cout<<"\nThe Interest Amount : "<<inter<<endl;
}
int main()
{
interest I;
I.getval();
I.calcint();
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class interest
{
int year;
float rate,amount;
public:
void getval();
void calcint();
};
void interest::getval()
{
cout<<"Enter Principal Amount : "<<endl;
cin>>amount;
cout<<"\nEnter Rate and Time in Year : "<<endl;
cin>>rate>>year;
}
void interest::calcint()
{
float inter=(amount*year*rate/100);
cout<<"\nThe Interest Amount : "<<inter<<endl;
}
int main()
{
interest I;
I.getval();
I.calcint();
getch();
return 0;
}
sorting
/*Q.N 3. Write a C++ code to sort the given 10 numbers in assending order .*/
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class sort
{
int val[10];
public:
void getval(void);
void sorts(void);
void disp(void);
};
void sort::getval()
{
int i;
cout<<"\nEnter 5 integer Data : \n";
for(i=0;i<5;i++)
{
cout<<"\nEnter Value "<<i+1<<" :";
cin>>val[i];
}
}
void sort::sorts()
{
int i,j,temp;
for(j=0;j<5;j++)
{
for(i=0;i<4;i++)
{
if(val[i]>val[i+1])
{
temp=val[i];
val[i]=val[i+1];
val[i+1]=temp;
}
}
}
}
void sort::disp()
{
int i;
cout<<"\nThe Sorted Array : \n";
for(i=0;i<5;i++)
{
cout<<"\nValue "<<i+1<<":"<<val[i];
}
}
int main()
{
sort S;
S.getval();
S.sorts();
S.disp();
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class sort
{
int val[10];
public:
void getval(void);
void sorts(void);
void disp(void);
};
void sort::getval()
{
int i;
cout<<"\nEnter 5 integer Data : \n";
for(i=0;i<5;i++)
{
cout<<"\nEnter Value "<<i+1<<" :";
cin>>val[i];
}
}
void sort::sorts()
{
int i,j,temp;
for(j=0;j<5;j++)
{
for(i=0;i<4;i++)
{
if(val[i]>val[i+1])
{
temp=val[i];
val[i]=val[i+1];
val[i+1]=temp;
}
}
}
}
void sort::disp()
{
int i;
cout<<"\nThe Sorted Array : \n";
for(i=0;i<5;i++)
{
cout<<"\nValue "<<i+1<<":"<<val[i];
}
}
int main()
{
sort S;
S.getval();
S.sorts();
S.disp();
getch();
return 0;
}
quadratic equations
/* Q.N 1. Write a C++ code to solve the quadratic equations . */
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>
class qequ
{
int a,b,c;
float root1,root2;
public:
void getdata(int ,int ,int);
void calroot();
void disp();
};
void qequ::getdata(int x,int y,int z)
{
a=x;
b=y;
c=z;
}
void
main()
{
int a,b,c;
float d,root1,root2;
cout<<"\nEnter The Value Of a , b & c from Equation : ";
cin>>a>>b>>c;
d=sqrt(b*b-4*a*c);
if(d<0)
cout<<"\nThe Roots Are Imaginarry !";
else
{
root1=((-b+d)/2*a);
root1=((-b+d)/2*a);
cout<<"\nThe Roots Are : ";
cout<<"\nRoot 1 : "<<root1;
cout<<"\nRoot 2 : "<<root2;
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>
class qequ
{
int a,b,c;
float root1,root2;
public:
void getdata(int ,int ,int);
void calroot();
void disp();
};
void qequ::getdata(int x,int y,int z)
{
a=x;
b=y;
c=z;
}
void
main()
{
int a,b,c;
float d,root1,root2;
cout<<"\nEnter The Value Of a , b & c from Equation : ";
cin>>a>>b>>c;
d=sqrt(b*b-4*a*c);
if(d<0)
cout<<"\nThe Roots Are Imaginarry !";
else
{
root1=((-b+d)/2*a);
root1=((-b+d)/2*a);
cout<<"\nThe Roots Are : ";
cout<<"\nRoot 1 : "<<root1;
cout<<"\nRoot 2 : "<<root2;
}
getch();
}
Student info
/*Create a class student with private data members name ,roll no,age and member functions input() to take input of data and display() to display the records .
Test the program for one student*/
#include<iostream.h>
#include<string.h>
#include<conio.h>
class student
{
private:
char name[25];
int roll,age;
public:
void input(char nam[] ,int rol,int ag);
void display(void);
};
void student::input(char nam[25],int rol,int ag)
{
strcpy(name,nam);
roll=rol;
age=ag;
}
void student::display()
{
cout<<"Name : "<<name<<endl;
cout<<"Roll No : "<<roll<<endl;
cout<<"Age : "<<age<<endl;
}
int main()
{
student st;
char name[25];
int roll,age;
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"Enter Age : "<<endl;
cin>>age;
st.input(name,roll,age);
st.display();
getch();
return 0;
}
Test the program for one student*/
#include<iostream.h>
#include<string.h>
#include<conio.h>
class student
{
private:
char name[25];
int roll,age;
public:
void input(char nam[] ,int rol,int ag);
void display(void);
};
void student::input(char nam[25],int rol,int ag)
{
strcpy(name,nam);
roll=rol;
age=ag;
}
void student::display()
{
cout<<"Name : "<<name<<endl;
cout<<"Roll No : "<<roll<<endl;
cout<<"Age : "<<age<<endl;
}
int main()
{
student st;
char name[25];
int roll,age;
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"Enter Age : "<<endl;
cin>>age;
st.input(name,roll,age);
st.display();
getch();
return 0;
}
/*Create a class Student with six data members (Roll No., name , marks in English ,Maths and Science , total), write a program with init()
to initializes necessary data members , Calctotal() that calculates the total of the marks obtained int the three subjects and display()
that displays the details of the Students.
In main() create two objects of the class student and for each object invoke calctotal() and display().*/
#include<iostream.h>
#include<string.h>
#include<conio.h>
class student
{
private:
char name[25];
int roll;
float eng,math,sci,total;
public:
void init(char [] ,int ,float ,float ,float);
float calctotal(void);
void display(void);
};
void student::init(char nam[25],int rol, float engl, float maths, float scie)
{
strcpy(name,nam);
roll=rol;
eng=engl;
math=maths;
sci=scie;
total=calctotal();
}
void student::display()
{
cout<<"Name : "<<name<<endl;
cout<<"Roll No : "<<roll<<endl;
cout<<"English : "<<eng<<endl;
cout<<"Math : "<<math<<endl;
cout<<"Science : "<<sci<<endl;
cout<<"Total : "<<total<<endl;
}
float student::calctotal()
{
return(eng+sci+math);
}
int main()
{
student st1,st2;
char name[25];
int roll;
float eng,sci,math;
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"\n\tEnter Marks : \n";
cout<<"English : "<<endl;
cin>>eng;
cout<<"Mathematics: "<<endl;
cin>>math;
cout<<"Science : "<<endl;
cin>>sci;
st1.init(name,roll,eng,math,sci);
st1.display();
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"\n\tEnter Marks : \n";
cout<<"English : "<<endl;
cin>>eng;
cout<<"Mathematics: "<<endl;
cin>>math;
cout<<"Science : "<<endl;
cin>>sci;
st2.init(name,roll,eng,math,sci);
st2.display();
getch();
return 0;
}
to initializes necessary data members , Calctotal() that calculates the total of the marks obtained int the three subjects and display()
that displays the details of the Students.
In main() create two objects of the class student and for each object invoke calctotal() and display().*/
#include<iostream.h>
#include<string.h>
#include<conio.h>
class student
{
private:
char name[25];
int roll;
float eng,math,sci,total;
public:
void init(char [] ,int ,float ,float ,float);
float calctotal(void);
void display(void);
};
void student::init(char nam[25],int rol, float engl, float maths, float scie)
{
strcpy(name,nam);
roll=rol;
eng=engl;
math=maths;
sci=scie;
total=calctotal();
}
void student::display()
{
cout<<"Name : "<<name<<endl;
cout<<"Roll No : "<<roll<<endl;
cout<<"English : "<<eng<<endl;
cout<<"Math : "<<math<<endl;
cout<<"Science : "<<sci<<endl;
cout<<"Total : "<<total<<endl;
}
float student::calctotal()
{
return(eng+sci+math);
}
int main()
{
student st1,st2;
char name[25];
int roll;
float eng,sci,math;
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"\n\tEnter Marks : \n";
cout<<"English : "<<endl;
cin>>eng;
cout<<"Mathematics: "<<endl;
cin>>math;
cout<<"Science : "<<endl;
cin>>sci;
st1.init(name,roll,eng,math,sci);
st1.display();
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"\n\tEnter Marks : \n";
cout<<"English : "<<endl;
cin>>eng;
cout<<"Mathematics: "<<endl;
cin>>math;
cout<<"Science : "<<endl;
cin>>sci;
st2.init(name,roll,eng,math,sci);
st2.display();
getch();
return 0;
}
Sunday, February 3, 2013
Comparision
#include<iostream.h>
#include<conio.h>
class comparison
{
int x,y,max;
public:
void getdata(int a,int b);
void largest(void);
void print(void);
};
void comparison::getdata(int a,int b)
{
x=a;
y=b;
}
void comparison::largest()
{
if(x>y)
max=x;
else
max=y;
}
void comparison::print()
{
cout<<"\nThe Largest Number : "<<max<<endl;
}
int main()
{
comparison com;
int a,b;
cout<<"Enter Two numbers : ";
cin>>a>>b;;
com.getdata(a,b);
com.largest();
com.print();
getch();
}
#include<conio.h>
class comparison
{
int x,y,max;
public:
void getdata(int a,int b);
void largest(void);
void print(void);
};
void comparison::getdata(int a,int b)
{
x=a;
y=b;
}
void comparison::largest()
{
if(x>y)
max=x;
else
max=y;
}
void comparison::print()
{
cout<<"\nThe Largest Number : "<<max<<endl;
}
int main()
{
comparison com;
int a,b;
cout<<"Enter Two numbers : ";
cin>>a>>b;;
com.getdata(a,b);
com.largest();
com.print();
getch();
}
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();
}
#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();
}
#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();
}
#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();
}
#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;
}
#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;
}
}
}
#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.co m/ 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"<<end l;
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:
}
Subscribe to:
Posts (Atom)