Advantage and Disadvantages of C++ programming.pptx
1. Advantages of C++
C++ programming language has many advantages over other
languages. Some of these advantages are listed as follows.
Rich Standard Library: C++ language provides the users
with a rich and useful Standard Template Library (STL). This
library has a lot of in-built methods and data structure
templates to make coding in this language efficient and quick.
OOPS Concepts: C++ language provides users with
Object-Oriented Programming concepts like class, object,
abstraction, polymorphism and much more. Hence, it acts as
a modified and better version of C programming language.
Faster Performance: C++ language is faster in
comparison to other languages like Python, Go, C#, and many
more. This makes it very useful in embedded systems and
gaming processors.
2. Efficient Compiler: C++ is a compiled language. C++
compiler is very versatile, and it can accept both procedural
programs as well as object oriented programs.
Hardware Independent: C++ language is independent of
any hardware or system design. C++ programs work on any
system that has a C++/GCC compiler installed and enabled in
it.
Large Support Base: C++ is one of the most widely used
programming languages across the globe. It has a vast
community of developers and programmers. This can be
explored on platforms like Github, Reddit, Discord, DEV, Stack
Overflow, and many more.
Advantages of C++
3. Disadvantages of C++
C++ programming language also has some disadvantages,
which are listed below:
Error Detection: C++ provides the facility of low-level design
and is very close to the hardware of the system. Hence, this may
lead the user to carry out small errors that are difficult to observe
and detect.
Large Syntax: C++ has a very lengthy code base, and many
programmers find it difficult to write such a lengthy syntax. This
has drawn backlash from the user-base of languages like Python,
Go, etc., which are easier to code and simpler to execute.
Learning Curve: As compared to Python and Go, C++ has a
very steep learning curve. Users feel that the initial building phase
is very tough to learn, and there are many concepts that beginners
find difficult to understand.
4. Facts about C++
C++ language was invented at the AT&T Bell Labs, the same place
where C language was invented.
C++ language is heavily used in NASA, where it finds applications in
flight software and command design.
C++ is the successor of the C language. The name C++ has been taken
from C only, and the increment operator ('++') signifies that this language
is the next version of C.
C++ is widely used in areas like game development, server-side
networking, TCP/IP connections, low-level design, and many more.
C++ programs begin by executing the main() function, and other
functions are redirected using the main() function only.
C++ has inherited almost all features of C, and it has incorporated
OOPS concepts from Simula68 programming language.
C++ does not support pure object-oriented programming. Programs
can be executed without the use of classes and objects, just like in
procedural languages.
There are many languages that are conceptualized using C++, and
some of those are C#, Java, JavaScript, and many more.
6. #include <iostream.h>
using namespace std;
int main()
{
float number1, number2, sum, average;
cout << ”Enter two numbers: ”; //prompt
cin >> number1; // Reads numbers
cin >> number2; //from keyboard
sum = number1 + number2;
average = sum/2;
cout<< ” Sum= “ <<sum<< ”/n”;
cout<< ” Average=” <<average<< ”n”;
return 0;
}
The output of program is:
Enter two numbers: 6.5 7.5
Sum = 14
Average = 7
Example Program on C++
7. Input operator of the C++ Programming
The statement
cin >> number1;
The identifier cin is a predefined object in C++ that
corresponds to the standard input stream. Here, this stream
represents the keyboard.
The operator >> is known as extraction or get from operator. It
takes the value from the keyboard and assigns it to the variable
on its right.
Object Insurant operator Variable
>>
cin 45.5
Keyboard
8. Cascading of I/O operators
We have used the extraction operator << repeatedly in the last
two statements for printing results. The statement
cout<< “Sum= “ << sum << “n”;
first sends the string “Sum=” to cout and then sends the value of sum.
Finally, it sends the newline character so that the next output will be in
the new line. The multiple use of << in one statement is called
cascading.
Object
Extraction operator
Variable
sum << cout
45.5
Keyboard
9. An Example with Class
One major features of Oops with C++ is classes. They
provide a method of binding together data and functions
which operate on them. Like structures in C, classes are user-
defined data types.
The below program defines person as a new data of
type class. The class person includes two basic data type
items and two functions to operate on that data. These
functions are called member functions. The main program
uses person to declare variables of its type. Class variables
are known as objects. Here, p is an object of type person.
Class objects are used to invoke the functions defined in that
10. // Program shows the use of class in C++ program
#include <iostream.h>
using namespace STD;
class person // NEW DATA TYPE
{
char name[30];
int age;
public:
void getdata(void);
void display(void);
};
void person :: getdata(void)// MEMBER FUNCTION
{
cout<< “Enter name: ”;
cin>> name;
cout<< “Enter age: ”;
cin>>age;
}
void person :: display(void)// MEMBER FUNCTION
{
cout<<”nName: ”<<name;
cout<<”nAge: ”<<age;
}
11. int main()
{
person p; // OBJECT OF TYPE person
p.getdata();
p.display():
return 0;
}
The output of program is:
Enter Name: Ravinder
Enter Age: 30
Name: Ravinder
Age: 30