Friday 11 July 2014

Account details using OOP



#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class bank
{
long int accno;
char name[20];
float bal;
public:
void input();
void display();
};
void bank::input()
{
cout<<"Enter Your accont number:";
cin>>accno;
cout<<"Enter Your name:";
gets(name);
cout<<"Enter Your balance amount:";
cin>>bal;
}
void bank::display()
{
cout<<"Your account number is:"<<accno;
cout<<"\n"<<"Name is:";
puts(name);
cout<<"Balance amount:"<<bal;
}
void main()
{
clrscr();
bank obj;
obj.input();
obj.display();
getch();
}

Character is present or not in a string using OOP



#include<conio.h>
#include<iostream.h>
#include<string.h>
#include<stdio.h>
class character
{
char a,str[50];
int i,flag;
public:
void readdata();
void result();
};

void character::readdata()
{
cout<<"Enter a string:";
gets(str);
cout<<"Enter a charecter:";
cin>>a;
flag=0;
for(i=0;str[i]!='\0';i++)

if(str[i]==a)

flag=1;
}
void character::result()
{
if (flag==1)
cout<<"charecter is present";
else
cout<<"charecter is not present:";
}
void main()
{
clrscr();
character obj;
obj.readdata();
obj.result();
getch();
}

Matrix Multiplication using OOP



#include<iostream.h>
#include<conio.h>
class matrix
{
int i,j,a[10][10],b[10][10],c[10][10],row1,row2,col1,col2,k;
public:
void getdata();
void putdata();
void multiply();
};
void matrix::getdata()
{
cout<<"Enter row size & column size of the first matrix:";
cin>>row1>>col1;
cout<<"Enter the elements for"<<row1<<"*"<<col1<<"matrix:";
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
cin>>a[i][j];
}}
cout<<"Enter the row size & column size of second matrix:";
cin>>row2>>col2;
if(col1==row2)
{
cout<<"Enter the elements for"<<row2<<"*"<<col2<<"matrix:";
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
{
cin>>b[i][j];
}}
multiply();
putdata();
}
else
cout<<"multiplication is not possible";
}
void matrix::multiply()
{
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
c[i][j]=0;
for(k=0;k<row2;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}}}}
void matrix::putdata()
{
cout<<"resultant matrix is:";
for(i=0;i<row1;i++)
{
cout<<"\n";
for(j=0;j<col2;j++)
{
cout<<"\t"<<c[i][j];
}}}
void main()
{
clrscr();
matrix obj;
obj.getdata();
getch();
}

Subtraction of Two matrices using oop



#include<iostream.h>
#include<conio.h>
class matrix
{
public:
int i,j,row,col,a[10][10],b[10][10],c[10][10];
void getdata();
void subdata();
void putdata();
};
void matrix::getdata()
{
cout<<"Enter the size of row and column of Matrices:";
cin>>row>>col;
cout<<"Enter the elements for Ist"<<row<<"x"<<col<<"matrix:";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cin>>a[i][j];
}}
cout<<"Enter the elements for IInd"<<row<<"X"<<col<<"matrix:";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cin>>b[i][j];
}}}
void matrix::subdata()
{
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
c[i][j]=a[i][j]-b[i][j];
}}}
void matrix::putdata()
{
cout<<"the Difference of matrix is:";
for(i=0;i<row;i++)
{
cout<<"\n";
for(j=0;j<col;j++)
{
cout<<"\t"<<c[i][j];
}}}
void main()
{
clrscr();
matrix obj;
obj.getdata();
obj.subdata();
obj.putdata();
getch();
}

Addition of Two matrices using oop



