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

Write a C++ program to reverse case of each alphabet in the string

Write a C++ program to reverse case of each alphabet in the string



Consider the following class mystring


class mystring
{
char str[100];
public:\\methods
};
overload operator "!" to reverse case of each alphabet in the string


#include<iostream.h>
#include<string.h>
#include<conio.h>
class mystring
{
char str[100];
public:void accept()
       {
       cout<<"\n Enter string:-";
       cin>>str;
       }
       void operator !();
};
void mystring::operator !()
       {
       int len;
       len=strlen(str);
       cout<<"\n Reverse string is:-";
       for(int i=len-1;i>=0;i--)
       cout<<str[i];
       }
int main()
{
mystring m1;
clrscr();
m1.accept();
!m1;
getch();
return 0;
}



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

OUTPUT :-


Enter string:-stop

Reverse string is:-pots

Monday, February 23, 2015

Write a visual basic program for stopwatch

Write a visual basic program for stopwatch:-

Design Window:-


Code:-

Dim starttime As Date
Dim s As Date
Private Sub Reset_Click()
Timer1.Enabled = False
starttime = Now
Timer1.Enabled = True
End Sub

Private Sub Start_Click()
starttime = Now
Timer1.Enabled = True
End Sub

Private Sub Stop_Click()
Timer1.Enabled = False
Label1.Caption = ""
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
End Sub

Private Sub Pause_Click()
If Pause.Caption = "Pause" Then
Timer1.Enabled = False
s1 = Label1.Caption
Pause.Caption = "Play"
End If
If Pause.Caption = "Play" Then
    Label1.Caption = s1
    Timer1.Enabled = True
End If
End Sub

Private Sub Timer1_Timer()
Label1.Caption = Format$(Now - starttime, "hh:mm:ss:ms")
End Sub

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



Write a visual program to calculate average using runtime textbox

Write a visual program to calculate average using runtime text-box
Design window:-

Code:

Dim t1 As TextBox
Dim t2 As TextBox
Dim t3 As TextBox
Dim t4 As TextBox
Dim a As Integer
Dim b As Integer
Dim c As Integer

Private Sub cmdClear_Click()
t1.Text = ""
t2.Text = ""
t3.Text = ""
t4.Text = ""
t1.SetFocus
End Sub

Private Sub cmdDisplay_Click()
 a = Val(t1.Text)
 b = Val(t2.Text)
 c = Val(t3.Text)
 t4.Text = (a + b + c) / 3
End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub Form_Activate()
    Set t1 = Controls.Add("VB.TextBox", "t1")
    t1.Visible = True
    t1.Height = 600
    t1.Width = 2200
    t1.Top = 100
    t1.Left = 3200
    t1.SetFocus
           
    Set t2 = Controls.Add("VB.TextBox", "t2")
    t2.Visible = True
    t2.Height = 600
    t2.Width = 2200
    t2.Top = 800
    t2.Left = 3200
       
    Set t3 = Controls.Add("VB.TextBox", "t3")
    t3.Visible = True
    t3.Height = 600
    t3.Width = 2200
    t3.Top = 1500
    t3.Left = 3200
       
    Set t4 = Controls.Add("VB.TextBox", "t4")
    t4.Visible = True
    t4.Height = 600
    t4.Width = 2200
    t4.Top = 2200
    t4.Left = 3200
End Sub

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


Write a Visual Basic program to implement the find and replace dialogue box for text-box

Design an application in Visual Basic to implement the find and replace dialogue box for text-box control with multiple line of text with 3 option buttons and check boxes

Design window of form:-

Code:-
Dim txt As String
Dim s, l, r As Integer
Private Sub Check1_Click(Index As Integer)
    If Check1(0).Value = 1 Then
        Text1.Font.Bold = True
    Else
        Text1.Font.Bold = False
    End If
    If Check1(1).Value = 1 Then
        Text1.Font.Italic = True
    Else
        Text1.Font.Italic = False
    End If
    If Check1(2).Value = 1 Then
        Text1.Font.Underline = True
    Else
        Text1.Font.Underline = False
    End If
End Sub

Private Sub cmdClear_Click()
Option1(0).Value = False
Option2(1).Value = False
Option3(2).Value = False

Check1(0).Value = 0
Check2(1).Value = 0
Check3(2).Value = 0
End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub cmdFind_Click()
txt = InputBox("enter Text to find")
l = Len(txt)
r = InStr(1, Text1.Text, txt, vbTextCompare)
Text1.SelStart = r - 1
Text1.SelLength = l
End Sub

