IT1050 Object Oriented Concepts Lecture 02 PDF
Document Details
Uploaded by EarnestDivergence
SLIIT
2024
Tags
Related
- Object-Oriented Programming, Lecture 06 PDF
- Gls University Object-Oriented Programming Notes PDF
- Object Oriented Programming With C++ (Fifth Edition) PDF
- 22316 Object-Oriented Programming using C++ Sample Question Paper PDF
- Object-Oriented Programming in C++ (Level 2) PDF
- C++ Object-Oriented Programming Concepts PDF
Summary
This lecture provides an introduction to C++ programming concepts, emphasizing object-oriented programming and namespaces. It covers key elements and structures for beginning C++ programmers.
Full Transcript
IT1050- Object Oriented Concepts Lecture – 02 - C++ 1 IT1050| Object Oriented Concepts| C++| Learning Outcomes At the end of the Lecture students should be able to Write a C++ program including : - Namespaces - Variables...
IT1050- Object Oriented Concepts Lecture – 02 - C++ 1 IT1050| Object Oriented Concepts| C++| Learning Outcomes At the end of the Lecture students should be able to Write a C++ program including : - Namespaces - Variables - Sequence - Selection - Repetition - Using Input Commands and Formatting Output 2 IT1050| Object Oriented Concepts| C++| The std namespace Let’s have a look at the iostream.h header file (a simplistic view of the actual file) // iostream.h header file // this is inserted to your program when you use the command #include namespace std { // various commands related to input and output are defined here ofstream cout; To access cout, cin, endl outside the namespace ifstream cin; we have to explicitly use char endl = ‘\n’; std::cout } std::cin std::endl Everything defined in the iostream header file is defined under a namespace called std 3 IT1050| Object Oriented Concepts| C++| namespaces are used to avoid naming collisions // I could write my code for example // using the namespace FOCSLIIT // Imagine a namespace to be a folder // in your computer. FOCSLIIT::data namespace FOCSLIIT { FOCSLIIT::graphics(10,20); int data; void graphics(int x, int y); } namespace Graphics { Graphics::data void graphics(int x, int y); int mygraphics; Graphics::graphics(10,20); int data; } // Since FOCSLIIT and Graphics are // two separate namespaces (folders) namespace1.cpp // variables, functions with the same // name can exist without issues namespace2.cpp 4 IT1050| Object Oriented Concepts| C++| The std namespace The std :: before cout is required when we use names that we’ve brought into the program by the preprocessing directives #include Means cout belongs to namespace std // C++ Program // C++ Program #include #include using namespace std; int main ( ) int main ( ) { { std::cout