On Classes - 1
On Classes - 1
Set 1
1.Create a computer warehouse class in which three types of computer peripherals are stored ,for
selling.
Write a main function which prints how many of each peripheral is sold, what is the total amount
received by sales ,and a message stating whether the month’s target is achieved or not .Note that
every month , many of these items are sold .Develop the code for such a system.
2.Create an employee class in which an employee’s name , identity number , salary and number
of ‘leaves’ available are noted . Write a main function which prints all these for employees.
Note that every year , an increment is given to an employee .Also , when an employee takes leave ,
his ‘net ‘ leave reduces until after a limit ,no more leave can be sanctioned .Appropriate messages
may be given.
2.Construct an object oriented data base to carry out the following methods.These actions are to be
done for different data which is given .
A)Personal Information:
Name
Date of Birth
Blood Group
Height Weight
Contact address
Telephone number
B)Library
Accession Number
Name of the author
Title of the book
Year of Publication
Cost of the book
4. Consider a class of ‘land’ named ‘polygons’ where ‘ area’ and
‘perimeter’ are functions . From this base class ,lands of various shapes
can be derived . It is required to print the charges incurred in building
a fence around a polygon of shape rectangle and also the charges for
laying a lawn in that area. Write a C++ program for this setup.
Set 2
1. Write a program to Read and print details (name, roll no, total marks obtained) of a
student using classes in C++.
2. Write a program to print the area and perimeter of a triangle having sides of 3, 4 and 5
units by creating a class named 'Triangle' with a function to print the area and
perimeter.
3. Write a program to print the area of a rectangle by creating a class named 'Area' having
two functions. First function named as 'setDim' takes the length and breadth of the
rectangle as parameters and the second function named as 'getArea' returns the area of
the rectangle. Length and breadth of the rectangle are entered through keyboard.
4. Print the sum, difference and product of two complex numbers by creating a class
named 'Complex' with separate functions for each operation whose real and imaginary
parts are entered by the user.
5.
Create a class called 'Matrix' containing constructor that initializes the number of rows
and the number of columns of a new Matrix object. The Matrix class has the following
information:
You can assume that the dimensions are correct for the multiplication and addition.
7. The class Movie is started below. An instance of class Movie represents a film. This class
has the following three class variables:
● title, which is a Stringrepresenting the title of the movie
● studio, which is a Stringrepresenting the studio that made the movie
● rating, which is a Stringrepresenting the rating of the movie (i.e. PG13, R, etc)
a) Write a constructor for the class Movie, which takes a String representing the title of
the movie, a String representing the studio, and a String representing the rating as its
arguments, and sets the respective class variables to these values.
b) Write a second constructor for the class Movie, which takes a String representing the
title of the movie and a String representing the studio as its arguments, and sets the
respective class variables to these values, while the class variable rating is set to "PG".
c) Write a method getPG, which takes an array of base type Movie as its argument, and
returns a new array of only those movies in the input array with a rating of "PG". You
may assume the input array is full of Movie instances. The returned array need not be
full. d) Write a piece of code that creates an instance of the class Movie with the title
“Casino Royale”, the studio “Eon Productions”, and the rating “PG13”.