You are on page 1of 16

ArguS academy

V.B-PART-III
Exception Handling

An exception is a response to an abnormal or unexpected condition occurring in a program in a program, due to which the
execution of a program may be aborted. To avoid the abrupt termination of the program, the exception is generally caught and
handled appropriately. Code is written such that in case an exception occurred, alternative action is taken instead of aborting
the program abruptly.
VB.Net used a structured mechanism to handle exceptions- the try catchend try block.
Module mtry
Sub main()
Dim a as integer=9
Dim b as integer
Dim c as integer
Try
c=a/b
System.Console.WriteLine(c)
Catch s as System.Exception
System.Console.WriteLine(Error .divide by zero)
End try
End sub
End module
When keyword
Module mtry1
Sub main()
Dim a as short
Dim b as short
Dim c as decimal
System.Console.WriteLine(Enter values of a and b)
a=System.Console.ReadLine()
b= System.Console.ReadLine()
try
c=a/b
System.Console.WriteLine(c)
Catch s as System.Exception when b=0
System.Console.WriteLine(Error..divide by zero)
Finally
System.Console.WriteLine(End of main)
End try
End sub
End module
Multiple catch block
There can be multiple catch blocks in one TryEnd Try block. The order in which these catch statements are placed is very
important. If a catch with a generic exception is placed right at the beginning followed by specific exception handlers, the specific
exception handlers will never be executed as the generic exception handler will be executed first.
Option Strict on
Module trym
Sub main()
Dim a as short
Dim b as long
a=5000
b=50000
try
a=CType(b,Short)
System.Console.WriteLine(a)
Catch s as System.OverflowException
System.Console.WriteLine(Error..value exceeds range of short)
Catch s as System.Exception
System.Console.WriteLine(Exception Occured)
System.Console.WriteLine(s)
End try
End sub
End module

Page 1

ArguS academy
Finally

V.B-PART-III

The finally Keyword is optionally used with the Try .Ent try Block when an action when an action has to be carried out regardless
of whether an exception occurred or not. If the exception occurs, the control is transferred to the catch block wherein the
statements enclosed within are executed. The control is then passed onto the finally statement.
Module trym12
Sub main()
Dim a as integer
Dim b as integer
Dim c as integer
System.Controle.WriteLine(Enter value of a and b)
a=System.Console.ReadLine()
b=System.Console.ReadLine()
try
c=a/b
System.Console.WriteLine(c)
Catch s as System.Exception
System.Console.WriteLine(Errordivide by zero)
Finally
System.Console.WriteLine(End of main)
End Try
End sub
End module

Enumeration
Enumeration are used when we need to refer to values of primitive types such as byte, short, integer and long as constants or
literals
Module m1
Enum cities as short
Ranchi
Bokaro
Dhanbad
Jamshed Pur
End Enum
Sub main()
System.Console.WriteLine(cities.Dhanbad)
End sub
End module
E.g.-ii
Enum Grade as Byte
A=100
B=80
C=70
D=60
E=40
End Enum
Module m12
Sub main()
Dim gradevalue as byte
System.Console.WriteLine(Choose one of the values: 40/60/70/80/100)
Gradevalue=System.Console.ReadLine()
Select case gradevalue
Case grade.A
System.Console.WriteLine(You got an A)
Case grade.B
System.Console.WriteLine(You got an B)
Case grade.C
System.Console.WriteLine(You got an C)
Case grade.D
System.Console.WriteLine(You got an D)
Case grade.E

Page 2

ArguS academy

V.B-PART-III

System.Console.WriteLine(You got an E)
Case Else
System.Console.WriteLine(Wrong Choice)
End select
End sub
End Module

