Object oriented programming language with c++
C++
The operator ++ meaning that increment in C. ++ is increment operator in C/C++.Enhancements started with the addition of classes, followed by, among other features, virtual functions, operator overloading, multiple inheritance, templates, and exception handling.
The operator ++ meaning that increment in C. ++ is increment operator in C/C++.Enhancements started with the addition of classes, followed by, among other features, virtual functions, operator overloading, multiple inheritance, templates, and exception handling.
Example Program of C++
: #include <iostream>
using namespace std;
int main()
{
cout<<’’Hello, World!’’;
return 0;
}
keyelement
- IDE- Write the code and run it and compiler(translate computer program can understand to computer can understand (1 and 0)
- Download and install codeblock( GO to codeblock.org website and click download then binary release and then download which contain mingw.setup.exe which contain both IDE and compiler and install it.
- #include <iostream> //is Preprocessor directive ( include files that is use later )
using namespace std; //( standard library )
Int main // () function through which computer program start
Cout is output stream object and << ( insertion operation )
4) variable - placeholder before variable we have to give datatype( int and float)
5) Basic arithmetic - Order of precedence, In (3==3) for testing and = for creating like int a = 5;
6) Function -
before function name type return type void( function that does not return only print) and int return type - function that return something , computer program run from top to bottom we declare before function call or do function prototype.
Function using parameter like void favNumber(int x) and function using multiple parameter int addNumber(int x, int y)
7) Class and object-
Declaring class - Class classname { access specifier(public and private): and access function and variable by using object of class.
8) using variable in classes - private variable with public function
9) Constructors - is a function which is call automatically when create object of class have no return type it initialize some variable
10) Placing class in separate file - file new class name class header, .cpp (source file) building function in same directory , In header function prototype and variable declaration and declaration in .cpp we compile .cpp and only give header file and many can build many class (100)
20) Sentinel controlled program - dynamic program while( age!=1)
21) Assignment & increment operator x+=10, x+=10, ++x(increment first)
22) for and switch - (switch(age) , reduce if statement
23) Logical operator - not multiple if statement but all in one statement (&& and ||) like if ( age >20 & money>5000)
24) Random number - 1+ (rand()%6)
28) default argument - 29) unary scope resolution - local and global variable ( ::) Inside function local variable and outside function global variable use :: inside function to use global variable if both have same name function
29 ) function overloading - build more than one function using same name of function with different data type. Make easy for user as they can print float and integer using printnumber( )
30) Recursion- Function call itself , base case (factorial) fact( int x)
31) Array - Small array by array initialize bigger array by creating a loop and passing array to function void printArray( int Array[ ] , int sizeofArray );
32) Multi Dimensional array - like table - row and column , no of row determined no of array to use and no of column determined value in each array and print out using two loop ( row and column )
33) POINTER - special type of variable that contain memory address, & is a address operator and * is pointer opearaor , pass by reference by pointer,
34) Arrow member selector operator -> two way of accessing object of class one by object (by dot .) and one by pointer (-> )
35) deconstructor- ¬ sally() and const object( )
44) const object - need const function like const sally constobj need void sally :: print() const { }
45) member initializer - if const variable then use member initializer between parameter and body
46) Composition - class can also have object of another class like people class have object of birthday class
47) friend - friend function can use object of his friend class 48) this - special pointer that save address of current object
50) Operator overloading - function
51) Inheritance- Inherit things from another class like daughter(derived class) inherit from mother( base class)
Class daughter : public mother
55) polymorphism - such enemies and nija common function have attack with different type
56) virtual function - make every enemies object to attack virtual void attack{ } Abstract classes and pure virtual ( virtual void attack( ) = 0; and derived class need to overwrite.
58) Function template- handle multiple types of data. Generic data type.
Function template with multiple parameters and template specialization - different implementation
62) Exception ( way of handling error)
64) Working in files( use in animation and game development )
# include <fstream>
Ofstream buckyfile(“shirshak.txt” )
Custom file structure ,
read custom file structure by ifstream
71) String class and string function
A variable is a storage area capable of holding a value. The variables have names to identify them. Not just variables, functions, classes, etc. also have names, which are called identifiers.The name we use to call a particular entity in a program, which is not a keyword is called “identifier”
- float area;
Here ‘float’ is a ‘keyword’, and ‘area’ is an ‘identifier’. The identifier ‘area’ is a name given to a ‘variable’ which will store a float value. Now if ‘area’ weren’t a variable, but a function, then
- float area(){
- }
Here, ‘area’ is still an identifier, But this time, the identifier ‘area’ is a name given to a ‘function’.
Class and object
The only difference between a structure and a class in C++ is that, by default, the members of a class are private, while, by default, the members of a structure are public. Class is a collection of logically related data items and the associated functions which operate and manipulate those data.The key feature of OOP is data hiding. Generally, data within a class is made private and the functions are public. So, data will be safe from accidental manipulations, while the functions can be accessed from outside the class.
class A
{
int x,y; void fu1();
public: int z; void fu2();
};
- - - - - - - - - - - - - - - - - - - - - - -
A obj1; obj1.x = 0; //generates error since x is private and can be accessed only throwing member functions
obj1.z = 0; //valid
obj1.fu1(); //generates error since fu1() is private
obj1.fu2(); //valid
No comments:
Post a Comment