Friday, March 6, 2015

Visual basic program to create calculator with extra two button for factorial and check even/odd.

Design window  :-
Take button on form and one textbox on form and make it place as shown below and then in code window of each button do following coding.


Dim operand1 As Double
Dim operand2 As Double
Dim operator As String

Private Sub Command1_Click()
Text1.Text = Text1.Text + "1"
End Sub

Private Sub Command2_Click()
Text1.Text = Text1.Text + "2"
End Sub

Private Sub Command3_Click()
Text1.Text = Text1.Text + "3"
End Sub

Private Sub Command4_Click()
Text1.Text = Text1.Text + "4"
End Sub

Private Sub Command5_Click()
Text1.Text = Text1.Text + "5"
End Sub

Private Sub Command6_Click()
Text1.Text = Text1.Text + "6"
End Sub

Private Sub Command7_Click()
Text1.Text = Text1.Text + "7"
End Sub

Private Sub Command8_Click()
Text1.Text = Text1.Text + "8"
End Sub

Private Sub Command9_Click()
Text1.Text = Text1.Text + "9"
End Sub

Private Sub Command10_Click()
Text1.Text = Text1.Text + "0"
End Sub

Private Sub Command11_Click()
Text1.Text = Text1.Text + "."
End Sub

Private Sub Command12_Click()
Text1.Text = ""
End Sub

Private Sub Command13_Click()
operand1 = Val(Text1.Text)
operator = "+"
Text1.Text = ""
End Sub

Private Sub Command14_Click()
operand1 = Val(Text1.Text)
operator = "-"
Text1.Text = ""
End Sub

Private Sub Command15_Click()
operand1 = Val(Text1.Text)
operator = "*"
Text1.Text = ""
End Sub

Private Sub Command16_Click()
operand1 = Val(Text1.Text)
operator = "/"
Text1.Text = ""
End Sub

Private Sub Command17_Click()
Dim n As Integer
Dim fact As Integer
fact = 1
n = Val(Text1.Text)
For i = 1 To n
fact = fact * i
Next
MsgBox "Factorial of " & n & " is = " & fact
Text1.Text = ""
End Sub

Private Sub Command18_Click()
Text1.Text = Text1.Text * -1
End Sub

Private Sub Command19_Click()
Dim n As Integer
n = Val(Text1.Text)
If n Mod 2 = 0 Then
MsgBox "Number is EVEN"
Else
MsgBox "Number is ODD"
End If
Text1.Text = ""
End Sub

Private Sub Command20_Click()
Dim result As Double
operand2 = Val(Text1.Text)
If operator = "-" Then result = operand1 - operand2
If operator = "*" Then result = operand1 * operand2
If operator = "+" Then result = operand1 + operand2
If operator = "/" And operand2 <> "0" Then result = operand1 / operand2
Text1.Text = result
End Sub
=============================================================
OUTPUT



Saturday, February 28, 2015

Write a C++ program using class to sort an integer array and float array element in ascending order using bubble sort method use function overloading

Write a C++ program using class to sort an integer array and float array element in ascending order using bubble sort method use function overloading





#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<float.h>
class bubble
{
public:void array(int ans);
       void array(float ans);
};
void bubble:: array(int ans)
       {
       cout<<"\n"<<ans;
       }
void bubble::array(float ans)
       {
       cout<<"\n"<<ans;
       }
int main()
{
bubble bb;
int i,j,n,a[20],temp=0;
float b[20];
clrscr();
cout<<"\n Enter how many integer number you want to enter:-";
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
n=n-1;
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
n++;
cout<<"\n Integer array after sorting:-";
for(i=0;i<n;i++)
bb.array(a[i]);
cout<<"\n Enter how many float number you want to enter:-";
cin>>n;
for(i=0;i<n;i++)
cin>>b[i];
n=n-1;
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(b[j]>b[j+1])
{
float(temp)=b[j];
b[j]=b[j+1];
b[j+1]=float(temp);
}
}
}
n++;
cout<<"\n Float array after sorting:-";
for(i=0;i<n;i++)
bb.array(b[i]);
getch();

return 0;
}

==================================================

OUTPUT