Structure
A structure is a composite user-defined data type using which we can group data of different data types together. A structure is
useful when we wish to create a record-like structure for an entity. A structure can hold not only fields but also methods,
properties and events.
Module m12
Public structure book
Public title as string
Public author as string
Public pages as integer
Public price as single
End structure
Sub main()
Dim b as new book()
System.Console.WriteLine(Enter Book Title)
b.title=System.Console.ReadLine()
System.Console.WriteLine(Enter Author Name)
b.author=System.Console.ReadLine()
System.Console.WriteLine(Enter Page)
b.page=System.Console.ReadLine()
System.Console.WriteLine(Enter Price)
b.price=System.Console.ReadLine()
System.Console.WriteLine(Book Title &b.title)
System.Console.WriteLine(Author Name &b.author)
System.Console.WriteLine(Page &b.page)
System.Console.WriteLine(Price &b.price)
Ens sub
End module

Array within structures


Module m123
Public structure x

Public arr() as integer


End structure
Sub main()
Dim obj as x
Redim obj.arr(1)
obj.arr(0)=155
obj.arr(1)=200
st

System.Console.WriteLine(1 Values & obj.arr(0))


nd
System.Console.WrteLine(2 Values & obj.arr(1))
End sub
End module

Procedures within Structure


In addition to data members, a structure can also define functions and procedures within its declaration
Module m123
Structure stud
Public name as string
Public rollno as integer
Public sub accept()

Page 3

ArguS academy

V.B-PART-III
System.Console.WriteLine(Enter Name)
name=System.Console.ReadLine()
System.Console.WriteLine(Enter Roll No)
rollno=System.Console.ReadLine()

end sub
end structure
sub main()
dim s as stud
s.accept()
System.Console.WriteLine(The student details are)
System.Console.WriteLine(Name & s.name)
System.Console.WriteLine(Roll No &s.rollno)
End sub
End Module

Structure within structure


A structure can be declared within another structure. This can be useful when a structure contains a composite data type as it
member.
Module m321
Structure dateofbirth
Public day as integer
Public month as integer
Public year as integer
End structure
Structure stud
Public name as String
Public rollno as integer
Public dob as dateofbirth
Public sub accept()
System.Console.WriteLine(enter name)
name=System.Console.readLine()
System.Console.WriteLine(enter roll no)
rollno=System.Console.readLine()
end sub
public void acceptdob()
System.Console.WriteLine(enter day)
dob.day=System.Console.readLine()
System.Console.WriteLine(enter month)
dob.month=System.Console.readLine()
System.Console.WriteLine(enter year)
dob.year=System.Console.readLine()
end sub
end structure
sub main()
dim s as stud
s.accept()
s.acceptdob()
System.Console.WriteLine(The Student details are)
System.Console.WriteLine(Student Name & s.name)
System.Console.WriteLine(Roll No &s.rollno)
System.Console.WriteLine(Date & s.dob.day & /)
System.Console.WriteLine(Month & s.dob.month & /)
System.Console.WriteLine(Year & s.dob.year & /)
End sub
End module

Object oriented programming


Object oriented programming (oop) is based on a real world interpretation of programming elements. It is a type of programming
in which programmers define not only the data elements but also the operations that can be performed on the data elements. An
object is an entity consisting of data as well as actions.

Page 4

ArguS academy

V.B-PART-III

Object oriented programming are analogous to real words object and define not only the data elements but also define operation
that may be applied to the elements. An object can have attributes and operations.
Public class vehicle
Public companyname as string
Public price as integer
Public mileage as integer
End class
Public sub mian()
Dim car as new vehicle
Dim truck as new vehicle
System.Console.WriteLine(Enter car company name )
car.companyname=System.Console.readLine()
System.Console.WriteLine(Enter car price )
car.price=System.Console.readLine()
System.Console.WriteLine(Enter car mileage)
car.mileage=System.Console.readLine()
System.Console.WriteLine(Enter truck company name )
truck.companyname=System.Console.readLine()
System.Console.WriteLine(Enter truck price )
truck.price=System.Console.readLine()
System.Console.WriteLine(Enter truck mileage)
truck.mileage=System.Console.readLine()
end sub
end module

