Trending

Object Oriented Programming Language (C++) is Better than c-programming ?

Object oriented programming (C++) language is mainly developed for overcomes the drawbacks of C++. C++ is more object oriented high-level-language use constructor and destructor which require fixed construction and principle. However, it is easier to code. C is a programming language does not adhere to the class and object concept, is the main difference between C++ and C. C++ is more secure programming language than c.

What is object oriented programming language?

Object oriented programming language is basically used to develop operating system and applications. It is developed by Bjarne Stroustrup. Object oriented programming (C++) allows the decomposition of problems into number of entities called object and and build the data and function arounds that object. Main purpose of developing C++ to overcome the drawbacks of C.

benifits of c++
Object Oriented Programming Language (C++) is Better thanc-programming ?

What are the features of object oriented programming ?

  • Emphasis on data rather than procedural oriented programming language.
  • Programs are divided into objects.
  • Data structure are designed such that they characteries the object.
  • Follow bottom-up approach in program design.
  • Simple.
  • Platform Dependent.
  • Mid-level programming language.
  • Structured programming language.
  • Rich Library.
  • Memory Management.
  • Powerful & Fast.

What is procedural oriented programming language?

Programming language using high level language such as FORTRAN,COBOL & C is commonly known as procedural oriented programming (POP). In the procedural programming the problem is viewed as a sequence of things to be done such as reading, calculating, and printing a number of function are written to accomplish those task. The primary focus is on function.

What are the characteristics of procedural oriented programming language?

  • Emphasis is on doing things (Algorithm).
  • Large program is divided into small program known as function.
  • Most of the function store global data
  • Function transform data one form to another
  • Employee top-down approach in program design.

What are the differences between C and C++?

Here’s some differences between C++ and c are given below ;

CC++
This language was developed by Dennis RitchieThis language was developed by Bajarne Stroustrap
It follows procedural approach of programs development.It follows object oriented approach of program development.
C application is faster to compile than C++C++ application is comparatively slower to compile than C.
C has comparatively less implementation than C++C++ has large implementation than C like GUI & graphics support
C does not support extensive programmingC++ directly supports programming like operator overloading, inheritance etc.

Advantages of object-oriented programming

Before knowing the advantage, you must know the basic programs:

Hello World Program

#include<iostream>

int main() {
std::cout << “Hello, World!” << std::endl;
return 0;
}

  • This program demonstrates the basic structure of a C++ program.
  • #include <iostream> includes the standard input/output stream library.
  • int main() is the main function where program execution begins.
  • std::cout is used to output text to the console, and << is the stream insertion operator.
  • std::endl is used to insert a newline character.
  • return 0; exits the program with a success status.

Variables and User Input:

#include <iostream>

using namespace std;

int main() {
int num;
cout << “Enter an integer: “; cin >> num;
cout << “You entered: ” << num << endl;
return 0;
}

  • This program demonstrates variable declaration and user input.
  • int num; declares an integer variable num.
  • cin >> num; is used to input a value from the user.
  • The program then displays the entered value.

If-Else Statement:

#include<iostream>

using namespace std;

int main() {
int num;
cout << “Enter an integer: “; cin >> num;

if (num % 2 == 0) {
cout << num << ” is even.” << endl;
} else {
cout << num << ” is odd.” << endl;
}

return 0;

}

  • This program demonstrates the use of conditional statements (if-else).
  • It checks if the entered integer is even or odd based on the remainder when divided by 2

Loops (For Loop):

#include<iostream>

using namespace std;

int main() {
for (int i = 1; i <= 5; i++) {
cout << “Iteration ” << i << endl;
}
return 0;
}

  • This program uses a for loop to print “Iteration” messages five times.
  • The loop initializes i to 1, executes while i is less than or equal to 5, and increments i by 1 in each iteration.

These are simple examples to get you started with C++. You can expand on these concepts to create more complex programs and explore advanced features of the language such as functions, arrays, classes, and templates as you progress in your C++ programming journey.