Enter how many integer number you want to enter:-5                             
9                                                                              
8                                                                              
7                                                                              
4
1                                                                              
                                                                               
Integer array after sorting:-                                                  
1                                                                              
4                                                                              
7                                                                              
8                                                                              
9  
                                                                           
Enter how many float number you want to enter:-4                               
6.3                                                                            
5.2                                                                            
4.2                                                                            
1.3                                                                            
                                                                               
Float array after sorting:-
1.3
4.2
5.2
6.3

Write a C++ program to Design a class which contain static data member and member function show()

Design a class which contain static data member and member function show() which display number of times display operation is performed irrespective of the object responsible for display using static data
member.

#include<conio.h>
#include<iostream.h>
class number
{
public:static int cnt;
public:static void show()
       {
       cnt++;
       cout<<"\n Number of times display operation is performed:-"<<cnt;
       }
};
int number::cnt;
int main()
{
number n1,n2,n3,n4;
clrscr();
n1.show();
n2.show();
n3.show();
n4.show();
getch();
return 0;
}


==================================================
OUTPUT

Number of times display operation is performed:-1
Number of times display operation is performed:-2
Number of times display operation is performed:-3
Number of times display operation is performed:-4

Write a c++ program using class to calculate cube and square of a given number using inline function.

Write a C++ program using class to calculate cube and square of a given number using inline function.





#include<iostream.h>
#include<conio.h>
class calc
{
int no;
public:inline void number()
       {
       int square,cube;
       cout<<"Enter the number";
       cin>>no;
       square=no*no;
       cube=no*no*no;
       cout<<"Square of a given number is:-"<<square;
       cout<<"\n Cube of a given number is:-"<<cube;
       }
       };
int main()
{
calc c;
clrscr();
c.number();
getch();
return 0;
}

======================================================

OUTPUT:-

Enter the number5
Square of a given number is:-25
Cube of a given number is:-125

Write a C++ program using class to overload the operator unary decrement -- for an integer number.

Write a C++ program using class to overload the operator unary decrement -- for an integer number.





#include<conio.h>
#include<iostream.h>
class decrement
{
public:int no;
public:void getdata()
       {
       cout<<"\n Enter the number:-";
       cin>>no;
       }
       void operator --()
       {
       no=no-1;
       }
       void display()
       {
       cout<<"\n The number after decrement is:-"<<no;
       }
};
int main()
{
decrement i;
clrscr();
i.getdata();
--i;
i.display();
getch();
return 0;
}




===========================================

OUTPUT


Enter the number:-6

The number after decrement is:-5

Write a c++ program using class to overload the operator unary increment ++ for an integer number.

Write a C++ program using class to overload the operator unary increment ++ for an integer number.



#include<conio.h>
#include<iostream.h>
class increment
{
public:int no;
public:void getdata()
       {
       cout<<"\n Enter the number:-";
       cin>>no;
       }
       void operator ++()
       {
       no=no+1;
       }
       void display()
       {
       cout<<"\n The number after increment is:-"<<no;
       }
};
int main()
{
increment i;
clrscr();
i.getdata();
++i;
i.display();
getch();
return 0;
}


=========================================

OUTPUT


Enter the number:-2

The number after increment is:-3

Friday, February 27, 2015

VB program to dispaly age from birth date

Design Window:-


Code:

Private Sub cmdClear_Click()
    Text1.Text = ""
    Text2.Text = ""
    Text1.SetFocus
End Sub

Private Sub cmdDisplay_Click()
    Dim b As Date
    Dim d As Date
    Dim age As Date
    b = Text1.Text
    d = Format$(Now, "dd/mm/yyyy hh:mm:ss ")
    age = Format$(d - b, "dd/mm/yyyy hh:mm:ss")
   
    Text2.Text = Year(age)
    Text3.Text = Month(age)
    Text4.Text = Day(age)
    Text5.Text = Hour(age)
    Text6.Text = Minute(age)
    Text7.Text = Second(age)
End Sub

Private Sub cmdExit_Click()
    Unload Me
End Sub
===================================================
OUTPUT

Thursday, February 26, 2015

Write a C++ program using class to read the name of user and number of units consumed and printout charges with name(Electricity)