Methods
Methods govern the behaviour of the object. Methods in a class typically consist of action statements similar to a function or a
procedure and are written using a sub main(). End sub block
Module m145
Public class data1
Public a as integer
Public b as integer
Public c as integer
Public sub getdata()
System.Console.WriteLine(Enter two no)
a=System.Console.ReadLine()
b=System.Console.ReadLine()
c=a+b
end sub
end class
public sub main()
dim ob as new data1
ob.getdata()
System.Console.WriteLine(Value of A = & ob.a)
System.Console.WriteLine(value of B= & ob.b)
System.Console.WriteLine(sum of A & B = & ob.c)
End sub
End module
e. g. ii
Module m111
Public name as String
Public gender as char
Private age as integer
Public address as String
Public property agevalue() as integer
Set(ByVal value as integer)
age=value
end set

Page 5

ArguS academy

V.B-PART-III

get
return age
end get
end property
public sub input()
System.Console.WriteLine(Enter the name, gender and address)
name=System.Console.ReadLine()
gender= System.Console.ReadLine()
address= System.Console.ReadLine()
end sub
end class
public sub main()
dim student as new person
student.age=19
student.input()
System.Console.writeLine()
System.Console.writeLine(Student details are )
System.Console.writeLine()
System.Console.writeLine(Student Name & student.name)
System.Console.writeLine(Student Gender & student.gender)
System.Console.writeLine(Student Age & student.age)
System.Console.writeLine(Student Address & student.address)
End sub
End module

Constructor and Destructors


A constructor is a method having the same name as the class within which it is defined. This method executes automatically every
time an object is created. Constructor are typically declared public and are used for initialization purposes. Destructors are
methods that execute whenever the object goes out of scope or is destroyed.

Constructors
In VB. Net, the lifetime of an object begins when it is created with the New keywords. Constructors in VB. Net are written using
the sub New() end Sub block
Module mcon
Public class point
Public x as integer
Public y as integer
Public sub New()
System.Console.WriteLine(This is a Constructor)
System.Console.WriteLine(Enter values for point)
x= System.Console.ReadLine()
y= System.Console.ReadLine()
end sub
end class
public sub main()
dim p as new point()
System.Console.WriteLine(Point p is)
System.Console.WriteLine(Value of x= & p.x)
System.Console.WriteLine(Value of y= & p.y)
End sub
End module

Destructors
Module mdes
Public class point
Public x as integer
Public y as integer
Public sub new()
System.Console.WriteLine(This is a constructor)
System.Console.WriteLine(Enter values for point)
x= System.Console.ReadLine()

Page 6

ArguS academy

V.B-PART-III

y= System.Console.ReadLine()
end sub
overrides protected sub finalize()
System.Console.WriteLine(This is a destructor executing since object is now going to be destroyed)
End sub
End class
Public sub main()
Dim p as new point()
System.Console.WriteLine(Point p is )
System.Console.WriteLine(p.x)
System.Console.WriteLine(p.x)
End sub
End module

Overloading, Inheritance and overriding


Overloading is the process of declaring method of a class having the same name but different signatures. The signature of a
method comprises of the name of the method, the number and type of arguments. The return type of a method is not a part of
the signature and hence cannot be used as a factor for overloading.
The overloads keyword indicates that the method or property is being overloaded. It is not mandatory to use the overloads
keyword. However, once it is used with a method all subsequent overloaded methods must use it.
Procedure and function Overloading
Module m121
Class x
Sub max(a as integer, b as integer)
Dim c as integer
c=a+b
System.Console.WriteLine(Sum of a and b is & c)
End sub
Sub max(s1 as String, s2 as String)
Dim s3 as String
s3=s1+s2
System.Console.WriteLine(the combined string is & s3)
End sub
End class
Sub main()
Dim y as new x()
y.max(10,15)
y.max(Argus, Academy)
end sub
end module
Constructor overloading is a special case of method overloading. Parameterized constructors that satisfy the rule for overloading
can be used within classes.
Module m1234
Class base
Public sub new()
System.Console.WriteLine(Parameterless constructor )
End sub
Public sub new(x as integer)
System.Console.WriteLine(integer parameter constructor )
End sub
Public sub new( s as String)
System.Console.WriteLine(String parameter constructor )
End sub
End class
Sub main()
Dim b1 as new base()
Dim b2 as new base()
Dim b3 as new base(Hello)
End sub

