🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Lecture 02-2024.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Document Details

EarnestDivergence

Uploaded by EarnestDivergence

2024

Tags

C++ programming object-oriented concepts programming concepts

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

Use Quizgecko on...
Browser
Browser