Write a C++ program using class to read the name of user and number of units consumed and printout charges with name(Electricity)



An electricity board charges the following rates to users

-for first 100 units:40p per unit

-for next 200 units: 50p per unit

-for beyond 300 units :60p per unit

all user are charged a minimum of Rs.150. if the total cost is more than Rs.250 then an additional charges of 15% are added.

Write a c++ program using class to read the name of user and numberof units consumed and printout charges with names.(use array of object)




#include<conio.h>
#include<iostream.h>
class elec
{
char name[20];
int nou;
float charge;
public:void accept()
       {
       cout<<"\n enter name:-";
       cin>>name;
       cout<<"\n enter number of unit:-";
       cin>>nou;
       }
       void calc()
       {
       if(nou<100)
       charge=nou*0.4;
       else
       if(nou<=300)
       {
       int temp=nou-100;
       charge=100*0.4;
       charge=(float)charge+(temp*0.5);
       }
       else
       if(nou>300)
       charge=nou*0.6;
       if(charge<150)
       charge=150;
       else
       if(charge>250)
       charge=(float)charge+(charge*0.15);
       }
       void display()
       {
       cout<<"\n name="<<name;
       cout<<"\n charges="<<charge;
       }
};
int main()
{
elec e[3];
clrscr();
for(int i=0;i<3;i++)
{
e[i].accept();
e[i].calc();
}
for(i=0;i<3;i++)
e[i].display();
getch();
return 0;
}

=============================================

OUTPUT:-


enter name:-XYZ                                                             
                                                                               
enter number of unit:-122                                                      
                                                                               
enter name:-ABC                                                                
                                                                               
enter number of unit:-302                                                      
                                                                               
enter name:-PQR                                                             
                                                                               
enter number of unit:-1000                                                     
                                                                               
name=XYZ                                                                    
charges=150                                                                    
name=ABC                                                                      
charges=181.199997                                                             
name=PQR
charges=690

Write a C++menu driven program to show class hierarchy.

Write a C++menu driven program to show class hierarchy.




Consider the following class hierarchy.

    Create a base class Employee(empcode, empname). Derive the classes Manager(designation, clubdues), Scientist(deptname, publications) and Labourer fromEmployee class. Write a C++ menu driven program

1.    to accept  the details of ‘n’ employees

2.    to display the information

3.    to display all the scientist from “Chemistry Department”.



#include<conio.h>
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
char ans[20];
int ch,n,a=0,b=0,i,cnt;
class employee
{
protected:int empcode;
       char empname[20];
};
class manager:protected employee
{
protected:char desg[20];
      int dues;
public:void accept1();
       void display1();
}m[10];
void manager::accept1()
{
cout<<"\n enter employee code:-";
cin>>empcode;
cout<<"\n enter employee name:-";
cin>>empname;
cout<<"\n enter designation:-";
cin>>desg;
cout<<"\n enter club-dues:-";
cin>>dues;
}
void manager::display1()
{
cout<<empcode<<"\t"
<<empname<<"\t"
<<desg<<"\t"
<<dues<<"\n";
}
class scientist:protected employee
{
protected:char dept[20],pub[20];
public:void accept2();
       void display2();
       void search(char name[20]);
}s[10];
void scientist::accept2()
{
cout<<"\n enter employee code:-";
cin>>empcode;
cout<<"\n enter employee name:-";
cin>>empname;
cout<<"\n enter department name:-";
cin>>dept;
cout<<"\n enter the publication:-";
cin>>pub;
}
void scientist::display2()
{
cout<<empcode<<"\t"
<<empname<<"\t"
<<dept<<"\t"
<<pub<<"\n";
}
void scientist::search(char name[20])
{
int i,cnt;
for(i=0;i<b;i++)
      {
       cnt=strcmp(name,ans);
       if(cnt==0)
       cout<<"\n scientist is chemistry department is:-"<<s[i].empname;
       }
}
int main()
{
int temp;
clrscr();
while(1)
{
cout<<"\n 1:accept the details";
cout<<"\n 2:display the information";
cout<<"\n 3:to display all the scientist of chemistry department";
cout<<"\n 4:exit";
cout<<"\n enter your choice";
cin>>ch;
switch(ch)
{
case 1:cout<<"\n enter how many employee:-";
       cin>>n;
       for(i=0;i<n;i++)
       {
       cout<<"\n whose information you want to enter";
       cout<<"\n press 1:for manager";
       cout<<"\n press 2:for scientist";
       cin>>temp;
       if(temp==1)
       m[a++].accept1();
       else
       s[b++].accept2();
       }
       break;
case 2:for(i=0;i<a;i++)
       m[i].display1();
       for(i=0;i<b;i++)
       s[i].display2();
       break;
case 3:strcpy(ans,"chemistry");
       s[i].search(ans);
       break;
case 4:exit(0);
default:cout<<"\n you entered wrong choice";
       }
}
getch();
return 0;
}