Page 7

ArguS academy

V.B-PART-III

End module

Property Overloading
Just as procedures and function can be overloaded, properties within a class too can be overloaded.
Module m1
Public class x
Private addr as string
Private addr2 as sting
Overloads public property address() as string
Set(Byval add as String)
addr=add
end set
get
return addr
end get
end property
overloads public property Address (s as string) as string
set (Byval add as string)
addr2=add
end set
get
return addr2
end get
end property
end class
public sub main()
Dim y as new x()
Dim s as String
System.Console.WriteLine(Enter Company Address)
y.address()=System.Console.ReadLine()
System.Console.WriteLine(Enter residence address)
y.address(residence)=System.Console.ReadLine()
System.Console.Writeline(the residence Address is :)
System.Console.Writeline(y.address(residence))
System.Console.Writeline(the Company Address is :)
System.Console.Writeline(y.address())
End sub
End module

Inheritance
Inheritance is the process of creating classes based on existing classes. Inheritance is based on the principle of code reuse. Instead
of creating a class from scratch, we can add new methods, properties, and events to existing classes, thus saving time and effort.
The class based on which the new class is created is called base class or parent class and the class that is created is called derived
or child class.

Access Modifiers and inheritance


With respect to inheritance, access modifiers play a very importance role. In VB. Net, there are five access modifiers that are
relevant to inheritance : Public, private, protected, Friends and protected friend
-

All public elements of a class are inherited by its derived classes.


Private elements of a class cannot be inherited by derived class.
Protected access for elements denotes that elements may be used within the derived class but not outside the derive
class.
Friend access modifier is used to denote that the element is accessible throughout the program in which the class is
defined.
Protected Friend access modifier indicates that the elements bears features of both protected and friend modifiers.

Module m123
Public class x
Public j as integer

Page 8

ArguS academy

V.B-PART-III
Private k as integer
Protected l as integer
Friend m as integer
Public sub test()
l=100
end sub

end class
public class y
Inherits x
Public n as integer
End class
Public sub main()
Dim a as new x()
Dim b as new y()
a.j=100
a.m=100
a.test()
b.j=120
b.m=130
b.test()
b.n=150
System.Console.WriteLine(Value of j in base class & a.j)
System.Console.WriteLine(Value of m in base class & a.m)
System.Console.WriteLine(Value of j in derive class & b.j)
System.Console.WriteLine(Value of m in derive class & b.m)
System.Console.WriteLine(Value of n in derive class & b.n)
End sub
End module

Inheriting Constructor and destructor


Constructor and destructors are by default, inherited by derived classes.
Module m1
Class base
Public sub new()
System.Console.WriteLine(Constructor of Base class)
End sub
End class
Class child
Inherits base
End class
Sub main()
Dim b as new base()
System.Console.WriteLine(Now creating child class object)
Dim c as new child()
End sub
End module

Destructor is inherited by a derived class


Module md
Class base
Public sub new()
System.Console.WriteLine(Constructor of Base class)
End sub
Overrides protected sub Finalize()
System.Console.WriteLine(Destructor of Base Class)
End sub
End class
Class child
Inherits base
End class

Page 9

ArguS academy

V.B-PART-III

Sub main()
Dim b as new base()
System.Console.WriteLine(Now creating child class object)
Dim c as new child()
End sub
End module

