Anda di halaman 1dari 8

Homework -1 CAP 320 PROGRAMMING WITH OBJECT ORIENTED PARADIGM

SUBMITTED TO:

SUBMITTED BY:

LECT. SUCHARU MAHAJAN

NAME : Aarti MCA2nd sem RE3004A28

Part - A Q1: Distinguish between following term. (a)Classes/ Objects (b)Data abstraction and encapsulation (c) Inheritance/ Polymorphism Ans: (a) Classes/ Objects:

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. 4.Example: Employee is a class Fruit is a class

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 DEVARATHNAM is an object ROSE is an object

b) Data abstraction and encapsulation

DATA ABSTARCTION

DATA ENCAPSULATION

1.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.

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 permits you to use the existing features of a class as it is and add a few of your own. 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.

QUES 2) Whether following are true or false and give the appropriate answer for your reason ? 1) In the procedure oriented , all the data shared by all the function. ANS : TRUE.

REASON :there is no encapsulation which bind the data and object together. And there is nothing like to make the data private in the program T` 2) The main emphasis of procedure oriented programming is on algorithm rather than data . ANS: TRUE REASON: in the procedure oriented programming ,the emphasis has given on the algorithm of the program or the logic of the program.data is free in the program.

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.

Q4: WAP to produce a Multiplication table that covers the integer from 1 to 10? Ans: #include<iostream.h> #include<conio.h> Void main() { int n, i; Clrscr(); cout<<Enter the number for print the table:; cin>>n; for(i=1;i<=10;i++) { cout<<endl; cout<< n <<*<< i <<=<< n*i; }

getch(); }

5 Ques:-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 Ques:-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<conio.h> #include<iostream.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); }

Anda mungkin juga menyukai