Professional Documents
Culture Documents
1
fields and methods that operate on those fields. The data fields and methods are bound together
within the class, creating a self-contained unit that can be used to model a particular concept or
behavior in a program.
Abstract class:
o An abstract class is a class that cannot be instantiated.
o It is designed to serve as a base class for other classes to inherit from.
o It contains at least one pure virtual function, which means that the function has no
implementation in the abstract class and must be overridden by any derived class that
inherits from it.
o Abstract classes are used to create a common interface for a group of related classes, and
to define a set of operations that the derived classes must implement.
Concrete class:
o A concrete class is a class that can be instantiated.
o It is a complete class that has a defined implementation for all of its methods.
o A concrete class does not have any pure virtual functions.
2
o It can be instantiated directly, and can also be used as a base class for other classes to
inherit from.
ix. What does the term information hiding means and how it is achieved in Object Oriented
Model?
Information hiding is a principle of software design that aims to minimize the dependencies
between different parts of a program by restricting access to implementation details and
only exposing a well-defined interface to other components. This helps to keep the code
modular, easier to maintain and modify, and reduces the risk of introducing bugs or errors.
In Object-Oriented Programming (OOP), information hiding is achieved through
encapsulation. Encapsulation is a technique of binding together the data and methods that
operate on that data, and controlling access to them through well-defined interfaces.
By encapsulating the data and methods within a class, other components of the program
can only access them through the public interfaces provided by the class, which hides the
implementation details and protects the internal state of the object from external
modification. This allows for better control over the behavior and state of objects in a
program, and helps to prevent unintended consequences and errors.
3
string idNumber; yearAdmitted = year;
int yearAdmitted; }
4
Q. No. 3 CLO3, PLO4, C6 Marks: 15
In a population, the birth rate and death rate are calculated as follows:
Birth Rate = Number of Births ÷ Population
Death Rate = Number of Deaths ÷ Population
For example, in a population of 100,000 that has 8,000 births and 6,000 deaths per year, the birth rate and
death rate are:
Birth Rate = 8,000 ÷ 100,000 = 0.08
Death Rate = 6,000 ÷ 100,000 = 0.06
Design a Population class that stores a population, number of births, and number of deaths for a period of
time. Member functions should return the birth rate and death rate. Implement the class in a program.
i. Input Validation: Do not accept population figures less than 1, or birth or death numbers less than 0.
ii. The program should continue execution until the user explicitly wants to quit (Sentinel).
iii. Implement the functions in sequence i.e. 3 x Constructors, Set Functions, Other required functions,
get/display functions, destructors.
#include <iostream> else death = z;
#include <iomanip> }
using namespace std; double getBirth()
{ return static_cast<double>(birth); }
class Population
{ double getDeath()
private: { return static_cast<double>(death); }
int population, birth, death; };