Ad Code

CS - 304 || Quiz 1 Correct solution solved by Vicky Lab || Fall 2020


Solution File:

Class

It is a way (Mechanism) given by c++ to realize objects in a program. It is concrete implementation of objects in c++. We capture any object attributes and behaviour in a programming language using classes.  In other words it can be defined as facility given by c++ to create new types according to our requirement. (Class is composite data type made from basic c++ types like integers, chars and float). 

Example: Consider the examples of entity lion there are many lions but all lions will have similar attributes and behaviour. Similarly consider student object all students have separate existence but all students have similar attributes and they exhibit similar behaviour.  

When we hear word student or think about student a sketch comes in our mind for student along with its attributes and behaviour. The attributes of student comes in our mind are its name, roll no, class, degree so on. Similarly the behaviour of student comes in our mind are study, register and many more. 

We need to capture the characteristic features of any object (attributes and behaviour) in the programming language. The concept of class is used for this purpose. 

Now consider the scenario having many interacting objects: a University System having many objects like student, subject, classroom, and teacher so on…we will realize all these objects in our software using classes. These all object will use the services of each other for example student will ask teacher to teach him. This approach is closer to real life instead of having simple functions being called from main here these objects will call each other to get their services. This is the reason we say that object oriented programming mimics real life. 

Uses 

Objects are structured in terms of class so our problem becomes easier to understand in the terms c++ program.  We can implement interactions easily in terms of classes. 

Student objects will interact with each other to take and give services to each other as happens in real life and mapped in object oriented programming approach. 

Now we see how class mechanism helps us in implementing real life concept. 

Type in C++ 

We implement generic concepts using types.

We have to model generic concept of Student. But there is no built in type student in c++ like built-in c++ type’s int or float. Class is mechanism in c++ that will allow us to define student as user defined type, similarly generic concept circle will also be implemented in the same way.  User define types will be, 

• Student in student management system

• Circle in a drawing software


Post a Comment

0 Comments

Close Menu