Abstract Classes
An abstract class is a class that cannot be instantiated. In other words, an abstract class cannot be used to create objects. It is
generally used as a template to derive other classes. An abstract class typically has abstract methods which are only method
declaration without any implementation.
Module m1
MustInherit class absbase
Public sub test()
System.Console.WriteLine(Abstract Base Class)
End sub
MustOverride Sub AnotherTest()
End class
Class child
Inherits absbase
Overrides sub AnotherTest()
System.Console.WriteLine(Implementing abstract method)
End sub
End class
Sub main()
Dim c as new child()
c.test()
c.AnotherTest()
end sub
end molude

Final classes
Final classes in VB.Net are market with the NotInheritable keyword. Final classes cannot have derived classes but can be used to
create objects.
Module m1
NotInheritable class one
Public sub test()
End sub
Public sub test(x as integer)
System.Console.WriteLine(value is & x)
End sub
End class
Sub main()
Dim f as new one()
f.test()
f.test(100)
end sub
end module

Overriding
Overriding is the process of overwriting the methods or properties of a base class in a derived class. In case of method overriding,
the return type, name and arguments of the method in the derived class must be the same as that of the method being
overridden. When an object of the derived class invokes the overridden method, it will be the derived class implementation that
will be called.
The base class method must be marked with the keyword Overridable and the derived class method must be marked with the
keyword Overrides.
Module m12
Class base
Overridable public sub test(a as integer, b as integer)
System.Console.WriteLine(Answer is & a+b)
End sub
End class

Page 10

ArguS academy

V.B-PART-III

Class child
Inherits base
Overrides public sub test(a as integer, b as integer)
System.Console.writeLine(Answer is & a*b)
End sub
End class
Sub main()
Dim b as new base()
Dim c as new child()
b.test(10,20)
c.test(10,20)
end sub
end module

Shadows keyword
If we wish to hide an inherited methods within a derived class, and invoke an overridden version of the method, then we use the
shadows keyword cannot be used with the overloads keywords.
Module m12
Class base
Public sub test()
Public sub test()
End sub
Public sub test(x as integer)
System.Console.writeLine( value from base class & x)
End sub
End class
Class child
Inherits base
Shadows sub test(y as integer)
System.Console.writeLine(value from child class & y)
End sub
End class
Sub main()
Dim c as new child()
c.test(100)
end sub
end module

MyBase Keyword
This keyword is used to refer to the base class method in a derived class that has overridden methods of the base clasystem.s
MyBase cannot act as a variable nor does it contain any value that can be passed or assigned. MyBase refer to the immediate base
class and its inherited members. It can be used to access only public and protected members of the base class.
Module m12
Public class animal
Overridable public sub eats()
System.Console.WriteLine(Eats Food)
End sub
End class
Public class cow
Inherits animal
Overrides public sub eats()
System.Console.WriteLine(Eats grass)
End sub
Public sub eating()
MyBase.eats()
System.Console.WriteLine(is a herbivorous animal )
End sub
End class
Sub main()
Dim a as new animal()
Dim c as new cow()
c.eating()

Page 11

ArguS academy

V.B-PART-III
c.eats()

end sub
end module

MyClass keyword
This keyword opposite to the way in which MyBase keyword works. Assume that a base class method is overridden in a derived
class. If the object that is used to invoke the method is of type derived class.
Module m12
Public class animal
Overridable public sub eats()
Systen.console.WriteLine(Animal eats food)
End sub
Public sub eatinghabits()
System.Console.WriteLine(Calling method directly)
Eats()
System.Console.WriteLine(Calling method using myclass)
Myclass.eats()
End sub
End class
Public class cow
Inherits Animal
Overrides public sub eats()
System.Console.WriteLine(Cow eats grass)
End sub
End class
Sub main()
Dim c as new cow()
c.eats()
c.eatinghabits()
end sub
end module

Interfaces, Namespaces and Collection


