v
Bansilal Ramnath Agarwal Charitable Trust's
Vishwakarma Institute of Technology
(An Autonomous Institute affiliated to Savitribai Phule Pune University)
Vishwakarma Institute of Technology, 666, Upper Indiranagar, Bibwewadi , Pune, Maharashtra, INDIA - 411 037.
Contact No. +91 - 20 - 2428 3001
INTRODUCTION
C++ is a general-purpose programing language created
by Bjarne Stroustrup in 1985 as an extension of C programing language or the C
with Classes. The language has expanded significantly over time, and modern
C++ now has object oriented, generic, and functional features in addition to
facilities for low level memory manipulation as a compiled language and many
vendors provide C++ compliers.
The most important facilities that C++ adds on to C
are classes, inheritance, function overloading and operator overloading. These
features enable creating of abstract data types, inherit properties from
existing data types and support polymorphism.
In 1979, Bjarne stroustrup a Danish computer scientist
and the inventor of C++ began work on “C with Classes” in 1979. In 1982, he
started to develop a successor to C with Classes, which he named C++. In 1985,
The first edition of the C++ programming Language. The second edition of
the C++ was released in 1989. The C++ programming language was initially
standardized in 1998 by The International Organization for standards (ISO). The
current C++20 standards supersede with new features and an enlarged standard
library.
Although there are few truths and myths in this world
about the C++ programming language. These we are going to explain here:
1. To understand C++, you must first learn C
No.
Learning basic programming using C++ is far easier than with C. C is almost a
subset of C++, but it is not the best subset to learn first because C lacks the
notational support, the type safety, and the easier-to-use standard library
offered by C++ to simplify simple tasks.Naturally, in a real program, not all
arguments will be literal strings. The C version requires explicit manipulation
of characters and explicit memory management:
char*
compose(const char* name, const char* domain)
{
char*
res = malloc(strlen(name)+strlen(domain)+2);
// space for strings, '@', and 0
char*
p = strcpy(res,name);
p
+= strlen(name);
*p = '@';
strcpy(p+1,domain);
return
res;
}
It can be used
like this
char*
addr = compose("gre","research.att.com");
// …
free(addr); // release memory when done
Which version would you rather teach? Which version is easier to use? Did I really get the C version right? Are you sure? Why? Finally, which compose() is likely to be the most efficient? Yes, the C++ version, because it does not have to count the argument characters and does not use the free store (dynamic memory) for short argument string.
C++ is an Object-Oriented Language
No. C++ supports OOP and other programming styles, but is deliberately not limited to any narrow view of “Object Oriented.” It supports a synthesis of programming techniques including object-oriented and generic programming. More often than not, the best solution to a problem involves more than one style (“paradigm”). By “best,” I mean shortest, most comprehensible, most efficient, most maintainable, etc. The “C++ is an OOPL” myth leads people to consider C++ unnecessary (when compared to C) unless you need large class hierarchies with many virtual (run-time polymorphic) functions – and for many people and for many problems, such use is inappropriate. Believing this myth leads others to condemn C++ for not being purely OO; after all, if you equate “good” and “object-oriented,” C++ obviously contains much that is not OO and must therefore be deemed “not good.” In either case, this myth provides a good excuse for not learning C++
For reliable software, you need Garbage Collection
Garbage
collection does a good, but not perfect, job at reclaiming unused memory. It is
not a panacea. Memory can be retained indirectly and many resources are not
plain memory. Consider:
class
Filter
{
//
take input from file iname and produce output on file on name
public:
Filter(const
string&iname, const string&oname); //
constructor
~Filter(); //
destructor
// …
private:
ifstream
is;
ofstreamos;
//
…
};
This
Filter’s constructor opens two files. That done, the Filter performs some task
on input from its input file producing output on its output file. The task
could be hardwired into Filter, supplied as a lambda, or provided as a function
that could be provided by a derived class overriding a virtual function. Those
details are not important in a discussion of resource management. We can create
Filters like this:
void
user()
{
Filter flt {“books”,”authors”};
Filter*
p = new Filter{“novels”,”favorites”};
//
use flt and *p
delete
p;
}
From a resource management point of view, the problem here is how to guarantee that the files are closed and the resources associated with the two streams are properly reclaimed for potential re-use.
For efficiency, you must write low-level code
Many people seem to believe that efficient code must be low level. Some even seem to believe that lowlevel code is inherently efficient (“If it’s that ugly, it must be fast! Someone must have spent a lot of time and ingenuity to write that!”). You can, of course, write efficient code using low-level facilities only, and some code has to be low-level to deal directly with machine resources. However, do measure to see if your efforts were worthwhile; modern C++ compilers are very effective and modern machine 12Stroustrup Myths December 2014 architectures are very tricky. If needed, such low-level code is typically best hidden behind an interface designed to allow more convenient use. Often, hiding the low-level code behind a higher-level interface also enables better optimizations (e.g., by insulating the low-level code from “insane” uses). Where efficiency matters, first try to achieve it by expressing the desired solution at a high level, don’t dash for bits and pointers.
C++ is for large, complicated, programs only
C++ is a big
language. The size of its definition is very similar to those of C# and Java.
But that does not imply that you have to know every detail to use it or use
every feature directly in every program.In any language, writing a program
using only the built-in language features (such as if, for, and +) is quite
tedious. Conversely, given suitable libraries (such as graphics, route
planning, and database) just about any task can be accomplished with a
reasonable amount of effort.
C++
is a compiled language designed with the primary aim of delivering good,
maintainable code where performance and reliability matters (e.g.,
infrastructure [10]). It is not meant to directly compete with interpreted or
minimally-compiled “scripting” languages for really tiny programs. Indeed, such
languages (e.g. JavaScript) – and others (e.g., Java) – are often implemented
in C++. However, there are many useful C++ programs that are just a few dozen
or a few hundred lines long.
Home Assignment Activity By -
SY ME A_ Batch - 3_Group - 5
85 - Ahire Mrunal Keshav
86 - Mathpati Vaishnavi Vikas
87 - Sonawane Pushkar Mukesh
88 - Jagtap Sanket Rajendra
89 - Chavan Sanskruti Suresh
Guided By :
Prof. R. S. Patil
✌.... Informative content... Good one...
ReplyDeleteVery Useful content✌
ReplyDeleteReally helpful info!!!
ReplyDeleteReally Informative ππ
ReplyDeleteGreat work π
ReplyDeleteUseful....! ����
ReplyDeleteGreat work π
ReplyDeleteGreat job ππ
ReplyDeleteNice infoπ
ReplyDeleteGood job !!!
ReplyDeleteThey explained it so well that those who barely know anything can catch most of the things in this blog✌
ReplyDeleteVery nice work ✌π»✨
ReplyDeleteExplained well π
ReplyDeleteReally Informative ππ
ReplyDeleteGreat bhava π₯
ReplyDeleteInformative....
ReplyDeleteVery Useful content of programming
ReplyDeleteVery useful it is
ReplyDeleteNice explanation good job
ReplyDeleteNice infoπ
ReplyDeleteNice explanation π
ReplyDeleteGreat jobπ
ReplyDeleteExcellent work π
ReplyDeleteAmazing work!
ReplyDeleteGood π
ReplyDeleteAwesome!! Helpful π―
ReplyDelete