You are on page 1of 8

Homework -1

COURSE CODE: CAP 320 COURSE TITLE: PROGRAMMING WITH OBJECT ORIENTED PARADIGM

SUBMITTED TO: LECT. SUCHARU MAHAJAN

SUBMITTED BY: GURINDERPREET SINGH A86

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. 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. OBJECT 1.Object is defined as a software construct which binds data and logic method together.

2.Object is an instance of 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 Q.4. WAP to produce a multiplication table that covers the integer from 1 to 10. ANS: #include<iostream.h> #include<conio.h> void main() { int t,y,table; clrscr(); for(t=1;t<=10;t++) { for(y=1;y<=10;y++) { table=t*y; cout<<t<<"*"<<y<<"="<<table<<endl; } cout<<endl;

} getch(); }

Q.5. WAP to convert temperature in fahrenheit and display it in Celsius. Ans.:#include<iostream.h> #include<conio.h> Void main() { Float cel,far; Cout<<Enter temp in Fahrenheit:-; Cin>>far; Cel=(f-32)*5/9; Cout<<temperature in celceius is=<<cel; Getch(); }

Q.6. An election is contested by 5 candidates. The candidates are no from 1 to 5. And voting is done by marking candidate on ballet paper. WAP to read the ballet and count the votes cast for each candidate. If in a case the no write is outside the range of 1 to 5, the ballet should be considered as a spoiled ballet. You have to also count the total no of spoiled votes. 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); }

You might also like