Sie sind auf Seite 1von 6

HOMEWORK1 CAP320 PROGRAMING WITH OBJECT ORIENTED PARADIGM

SUBMITTED TO:LECT.SUCHARU MAHAJAN

SUBMITTED BY:DAMANDEEP SINGH B37

PART A QUES: 1 -> Distinguish between following terms : 1) Classes and objects . 2) Data abstraction and data encapsulation 3) Inheritance and polymorphisms. ANS-> 1) classes and object : CLASS 1.Class is a template(type) or blue print its state how objects should be and behave. eg consider a construction plan which is a class with this description mentioned in a plan we can constructs 'n' number of buildings of same type. These buildings are consider to be an objects come under same type of that plan. 2.Class is template for an object. 3. We can define a class as a blueprint from which the individual objects are created. Uses a new operator to create the instance of the class. Class is a logical construct. OBJECT 1.Object is defined as a software construct which binds data and logic method together.

2.Object is an instance of a class. 3)A software bundle of related state and behavior. Stores the state in fields and express it behavior through methods. The methods operate on an object's internal state. Object is a Physical reality. 4. Example : ram is an object.

4)for example:person is a class.

b) Data abstraction and encapsulation DATA ABSTARCTION Data Abstraction - Is the separation of a data type's logical properties from it's implementation. To hide the irrelevant details of the computer's view of data from our own, we use data abstraction to create another view. DATA ENCAPSULATION 1. Data Encapsulation - The separation of the representation of data from the application that use the data at a logical level; a programming language feature that enforces information hiding. The physical representation of the data remains hidden. Data hiding is a form of encapsulation in which we define access to data as a

responsibility.

2. Abstraction is taking the common elements out of a collection of types and defining a super class containing all of those elements

2. Encapsulation is the fields and methods contained by a class. Data hiding is using the private or protected keyword to keep developers without access to your source from seeing the details of your code. This is more about simplicity than security.

c) Inheritance/ Polymorphism

INHERITANCE 1. Inheritance provide you to use the existing features of a class in the derived class 2. When one object inherits functionality implemented by another. This allows you to create new objects that share base functionality with other objects, while implementing their own new, additional functionality

POLYMORPHISM 1. Polymorphism is when you refer to something as it's base class. 2. When functionality defined in some base object can vary in implementation depending on the actual object instance and what derived class it actually is. This allows you to create base objects that define and even implement a basic contract (or "interface") but allow derived classes to change the way that contract is implemented.

Q2: Whether TRUE or FALSE? Giving appropriate reason for each?? (a) In procedure object programming all the data are shared by all functions. ANS: It is true. In pop all the data is shared by all the users. Because in procedure object programming we have no option to make the data private to a particular function (b) The main emphasize of procedure object programming is on algorithm rather than on data. ANS: It is true. In procedure object programming the main emphasize on logic of the program rather than data because in POP functions can use the data of any another function because in this we have no facility to make the data private.

Q.3. Why do we need the pre-procedure directories #include<iostream> along with describe the major parts of c++ programming? Ans:- with the use of the #include<iostream.h> directive ,we can use the input and output function.because the body of these function are defined in this directive . Major parts of c++ program #include<iostream.h> Using namespace std; Void main() { Cout<<enter the number \n; Cin>>n; Cout<<the number is=<<n; Getch(); } 1. The header file used in c++ is <iostream.h>. It is used for I/O statement in program. Because the body of the inbuilt functions are defined in the header file. 2. Using namespace are new keyword added in c++, where we group all the items having similar characterstics under a single domain. Std stands for all the codes that are standard to c++ languages. 3. Main() tells the compiler that from here we have to start the execution of the program. 4. Braces are the body of the program in which all the statements written. 5. Getch () is used to see the output at the console window.

PART-B 4.W.A.P to produce a multiplication table that covers the integer from 1 to 10. Ans:#include<iostream.h> #include<conio.h> int main() { int i,n; clrscr(); cout<<Enter the number for produce multiplacation table:; cin>>n; cout<<The multiplication table for given number is:\n; for(i=1;i<=10;i++) { cout<<n<<*<<i<<=<<n*i<<\n; } getch(); return(0); }

5. W.A.P that will ask the temp in faregnheight and display in celceious. Ans:#include<iostream.h> #include<conio.h> int main() { float c,f; clrscr(); cout<<Enter the value of temp in faregnheight:; cin>>f; c=(f/9)-32; cout<<The temp in celceious is:<<c; getch(); return(0); } 6.An election is contested by 5 candidates, the candidates are numbered 1 to5 and the voting is done by marking the candidate no on the ballet paper. W.A.P to read the ballet and count the votes cast from each candidates if in a case the no is read is outside the range 1 to5 the ballet should be considered as a spoilt ballet. We have to also count total spoilt ballet. Ans:#include<iostream.h> #include<conio.h> int main() { int n,a,b,c,d,e,f; clrscr(); cout<<Press 1 for voting 1st candidate.\n; cout<<Press 2 for voting 2nd candidate.\n; cout<<Press 3 for voting 3rd candidate.\n; cout<<Press 4 for voting 4th candidate.\n; cout<<Press 5 for voting 5th candidate.\n; cout<<Enter your choice:; cin>>n; switch(n) { case 1: a++; case 2: b++; case 3: c++; case 4: d++; case 5: e++; default: f++; } cout<<The total votes for candidate 1 is:<<a; cout<<The total votes for candidate 2 is:<<b;

cout<<The total votes for candidate 3 is:<<c; cout<<The total votes for candidate 4 is:<<d; cout<<The total votes for candidate 5 is:<<e; cout<<The total spoilt votes is:<<f; getch(); return(0); }

Das könnte Ihnen auch gefallen