Private Sub cmdFindNext_Click()
If r <> Len(Text1.Text) Then
    r = InStr(r + 1, Text1.Text, txt, vbTextCompare)
    Text1.SelStart = r - 1
    Text1.SelLength = l
Else
    MsgBox "No more Text", vbInformation, "Find"
End If
End Sub

Private Sub cmdReplace_Click()
txt1 = InputBox("Enter text to replace")
Text1.Text = Replace(Text1.Text, txt, txt1)

End Sub

Private Sub Form_Load()
Text1.Text = "Design an application in VB to implement the find and replace dialogue " & _
            "box for textbox control with multiple line of text with 3 option buttons and check boxes and"
End Sub

Private Sub Option1_Click(Index As Integer)
If Option1(0).Value = True Then
    Text1.Font.Name = "Arial"
ElseIf Option1(1).Value = True Then
    Text1.Font.Name = "Arial Black"
Else
    Text1.Font.Name = "Times New Roman"
End If
End Sub


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


Write a Visual Basic Program to make customer Survey and with their name and then display the survey result.

Write a Visual Basic Program to make customer Survey and  with their name and then display the survey result.
------------------------------------------------------------------------------------------
Design Window:-
 First Form :-

Second form:-

Code;-
Dim Excellent As Integer
Dim Satisfactory As Integer
Dim Average As Integer
Dim Bad As Integer
Dim Total As Integer

Private Sub cmdContinue_Click()
If optExcellent.Value Then
    Excellent = Excellent + 1
ElseIf optSatisfactory.Value Then
    Satisfactory = Satisfactory + 1
ElseIf optAverage.Value Then
    Average = Average + 1
Else
    Bad = Bad + 1
End If
txtName.Text = ""
optExcellent.Value = False
optSatisfactory.Value = False
optAverage.Value = False
optBad.Value = False
txtName.SetFocus
End Sub

Private Sub cmdQuit_Click()
Total = Excellent + Satisfactory + Average + Bad
With frmServeyResult
    .lblExcellent = Excellent
    .lblSatisfactory = Satisfactory
    .lblAverage = Average
    .lblBad = Bad
    .lblExcellentPer = Format((Excellent / Total) * 100, "#0.00")
    .lblSatisfactoryPer = Format((Satisfactory / Total) * 100, "#0.00")
    .lblAveragePer = Format((Average / Total) * 100, "#0.00")
    .lblBadPer = Format((Bad / Total) * 100, "#0.00")
End With
frmServeyResult.Show
Unload Me
End Sub

========================================
OUTPUT
After entry of six customers response of first form survey result is:-



Write a Visual Basic program to find the mouse position on screen and number click made by user on screen.

Write a Visual Basic program to find the mouse position on screen and number click that is Left, Right and Double made by user on screen form .

First Design Form Window (mousepose.frm):-


Second Design Form Window (summary.frm):-

Code:- for first form

Dim cnt As Integer
Dim cnt1 As Integer
Dim cnt2 As Integer

Private Sub Command1_Click()
Form2.Show
Form2.Text1.Text = cnt
Form2.Text2.Text = cnt1
Form2.Text3.Text = cnt2
End Sub

Private Sub Form_DblClick()
cnt2 = cnt2 + 1
LblDblClick.Caption = cnt2
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
    cnt = cnt + 1
    LblLeftClick.Caption = cnt
End If
If Button = vbRightButton Then
    cnt1 = cnt1 + 1
    LblRightClick.Caption = cnt1
End If

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim strpos As String
Dim xpos As Integer
Dim ypos As Integer

xpos = X
ypos = Y
strpos = "x : " & xpos & "   y : " & ypos
Label1.Caption = strpos
End Sub

Private Sub form_load()
cnt = 0
cnt1 = 0
End Sub

Private Sub LblRightClick_Click()

End Sub



------------------------


Code for Second form summary form:-
Design Window:-

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




Second Output of Summary :-




Write a Visual Basic program to calculate Sum of the Even digits of a given number.

 Write a Visual Basic program to calculate Sum of the Even digits of a given number.
Designing window :-
Take the following tools form toolbox in form.




Code:-

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

Private Sub cmdSum_Click()
    n = Val(Text1.Text)
    While n > 0
        r = n Mod 10
        n = n \ 10
        If r Mod 2 = 0 Then
            s = s + r
        End If
        Text2.Text = s
    Wend
End Sub

Private Sub cmFxit_Click()
Unload Me
End Sub

Private Sub Form_Activate()
Text1.SetFocus
End Sub

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



Featured posts

Mongolia

 Mongolia! Mongolia is a vast and sparsely populated country in East Asia, known for its stunning natural beauty, rich history, and unique c...

Popular posts