170 likes | 191 Views
Learn about the evolution of C++, from its inception as "C with Classes" to its standardization and popularity in modern programming. Discover the features that make C++ versatile and powerful, such as object-oriented programming, dynamic binding, templates, and exception handling.
E N D
C++ - - By Teeradaj Racharak 49540487 - -
Background • C++ was initially developed by Dr. Bjarne Stroustrupwith the name “C with Classes”in 1979 at Bell Labs. The idea of creating a new language came from Stroustrup’s experience in programming for his Ph.D. thesis.
Why did Dr.Stroustrup invent C++ (initially called “C with Classes”)? • He wanted to write efficient systems programs in the styles encouraged by Simula67. To do that, he added facilities for better type checking, data abstraction, and object-oriented programming to C. • The more general aim was to design a language in which he could write programs that were both efficient and elegant. Many languages force you to choose between those two alternatives. • The specific tasks that caused him to start designing and implementing C++ had to do with distributing operating system facilities across a network.
Briefly Evolution • C with Classes was used internally in AT&T in August in 1983. The name “C++” was used late that year. New features were added including virtual functions, function name and operator overloading, references, constants, user-controlled free-store memory control, improved type checking, and BCPL style single-line comments with two forward slashes(//). • In 1985, the first commercial implementation was released. It released with the name “Release 1.0” which include the version of C++ it implemented and Cfront -- Cfront is a system which translates C++ program into C program.
Briefly Evolution(cont.) • In 1989, Release 2.0 of C++ was released. New features included multiple inheritance, abstract classes, static member functions, const member functions, and protected members. • Release 3.0 of C++ evolved between 1989 and 1990. It added templates which provide parameterized types, and exception handling. • In 1988, a joint ANSI-ISO committee standardized C++.(ISO/IEC 14882 : 1988)
Language features • An object-oriented language. • Operators in C++ can be overloaded, meaning the user can create operators for existing operators on user-defined types. Moreover, C++ methods can also be overloaded, meaning the user can define more than one method with the same name, provided either the numbers or types of their parameters are different. • Dynamic binding in C++ is provided by virtual methods. These methods define type-dependent operations, using overloaded methods, within a collection of classes that are related through inheritance. A pointer to an object of class A can also point to objects classes that have class A as ancestor. When this pointer points to an overloaded virtual method, the method of the current type is chosen dynamically. • Support multiple inheritances.
Language features (cont.) • Both methods and classes can be templated which means that they can be parameterized. For example, a method can be written as a templated method to allow it to have versions for a variety of parameter types. Classes enjoy the same flexibility. • C++ includes exception handling that is significantly from that of Ada. One difference is that hardware-detectable exceptions cannot be handled. • STL ( Standard Template Library)
Contribution to Computer Languages • C++ has become a very popular language rapidly. One factor is the availability of good and inexpensive compilers. Another factor is that C programs can be compiled as C++ programs with few changes, and in most implementations it is possible to link C++ code with C code. Therefore, it’s easy for many C programmers to learn C++. In addition, at that time C++ first appeared, OOP style began to receive widespread interest and C++ was the only language that was available and suitable for large commercial software projects.
Useful Applications • C++ is one of the most popular programming language for graphical applications, such as those that run in Windows and Macintosh environments.
Sample Examples • Example1 : Introduction to the so-called “Hello World!!!”. // This is an example of "Hello World!!!" program. #include <iostream> using namespace std; int main() { cout << "Hello World!!!"; return 0; // terminate the program. }
Sample Examples (cont.) To detail the first example. • // This is an example of “Hello World!!!” program. This is a comment line. All comments will not have any effects on the behavior of the program. • #include <iostream> Lines beginning with # are directive for the preprocessor. In this case, it means to include the iostream standard files. • Using namespace std; All the elements of the standard C++ library are within the namespace named std. So in order to access its functionality, we must declare with this expression.
Sample Examples (cont.) • int main() {….} the instructions contained in this function will be the first one to be executed. • cout << “Hello World!!!”; cout represents standard output stream in C++. In addition, cout is declared in the iostream standard file within std namespace. • Return 0; The return statement causes the main function to finish. It may be followed by a return code. In our example, it’s followed by the return code 0, which means we expect our program have no errors during execution.
Sample Examples (cont.) • Example2 : How to perform numerical computations. #include <iostream> usingnamespace std; int main() { inta = 5; // initial value = 5 intb(2); // initial value = 2 int result; // initial value undetermined a =a + 3; result = a – b; cout << result; return 0; }
Sample Examples (cont.) • Example3 : How to input and output different kinds of data. #include <iostream> usingnamespace std; int main() { int i; cout << "Please enter an integer value to plus 2: "; cin >> i; cout << “The result is ”<< ((int)i + 2); // cast to int. return 0; }
Sample Examples (cont.) • Example4 : How to write and invoke a function. (part1) #include <iostream> using namespace std; int addition (int a, int b) { int r; r=a+b; return (r); } int main () { int z; z = addition (5,3); cout << “The result is ” << z; return 0; }
Sample Examples (cont.) • Example5 : How to write and invoke a function. (part2) #include <iostream> using namespace std; void printmessage () { cout << “ I’m a function!!! ”; } int main () { printmessage (); // Invoke printmessage function. return 0; }
Resource • http://www.cplusplus.com/doc/tutorial/has many documentations for C++. • http://www.research.att.com/~bs/homepage.html is the homepage of Dr.Bjarne Stroustrup who originated what we now call “C++”.