#include<iostream.h>
#include<conio.h>
class matrix
{
public:
int i,j,row,col,a[10][10],b[10][10],c[10][10];
void getdata();
void sumdata();
void putdata();
};
void matrix::getdata()
{
cout<<"Enter the size of row and column of Matrices:";
cin>>row>>col;
cout<<"Enter the elements for Ist"<<row<<"x"<<col<<"matrix:";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cin>>a[i][j];
}}
cout<<"Enter the elements for IInd"<<row<<"X"<<col<<"matrix:";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cin>>b[i][j];
}}}
void matrix::sumdata()
{
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
c[i][j]=a[i][j]+b[i][j];
}}}
void matrix::putdata()
{
cout<<"the sum of matrix is:";
for(i=0;i<row;i++)
{
cout<<"\n";
for(j=0;j<col;j++)
{
cout<<"\t"<<c[i][j];
}}}
void main()
{
clrscr();
matrix obj;
obj.getdata();
obj.sumdata();
obj.putdata();
getch();
}

The following program illustrates how to use Objects as Function Arguments

#include<iostream.h>
#include<conio.h>
class distance
          {
          private :
                   int mts ;
                   int cms;
          public :
                   void init (int a, int b)
                             {
                             mts=a; cms = b;
                             }
                   void get();
                   void put();
                   void add(distance, distance) ;
          } ;
void distance::get()
{
                   cout<<"enter two distances in meter:";
                   cin>>mts>>cms;
                   }
void distance :: put ( )
          {
          cout<<"\n"<<mts<<" Meters "<<cms<<"centimeters";
          }
void distance :: add (distance dl, distance d2)
          {
          mts = dl.mts+d2.mts;
          cms = dl.cms+d2.cms;
          if (cms>100)
                             {
                             mts+=cms/100;
                             cms%=100;
                             }
}
void main ()
{
clrscr();
distance ob1,ob2,ob3;
ob1.get();
ob2.init(5,85);
ob3.add(ob1, ob2);
cout<<"The two distances are..";

ob1.put ( ) ;
cout<<"\nAnd";
ob2.put () ;
cout<<"\nSum is ";
ob3. put () ;
getch();
}
Out put
          Enter a distance in meters and cms : 7                 65
          The two distances are:
          7 Meters 65 Centimeters
          And
          5 Meters 85 Centimeters
          Sum is
13 Meters 50 Centimeters.

The program illustrates the use of array of objects to store and display the name and telephone number of 50 subscribers.

 
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class subscriber
          {        char name [20] ;
                   long int phone;
          public :
          void read_data ()
                   {
                   cout<<"Enter name phone number of 50 students:";
                   gets (name);
                   cin>>phone;
                   }
          void print_data ()
                   {
                   cout<<name<<"\t"<<phone<<"\n";
                   }
};

void main ( )
{
subscriber ob [50] ;
for (int i=0;i<50;i++)
          ob [i]. read_data ( ) ;
for (i=0;i<50;i++)
          ob [i]. print_data ( ) ;
getch();
}

Monday 7 July 2014

Mark list




Code:
Dim mark(6) As Integer
 Private Sub Command1_Click()
For i = 1 To 6
mark(i) = Val(InputBox("Enter Marks"))
List1.AddItem (mark(i))
Next i
End Sub
 Private Sub Command2_Click()
Dim total As Integer, per As Single
total = 0
For i = 1 To 6
total = total + mark(i)
Next i
Text1.Text = total
per = total / 600 * 100
Text2.Text = per & "%"

If per > 90 Then
Text3.Text = "A+"
ElseIf per > 80 And per < 90 Then
Text3.Text = "A"
ElseIf per > 70 And per < 80 Then
Text3.Text = "B+"
ElseIf per > 60 And per < 70 Then
Text3.Text = "B"
ElseIf per > 50 And per < 60 Then
Text3.Text = "C+"
ElseIf per > 40 And per < 50 Then
Text3.Text = "C"
ElseIf per > 30 And per < 40 Then
Text3.Text = "D+"
ElseText3.Text = "Failed"
End If
End Sub

Private Sub Command3_Click()
Text1.Text = Clear
Text2.Text = Clear
Text3.Text = Clear
List1.Clear
End Sub