Samuel Kioko OOP Assignment PDF

Title Samuel Kioko OOP Assignment
Author Samuel Kioko
Course Object Oriented
Institution KCA University
Pages 16
File Size 564.8 KB
File Type PDF
Total Downloads 509
Total Views 1,001

Summary

OBJECT ORIENTED PROGRAMMINGSAMUEL KIOKO18/KCAU BBIT 2 TOWN CAMPUSQUESTION ONE(a) Distinguish between:(i) Objects and classes A class is an expanded concept of a data structure, instead of holding only data, it can hold both data and functions while an object is an instantiation of a class. In terms ...


Description

OBJECT ORIENTED PROGRAMMING SAMUEL KIOKO 18/05361 KCAU BBIT 2.2 TOWN CAMPUS

Pa g e1o f 1 6

QUESTION ONE (a) Distinguish between: (i) Objects and classes A class is an expanded concept of a data structure, instead of holding only data, it can hold both data and functions while an object is an instantiation of a class. In terms of variables, a class would be the type, and an object would be the variable. (ii) Data abstraction and data encapsulation Data abstraction refers to only providing the essential information about the data to the outside world while data encapsulation is the hiding of information, where data is packaged together with its corresponding procedures (methods) and forms class and the data can only be accessed through the methods. In layman’s terms abstraction is the process or method of gaining the information while encapsulation is the process or method to contain the information. (iii) Object based and object-oriented programming languages Object based -programming is the style of programming that primarily support encapsulation and object identity while object-oriented programming supports all the features of Oops including inheritance and polymorphism. (iv) Pointer variable and reference variable A pointer variable points to a variable whose memory location is stored in it while the reference variable is an alias for a variable which is assigned to it. (b) Benefits of object-oriented programming.  Maintainable: Object oriented programming make code maintainable. This simply means that identifying errors becomes easier since the objects are vivid (encapsulation). A good OOP design should preserve an application’s maintainability. 

Reuse of code through inheritance: This is where a class (sub class) can inherit the methods and traits of another class (super class). These methods and traits can be inherited by other classes reducing the need to retype the same code in other codes.



Scalable: OOP applications are thought to be more scalable than their earlier structured programming roots. A well-defined interface provides an opportunity to reuse the code in new software. Also, it provides you will the information you require to replace the object’s interface without affecting the codes. By doing so, it becomes easy to replace aging code with newer technology and faster algorithms.



Flexibility through polymorphism: This is where a function can “shape shift” to fit in whatever class it’s called in. Like we may have a function in the parent class called volume () but may be called in different child classes with the same name, parameters but with different implementations in different classes.



Causes less breakage: Object oriented programming allows you to add functionality to older languages, but if the code doesn’t have a calling contract, then this will beak Pa g e2o f 1 6

some parts of your project. OOP allows you to improve your functionality, and won’t affect how the codes work.

QUESTION TWO (a) A program to calculate and display mean, Variance, Standard deviation of N integers. #include #include using namespace std; int main() { int i,n,numbcount=1; double mean,var,standarddev,sum=0.0,numb[100],sum2=0.0; coutn; for(i=0;i...


Similar Free PDFs