1 / 17

C++

C++. - - By Teeradaj Racharak 49540487 - -. Background. C++ was initially developed by Dr . Bjarne Stroustrup with 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.

gamache
Download Presentation

C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C++ - - By Teeradaj Racharak 49540487 - -

  2. 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.

  3. 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.

  4. 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.

  5. 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)

  6. 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.

  7. 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)

  8. 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.

  9. Useful Applications • C++ is one of the most popular programming language for graphical applications, such as those that run in Windows and Macintosh environments.

  10. 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. }

  11. 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.

  12. 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.

  13. 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; }

  14. 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; }

  15. 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; }

  16. 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; }

  17. 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++”.

More Related