1 / 16

CSI 218 Object Oriented Programming Sessional Lab 1

CSI 218 Object Oriented Programming Sessional Lab 1. Presented By: Nazia Hossain. In POP. Emphasis on steps/algorithm. Large programs are divided into smaller programs known as functions. Most of the functions share global data. Data move openly around the system from function to function.

maj
Download Presentation

CSI 218 Object Oriented Programming Sessional Lab 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSI 218Object Oriented Programming SessionalLab 1 Presented By: Nazia Hossain

  2. In POP • Emphasis on steps/algorithm. • Large programs are divided into smaller programs known as functions. • Most of the functions share global data. • Data move openly around the system from function to function. • Functions transform data from one form to another. • Employes top-down approach in program design.

  3. In OOP • Emphasis is on data rather than procedure • Programs are divided into what are known as objects • Data structures are designed such that they characterize the objects. • Functions that operate on the data of an object are tied together in the data structure. • Data is hidden and cannot be accessed by external functions • Objects may communicate with each other through function • New data and functions can be easily added whenever necessary • Follows bottom-up approach in program design.

  4. Basic Concepts • Objects • Class

  5. Basic Concepts (Cont.) • Benefits: • Data abstraction and encapsulation • Inheritance • Polymorphism • Dynamic binding • Message passing

  6. objects • Objects are the basic run-time entities in an object-oriented system • They may represent, a place, a bank account, a table

  7. Class • The entire set of data and code of an object can be made a user-defined data type with the help of a class. • Objects are variables of the type class • Once a class has been defined, we can create any number of objects belonging to that class • A class is thus a collection of objects of similar type. • For example: mango, apple and orange are members of the class fruit.

  8. Structure and Class • If you define a structure and then declare an object of that structure, the members of the object are public by default. • But for class in c++, the members of the class is private by default.

  9. Sample Program #include <iostream> using namespace std; int main(){ cout<<“C++ is better that C.\n”; return 0; }

  10. The iostream file • This directive causes the preprocessor to add the contents of the iostream file to the program. It contains the identifier coutthe operator <<. • Some old versions of c++ use a header file called iostream.h

  11. Namespace: • A new concept introduced by the ANSI C++ • This defines a scope for the identifiers that are used in a program • For using the identifiers defined in the namespace scope we must include the using directive, like using namespace std; • std is the namespace where ANSI C++ standard class libraries are defined. And brings all the identifiers in global scope.

  12. The operator “<<” is called the insertion or put to operator. • The operator “>>” is calledextraction or get from operator. • Casecading I/O operator: • We can use insertion operator << repeatedly for printing results. • Multiple use of << in one statement is called casecading.

  13. More Sample Program #include <iostream> using namespace std; int main(){ float number1, number2, sum, average; cout<<“enter two numbers:”; cin>>number1; cin>>number2; sum=number1+number2; average=sum/2; cout<<“sum: ”<<sum<<“\n”; cout<<“average: ”<<average<<“\n”; return 0; }

  14. #include <iostream> using namespace std; // Class Declaration class person { //Access - Specifier public: string name; int number; }; //Main Function int main() { person obj; cout<<"Enter the Name :"; cin>>obj.name; cout<<"Enter the Number :"; cin>>obj.number; cout << obj.name << ": " << obj.number << endl; return 0; }

  15. #include <iostream> using namespace std; class Box { public: int width; void printWidth( Box box ); void setWidth( intwid ); }; // Member function definition void Box::setWidth( intwid ) { width = wid; } void Box::printWidth( Box box ) { /* Because setWidth() is a friend of Box, it can directly access any member of this class */ cout << "Width of box : " << box.width <<endl; }

  16. // Main function for the program int main( ) { Box box; int width; cout<<"Enter width: "; cin>>width; // set box width without member function box.setWidth(width); box.printWidth(box); return 0; }

More Related