हिंदी
तमिलनाडु बोर्ड ऑफ सेकेंडरी एज्युकेशनएचएससी विज्ञान कक्षा १२

How will you access the multi-item? Explain with example. - Computer Science

Advertisements
Advertisements

प्रश्न

How will you access the multi-item? Explain with example.

संक्षेप में उत्तर

उत्तर

The list allows data abstraction in that you can give a name to a set of memory cells. For instance, in the game Mastermind, you must keep track of a list of four colors that the player guesses. Instead of using four separate variables (color 1, color2, color3, and color4), you can use a single variable ‘Predict’,

e.g.,
Predict = [‘red’, ‘blue’, ‘green’, ’green’]
What lists do not allow us to do is name the various parts of a multi-item object. In the case of a Predict, you don’t really need to name the parts:
using an index to get to each color suffices.
But in the case of something more complex, like a person, we have a multi-item object where each ‘item’ is a named thing: the firstName, the Last Name, the id, and the email. One could use a list to represent a person.

Person = [‘Padmashri’, ‘Baskar’, ‘994 – 222 – 1234’, ‘[email protected]’]
but such a representation doesn’t explicitly specify what each part represents.
For this problem instead of using a list, you can use the structure constmct (In OOP languages it’s called class construct) to represent multi-part objects where each part is named (given a name). Consider the following pseudo-code:
class Person:
creation( )
firstName: = “”
lastName: = ” ”
id: = ” ”
email : = “”
The new data type Person is pictorially represented as

The class (structure) constmct defines the form for multi-part objects that represent a person. Its definition adds a new data type, in this case, a type named Person. Once defined, we can create new variables (instances) of the type. In this example, Person is referred to as a class or a type, while p1 is referred to as an object or an instance. You can think of class Person as a cookie-cutter and p1 as a particular cookie. Using the cookie cutter you can make many cookies. Same way using class you can create many objects of that type.

shaalaa.com
Introduction to Data Abstraction
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 2: Data Abstraction - Evaluation [पृष्ठ २०]

APPEARS IN

सामाचीर कलवी Computer Science [English] Class 12 TN Board
अध्याय 2 Data Abstraction
Evaluation | Q 3. | पृष्ठ २०
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×