==========================================

OUTPUT


enter your choice1

enter how many employee:-2

whose information you want to enter
press 1:for manager                                                            
press 2:for scientist                                                          
1                                                                              

enter employee code:-112                                                             
                                                                               
enter employee name:-XYZ                                                            
                                                                               
enter designation:-ABC                                                        
                                                                               
enter club-dues:-75                                                             
                                                                               
whose information you want to enter                                            
press 1:for manager                                                            
press 2:for scientist                                                          
2
                                                                               
enter employee code:-120.                                                            
                                                                               
enter employee name:-                                                                
enter department name:-chemistry                                                
                                                                               
enter the publication:-pqr                                                     

1:accept the details                                                           
2:display the information                                                      
3:to display all the scientist of chemistry department                         
4:exit                                                                         
enter your choice2                                                             
112     XYZ     ABC      75                                                     
120     .       chemistry        pqr                                            
                                                                               
1:accept the details                                                           
2:display the information                                                      
3:to display all the scientist of chemistry department                         
4:exit
enter your choice3

scientist is chemistry department is:-.
1:accept the details
2:display the information
3:to display all the scientist of chemistry department
4:exit
enter your choice4

Write a C++ program to create class currency using operator overloading

Write a C++ program to create class currency using operator overloading:




Create a class currency containing rupees and paisa as data members.
Write a necessary member function using operator overloading for the following.
1.currency(long int rup=0,int paisa=0)
2.currency &operator +=(currency &)to add one currency to another
3.currency & operator -=(currency &) to subtracts one currency from another accept rupees & paisa from user and display it.



#include
#include
class currency
{
int r,p;
public:currency(long int rs=0,int paisa=0)
       {
       r=rs;
       p=paisa;
       }
       currency  & operator +=(currency &);
       currency  & operator -=(currency &);
};
currency & currency :: operator +=(currency &c2)
{
int a,b;
a=r+c2.r;
b=p+c2.p;
if(b>=100)
{
b=b-100;
a=a+1;
}
cout<<"\n Addition of two currency is:-";
cout<<"\n Rupees:-"<<a;
cout<<"\n Paisa:-"<<b;
return *this;
}
currency & currency::  operator -=(currency &c2)
{
int a,b;
a=r-c2.r;
b=p-c2.p;
cout<<"\n Subtraction of two currency is:-";
cout<<"\n Rupees:-"<<a;
cout<<"\n Paisa:-"<<b;
return *this;
}
int main()
{
int rs,paisa;
clrscr();
cout<<"\n\t\t Accept two currency \n\n";
cout<<"\n Enter rupees:-";
cin>>rs;
cout<<"Enter paisa";
cin>>paisa;
currency c1(rs,paisa);
cout<<"\n Enter rupees:-";
cin>>rs;
cout<<"Enter paisa";
cin>>paisa;
currency c2(rs,paisa);
c1+=c2;
c1-=c2;
getch();
return 0;
}


===================
OUTPUT:-

        Accept two currency


Enter rupees:-12
Enter paisa34
Enter rupees:-45
Enter paisa34
Addition of two currency is:-
Rupees:-57
Paisa:-68
Subtractions of two currency is:-
rupees:--33
paisa:-0

Featured posts

Happy Independence Day August 15th

 Here's a message for India's Independence Day (August 15th): "शुभ स्वतंत्रता दिवस! आजादी की 79वीं वर्षगांठ पर, आइए हम अपने देश...

Popular posts