Interface
Interfaces are similar to classes except that they have no implementation. Methods are only declared within an interface and do
not contain any code. An interface cannot be instantiated. It is typically implemented by a class using the implements keyword. An
interface is defined using the interface . End interface keywords .
Module m12
Public interface I
Sub First()
Sub Second()
End Interface
Public class x
Implements I
Sub First() Implements I.First
System.Console.WriteLine(Implementation of first method)
End sub
Sub Second() Implements I.Second
System.WriteLine(Implementation of second method)
End sub
End class
Public sub main()
Dim y as new x()
y.First()
y.Second()
end sub
end module

Multiple Inheritance
Module m1
Public Interface I
Sub test()
End Interface

Page 12

ArguS academy

V.B-PART-III

Public class T
Public Sub Testing()
System.Console.WriteLine(Method Testing)
End sub
End class
Public class x
Inherits T
Implements I
Sub Test() Implements I.Test
System.Console.WriteLine(Implemented method)
End sub
End class
Public sub main()
Dim y as new x()
y.test()
y.testting()
end sub
end module

Namespaces
In VB. Net class libraries are comprised of namespaces. Namespace are used to organize nested entities such as other namespace,
classes, interfaces and so on. Namespace take care of the way in which program elements are exposed to other programs with the
help of various access modifiers. Modules and classes are generally put inside namespaces.
A namespace declaration consists of the keyword Namespace followed by a qualified identifier that servers as the namespace
name. Optional namespace member declarations as enclosed between Namespace and End Namespace keywords.
Namespace plants
public class abc
public fname as String
public lname as String
public sub print()
System.Console.WriteLine("First name " & fname)
System.Console.WriteLine("Last Name " & lname)
end sub
end class
end Namespace
save this file filename.vb
module m1
sub main()
dim s as new plants.abc
System.Console.WriteLine("Enter first name")
s.fname=System.Console.ReadLine()
System.Console.WriteLine("Enter Last name")
s.lname=System.Console.ReadLine()
s.print()
end sub
end module
Save this file test.vb
The option /t: library is include with the vbc command to compile a .vb file to a dll file.

Page 13

ArguS academy

V.B-PART-III

Example 2
Imports plants
Module m1
Sub main()
Dim s as new String
s.fname=Argus
s.fname=Academy
s.print()
end sub
end module

Collection
A collection is a term used to describe a means of grouping and managing related entities. In VB.Net, a collection is used to
manage object that are exposed by a class. The simplest way to do this is to create a public instance of type
System.Collection.ICollection- This interface provides a count() method that counts the total number of items in a collection. It
also provides additional methods for advanced operations like multithreading.
System.Collection.IEnumerable- This interface exposes an object that implements IEnumeration interface. This is used
whenever a collection contains objects.
System.Collections.IList-this interface provides list type access to a collection. It provides methods to add, remove and search
for items or objects in a collection.
Module m1
Public class book
Public title as string
Public author as string
Public sub new()
System.Console.WriteLine(Enter Book Title)
title=System.Console.ReadLine()
System.Console.WriteLine(Enter Author Name)
author=System.Console.ReadLine()
end sub
end module
public bookCollection as new Microsoft.VisualBasic.Collection
public sub main()
dim b as new book()
dim c as new book()
dim d as new book()
bookCollection.Add(b)
bookCollection.Add(c)
bookCollection.Add(d)
dim i as integer
System.Console.WriteLine()
System.Console.WriteLine(list of Book Titles: )
Syste.Console.WriteLine()
For I to bookCollection.count()
System.Console.WriteLine(bookCollection.item(i).title())
next
end sub
end module
The Code declares a class called Book having Title and Author as its data members and a construction method which reads in
values for these data members from the used.

Strongly typed Collection


With a simple non-typed collection, any object can be added to the collection. Since it may not be possible to implicitly convert
the element type of the collection to the type of the collection to the type of the iteration value, this feature can cause problems
later at runtime if we use a for.each loop to iterate through the collection. The for .. each next loop is used with array or
collections. The statements within the loop are executed for each element within the array or collection until all the elements
have been iterated