Now it’s turn for the advantages of object oriented programming.

  • Ability to simulate real-world event more effectively.
  • Code is reusable thus less code may have to written.
  • Data become active.
  • Better to create GUI
  • Easy to write and understand.
Benefit of C++

Object oriented approach

The object oriented approach main focus is on capturing the structure and behavior of information system into small modules that combines both data and process. The main aim of object oriented programming is to improve the quality and productivity of system analysis and design by making it more useable.

Object oriented concept

Object :-

An object is something that exist within the problem domain and can be identified by data (attribute and behavior). Eg: Book, Bank, Student etc.

object in C++
Class :-

Object with similar meaning and purpose known as class. A class encapsulate the data and behavior.

Abstraction :-

Data abstraction refers to providing only essential information to the outside world and hiding their details i.e. to present the needed information in program without representing the details.

Encapsulation :-

The wrapping of data and function into a single unit is known as Encapsulation. Encapsulation is the most striking feature of the class. The details not accessible to the outside world only those function which are wrapped into class and access it.

Inheritance :-

Inheritance is the process by which object of one class acquire the property of object of another class. It supports the concept of hierarchical classification.

Polymorphism :-

Polymorphism means the ability to take more than one form. A operation may exhibit different behavior depends upon the type of data used in operation.

Structure of C++ programming language

Here’s a simple program of C++, it may help you to understand how it works and it’s mechanism.

#include<iostream>using namespace std;int main(){	int num1,num2,sum;		cout<<"Enter two numbers";	cin>>num1;	cin>>num2;	sum=num1+num2;		cout<<"sum is "<<sum<<"\n";	return 0;	}
Output of simple C++ program

What is meant by <iosteram> ?

This directive cause the pre-processor to add the contents of the iostream file to the program. It contain the declaration for the identifier cout and the operator (<<). The header file iostream should be included at the beginning of any program that using input / output stream.

What are the input/output library files in C++ program

  1. <iostream> :- This files defines the cin, cout, cerr which corresponds to the standard input stream, standard output stream, the unbuffered standard stream.
  2. <iomanip> :- This file declares the service useful for performing formatted IO(input/output) with SO(shared object) called parameterized stream manipulated, such as setw( ) & set precissions. It is used to manipulate output in C++.
  3. <fstream> :- It stands for file stream. This file declares services for user defined file processing. It has ofstream and ifstream capabilities. This means it can create files, write to files, and read data from files.

Standard output stream (cout)

The predefined object cout is an instance of output stream. The cout object is connected to the standard output device which is usually the display screen. The cout is conjunction with the stream insertion operation which is <<.

Example:#include<iostream>using namespace std;int main() {char name[10]="your name" ;cout<<"my name is "<<name;return 0;}

Standard input stream (cin)

The predefined object cin is an instance of input stream. The cin is used in conjunction with the input operator >>“. This stream is usually used to read the input.

Example:#include<iostream>using namespace std;int main() {char name[10];cout<<"Enter your name";cin>>name;cout<<" my name is"<<name;return 0;}

Why we use namespace std; ?

Namespace in C++ is the declarative part where the scope of identifiers like functions, the name of types, classes, variables, etc., are declared. The code generally has multiple libraries, and the namespace helps in avoiding the ambiguity that may occur when two identifiers have the same name. using namespace std; are used because computer needs to know the code for the cout, cin functionalities and it needs to know which namespace they are defined.

What is meant by object and class?

A class definition starts with the keyword class followed by class-name and class body and enclosed by the pair of curly brackets. A class definition must be followed by either the semi-clone ( ; ) or list of declaration.

Exampleclass Box {public:int length;int breadth;int height;}

We declare the object of the class with exactly same sort of declaration that we declare the variables of basic types. Following statement declare two object of the class.

Box.box1; Box.box2;

Post a Comment

Previous Post Next Post