Assignment No2
Assignment No2
Q.1 Create a class named 'Rectangle' with two data members- length and breadth and a
function to calculate the area which is 'length*breadth'. The class has three
constructors which are:
1-having no parameter - values of both length and breadth are assigned zero.
2 - having two numbers as parameters - the two numbers are assigned as length and breadth
respectively.
3 -having one number as parameter - both length and breadth are assigned that number.
Now, create objects of the 'Rectangle' class having none, one and two parameters and print
their areas.
Q.2 Write a program to print the names of students by creating a Student class. If no
name is passed while creating an object of the Student class, then the name should be
"Unknown", otherwise the name should be equal to the String value passed while
creating the object of the Student class.
Q.3 Create a class to print the area of a square and a rectangle. The class has two
functions with the same name but different number of parameters. The function for
printing the area of rectangle has two parameters which are its length and breadth
respectively while the other function for printing the area of square has one parameter
which is the side of the square.
Q.4 Write a program to add two distances in inch-feet using structure. The values of the
distances are to be taken from the user.
Q.5 Create a class to print an integer and a character using two functions having the
same name but different sequence of the integer and the character parameters.
For example, if the parameters of the first function are of the form (int n, char c), then
that of the second function will be of the form (char c, int n).
Q.6 Enter the marks of 5 students in Chemistry, Mathematics and Physics (each out of
100) using a structure named Marks having elements roll no., name, chem_marks,
maths_marks and phy_marks and then display the percentage of each student.