Page 14

ArguS academy

V.B-PART-III

Module m1
Enum Color
Amber
Purple
Tan
Blue
Black
Grey
Whyte
End Enum
Public class colorCollection
Inherits System.Collections.CollectionBase
Public function add(ByVal col As Color ) As Integer
MyBase.List.Add(col)
End function
Public sub insert(ByVal I as Integer, ByVal c as Color)
List.Insert(I,c)
End sub
Public sub Remove (ByVal c as Color)
List.Remove(c)
End
Default property item(ByVal I as Integer ) As Color
Get
Return CType(MyBase.List(i),Color)
End get
Set(ByVal c as Color)
myBase.List.Item(i)=c
end set
end property
end class
sub main()
dim col as new ColorCollection()
col.Add(Color.Amber)
col.Add(Color.Purple)
col.Add(Color.Tan)
col.Add(Color.Blue)
col.Add(Color.Black)
col.Add(Color.Grey)
col.Add(Color.White)
dim shade as Color
for each Shade in col
System.Console.WriteLine(shade.ToString)
Next
Shade =col(1)
System.Console.WriteLine(shade & shade.ToString)
System.Console.WriteLine()
Try
Dim n as integer =col.count()
System.Console.WriteLine(Last item added to the collection is & col.item(n-1).ToString())
Col.add(just some text)
Catch e as System.Exception
System.Console.WriteLine(e.Message)
End try
End sub
End module

Page 15

ArguS academy

V.B-PART-III
Assignments Structure Exception Handling

1. WAP to store information of 10 employees and to display information of an employee depending upon the employee no
2. WAP to accept 5 students marks from user and print the students result using structure array inside it.
3. Write a program to accept 2 numbers from the user and calculates their product. Appropriate exception handling code
must be written to take care if the product of the two numbers is very large and does not fit into the data type.

Assignments Class & Object constructor


1. WAP class name student, data member String name, integer rollno, double m1,m2,m3, total, per
Member function sub getdata()- accept the name, rollno, and 3 marks from user. Sub calculate()Calculate the total and percentage. Sub display()- display all the information and grade, grade depends on percentage
Per>=95 Grade A*
Per>=80 and per<95 Grade A
Per>=70 and per<80 Grade B*
Per>=60 and per<70 Grade B
Per>=50 and per<60 Grade C
Per>=33 and per< 50 PASS
2. WAP class name counter, data member : integer count
Member function:
Init()
function that initializes count to 0
Inccount()
increment count by 1
Givecount()
returns the value of count
Design a program use this class counter to count the number of ladies, the number of gentlemen and the number of
children in a guest list. The guest list is stored as a character type array guest(). It consists of the following codes
Code
stands for
G
gentleman
L
lady
C
child
3. Declare a class to represent bank account of 10 customers with the following data member : name of depositor, Account
Number, type of account (s for savings and c for current account), Balance amount. The class also contains following
member functions:
- To initialise data members.
- To deposit money
- For withdrawal of money after checking the minimum balance (minimum balance is Rs. 1000)
- To display the data member.

Assignments Inheritance
1. WAP to read and display information about employees and managers. Employee is the base class and Manager is the sub
class
2. WAP to display the area of circle, area of rectangle and area of cylinder all variable will be declared in super class by using
the inheritance.
3. Write a program to declare a class student. This class should have two derived classes graduate and undergraduate. The
class student should have a method test() that should print a message This is a student . This method should be
overridden in the derived classes to print the messages this is graduate and This is undergraduate respectively . write
the code such that in the main block, first only this is a student is displayed no matter which Test() method is invoked.
4. Write a program that will create a namespace N with a class X having three integer members A,B and C. these members
are declared public. Make use of this namespace N and X in another namespace M having a class Y. this program should
assign the values 100,200 and 300 to the three integer members of class X. Finally display the sum of the three integer
variables

Page 16

You might also like