Object oriented programming deals with partitioning the entire programs into groups using data structures called 'objects' and assigning attributes and methods to them.Object oriented programming consists of two things:
1) classes
2) objects
CLASSES:
A class is a group of attributes of the same kind. it is used to impart object orientedness to a program. for example,pen, pencil, rubber etc belongs to a class stationary.A class is a blueprint for a data type. it cant be implemented itself, we always need an object to implement a class in a program.simple example using classes :
1) classes
2) objects
CLASSES:
A class is a group of attributes of the same kind. it is used to impart object orientedness to a program. for example,pen, pencil, rubber etc belongs to a class stationary.A class is a blueprint for a data type. it cant be implemented itself, we always need an object to implement a class in a program.simple example using classes :
class abc
{
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
A class can be used with 3 keywords:
1) public-This means the attributed included in that class can be used even outside that class
2) private-This means attributes of a class are used within that class only
3) protected-used basically in inheritance
OBJECTS:
Objects are the physical representation of classes. Classes cant be implemented without the help of the
objects.Classes are the blueprints for objects.
Syntax for creating object:
classname objectname;
for example:
box box1;
here box is a classname whereas box1 is an objectname.
PRINCIPLES OF OOPS:
1)Encapsulation
Encapsulation is the process of hiding of data implementation by restricting access to accessors and
mutators. Mutators are open ways that are used to update the state of an object, whereas concealing
the implementation of exactly how the data gets revised.
An accessor is a technique which is used to request an object about itself. In
OOP, they are generally in the form of properties, that have, under standard conditions, a get method,
that is an accessor method.However, accessor methods are not confined to properties and can be any
kind of public method that offers information about the state of the object.
2)Abstraction
Data abstraction is the easiest of principles to figure out. Data
abstraction and encapsulation are directly tied together, because a
plain definition of data abstraction is the growth and development of classes,
objects, types in terms of their interfaces and functionality, instead
of their implementation details. Abstraction denotes a model, a view,
or various other focused representation for an actual item. Its the
development of a software object to symbolize an object we can find in
the real world. Encapsulation hides the details of that implementation.
Abstraction is employed to manage complexity. Software developers use abstraction to
decompose complex models into smaller elements. As development
progress, software engineers know the overall performance they can expect from as
yet undeveloped subsystems. Thus, programmers are not burdened by
thinking about the ways in which the execution of later on subsystem
will influence the model of previous development.
3)Inheritance
Inheritance as the name suggests implies inheriting properties from one class to another.Let us take an
example,In a family child inherits properties/genes of his parents,his/her parents inherits properties/genes
of their parents and so on.The same happens in the case of classes.A class can inherit certain properties
from some other class.The class which inherits the properties from some other class is referred to as
child and the class from which the properties are inherited is referred to as base class or super-class.
4)Polymorphism
Polymorphism means a single name, numerous types. Polymorphism
manifests itself by having multiple ways all with similar name, but
slightly dissimilar functionality.
There are actually two basic types of polymorphism. Overriding, additionally
known as run-time polymorphism, and overloading, that is referred to as
compile-time polymorphism. This dissimilarity is, for method
overloading, the compiler decides which method will be
executed, and this choice is done when the code gets compiled.
Which method is going to be used for method overriding is determined at
run-time depending on the dynamic nature of an object.
Wednesday
//
Labels:
c++
//
0
comments
//
Variables are certain data types which can store values during execution of the program.The values stored in variables can be changed during the program execution.For eg. a,b,d etc.
Declaration of Variables
In order to create use of a variable in C++, they need to first declare it specifying which data type they need it to be. The syntax to declare a new variable is to write the specifier of the specified data type (like int, bool, float...) followed by a valid variable identifier.Various data types are as followed:
Name Description Size* Range*
char Character or small integer. 1byte signed: -128 to 127 unsigned:0 to 255
short int(short) Short Integer. 2bytes signed: -32768 to 32767
unsigned: 0 to 65535
int Integer. 4bytes signed: -2147483648 to 2147483647
long int (long) Long integer. 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
bool Boolean value. 1byte true
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
double Double precision floating 8bytes +/- 1.7e +/- 308 (15 digits) point number.
long double Long double precision 8bytes +/- 1.7e +/- 308 (15 digits) floating point number.
Declaration of Variables
In order to create use of a variable in C++, they need to first declare it specifying which data type they need it to be. The syntax to declare a new variable is to write the specifier of the specified data type (like int, bool, float...) followed by a valid variable identifier.Various data types are as followed:
Name Description Size* Range*
char Character or small integer. 1byte signed: -128 to 127 unsigned:0 to 255
short int(short) Short Integer. 2bytes signed: -32768 to 32767
unsigned: 0 to 65535
int Integer. 4bytes signed: -2147483648 to 2147483647
long int (long) Long integer. 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
bool Boolean value. 1byte true
It can take one of two or false
values: true or false.
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
double Double precision floating 8bytes +/- 1.7e +/- 308 (15 digits) point number.
long double Long double precision 8bytes +/- 1.7e +/- 308 (15 digits) floating point number.
//
Labels:
c++
//
0
comments
//
SAMPLE PROGRAM FOR BEGINNERS
// sample program
#include <iostream>
using namespace std;
int main ()
{
cout << "This is my first program";
return 0;
}
// sample program
This is a comment line. All lines starting with slash signs (//) are comments and don't
have any impact on the behavior of the program. The computer programmer will use them to incorporate short explanations or observations among the ASCII text file itself. In the above Example , the line may be a temporary description of what our program is or what is it all about.This is used in very large programs in order to avoid any confusion.
#include <iostream>
Lines starting with a hash sign (#) are directives for the preprocessor. They're not regular code lines
with expressions however indications for the compiler's preprocessor.In the above example, the directive #include
<cstdlib> General purpose utilities: program control, dynamic memory allocation
<csignal> Functions and macro constants for signal management
<csetjmp> Macro (and function) that saves (and jumps) to an execution context
<cstdarg> Handling of variable length argument lists
<typeinfo> Runtime type information utilities
<typeindex> std::type_index
<type_traits> Compile-time type information
<bitset> std::bitset class template
<functional> Function objects, designed for use with the standard algorithms
<utility> Various utility components
<ctime> C-style time/date utilites
<chrono> C++ time utilites
<cstddef> typedefs for types such as size_t, NULL and others
<initializer_list> std::initializer_list class template
<tuple>) std::tuple class template
using namespace std;
namespace with the name std.This line is frequent in C++ programs that use the library functions,
and actually it'll be enclosed in most of the source codes.
When you use using namespace std; you are instructing C++ compiler to use the standard C++ library. If you don't give this instruction, then you will have to use std::, each time you use a standard C++ function/entity.
int main ()
This line corresponds to the beginning of the definition of function operate. The main function is with which all C++ programs begin their execution, severally of its location among the ASCII text file. It
does not matter whether or not there is different functions with different names outlined before or when it - the instructions contained among this function's definition can continuously be the primary ones to execute in any C++ program. For that very same reason, it is essential that each one C++ programs have a main operate.
The word main is followed within the code by a combine of parentheses (()).That is because it is a function declaration: In C++, what differentiates a main declaration from different kinds of expressions are these parentheses that follow its name. Optionally, these parentheses might enclose an inventory of parameters among them. Right after these parentheses you can find the body of the main function enclosed in braces {}. What is contained within these braces is what the function does when it is executed.
cout << "This is my first program";
This line is a C++ statement. A statement may be a straightforward or compound expression which will actually turn out some result. In fact, this statement performs the sole action that generates an understandable result in our initial program.
cout represents the quality output stream in C++, which means to insert a sequence of characters (in this case the 'This is my first' program sequence of characters) in to the quality output stream (which is usually the output screen).
Notice that the statement ends with a punctuation mark character (;). This character is employed to mark the end of the statement & it should be enclosed at the end of all expression statements.
return 0;
The return statement causes the main function to finish. return may be followed by a return code (in our
example is followed by the return code 0). A return code of 0 for the main function is generally interpreted
as the program worked as expected without any errors during its execution. This is the most usual way to
end a C++ console program.
Friday
//
Labels:
c++
//
0
comments
//
Powered by Blogger.