Open Education Resource Basics of C Work done

Open Education Resource Basics of C++ Work done as part of FDP 201 x Pedagogy for Online and Blended Teaching-Learning Process RC 1108_Group_ID_348 Vinod Mahajan (Team Leader) Dipakkumar Ashokbhai Patel Jayesh Prakash Chaudhari This work is licensed under the Creative Commons Attribution-Non. Commercial 4. 0 International License. To view a copy of this license, visit http: //creativecommons. org/licenses/by-nc/4. 0/.

Basics of C++ § Class § Object § Simple Program This work is licensed under the Creative Commons Attribution-Non. Commercial 4. 0 International License. To view a copy of this license, visit http: //creativecommons. org/licenses/by-nc/4. 0/.

Class § It is an abstract user defined data type § It is collection of similar types of objects § Syntax class_name { public: ----- Member functions/ Data members ----- private: ------Member functions/ Data members ------ protected: ------Member functions/ Data members ------ }; This work is licensed under the Creative Commons Attribution-Non. Commercial 4. 0 International License. To view a copy of this license, visit http: //creativecommons. org/licenses/by-nc/4. 0/.

Class Continue… § Member function of class can be defined inside or outside of the class § Syntax for defining member function outside the class Returntype classname : : functionname(arg list) { // code to implement function } All member function should be defined outside the class, otherwise , data abstraction rule is violated and the compiler treats them inline function. This work is licensed under the Creative Commons Attribution-Non. Commercial 4. 0 International License. To view a copy of this license, visit http: //creativecommons. org/licenses/by-nc/4. 0/.

Object § It is an instance of class. § It is run time entity. § Syntax for creating object classname obj_name; § The size of an object depends on the following factors: § § Non Static Data Members Virtual Function § If data members and virtual function is not present then size of an object is one byte. § If data members are not present and virtual function is present then size of an object is two byte. This work is licensed under the Creative Commons Attribution-Non. Commercial 4. 0 International License. To view a copy of this license, visit http: //creativecommons. org/licenses/by-nc/4. 0/.

Simple Program // Program 1: To Display Message #include <iostream. h>// Header File int main() { cout<<“n Introduction to C++”; // output statement return 0; } cout is object , << is insertion/put to operator, message to be displayed is included in “ “. This work is licensed under the Creative Commons Attribution-Non. Commercial 4. 0 International License. To view a copy of this license, visit http: //creativecommons. org/licenses/by-nc/4. 0/.

Simple Program // Program 2 Read and display the value. #include <iostream. h>// Header File int main() { int a; // variable declaration cout<<“n Enter the value of a : “; cin>>a; // read value from Keyboard cout<<“n Value of a : “<<a; // cascading of << return 0; } cin is object , >> is extraction /get from operator, This work is licensed under the Creative Commons Attribution-Non. Commercial 4. 0 International License. To view a copy of this license, visit http: //creativecommons. org/licenses/by-nc/4. 0/.

Simple Program 3 Program using class and object. #include <iostream. h>// Header File class basic // Class specification starts { int a; public: void getdata(); void putdata(); }; // class specification end void basic : : getdata()// Member function definition start { cout<<“n Enter the value of a : ”; cin>>a; } void basic : : putdata() { cout<<“n Value of a : ”<<a; } // Member function definition end int main() { basic obj; // object created obj. getdata(); // Member function call obj. putdata(); return 0; } // This work is licensed under the Creative Commons Attribution-Non. Commercial 4. 0 International License. To view a copy of this license, visit http: //creativecommons. org/licenses/by-nc/4. 0/.

Sample Questions for out of class activity Q. How many access specifiers may be present while defining a class? 1) 2 2)1 3) 3 4) 0 Q. Write syntax to create an object ? Q. Write a Simple C++ program to display value of integer variable. Sample Questions for In class activity To write simple programs like, perform arithmetic operations, find even or odd no, etc. (With or Without Class) This work is licensed under the Creative Commons Attribution-Non. Commercial 4. 0 International License. To view a copy of this license, visit http: //creativecommons. org/licenses/by-nc/4. 0/.

Thank you This work is licensed under the Creative Commons Attribution-Non. Commercial 4. 0 International License. To view a copy of this license, visit http: //creativecommons. org/licenses/by-nc/4. 0/.
- Slides: 10