Fundamentals of Programming C++ Programming Language CS 1400 Dennis A. Fairclough Version 1.1 C++ Programming Language CS 1400 Dennis A. Fairclough Version 1.1
History of C++ CPL Published by Juan SoulieLast update on Jul 19, 2008 at 2:26pmJuan Soulie History of C++ CPL Published by Juan SoulieLast update on Jul 19, 2008 at 2:26pmJuan Soulie In 1963 the CPL (Combined Programming language) appeared with the idea of being more specific for concrete programming tasks of that time than ALGOL or FORTRAN. Nevertheless this same specificity made it a big language and, therefore, difficult to learn and implement. 2 Copyright © 2008 by Dennis A. Fairclough all rights reserved.
BCPL In 1967, Martin Richards developed the BCPL (Basic Combined Programming Language), that signified a simplification of CPL but kept most important features the language offered. Although it too was an abstract and somewhat large language. 3 Copyright © 2008 by Dennis A. Fairclough all rights reserved.
B Language In 1970, Ken Thompson, immersed in the development of UNIX at Bell Labs, created the B language. It was a port of BCPL for a specific machine and system (DEC PDP-7 and UNIX), and was adapted to his particular taste and necessities. The final result was an even greater simplification of CPL, although dependent on the system. It had great limitations, like it did not compile to executable code but threaded-code, which generates slower code in execution, and therefore was inadequate for the development of an operating system. Therefore, from 1971, Dennis Ritchie, from the Bell Labs team, began the development of a B compiler which, among other things, was able to generate executable code directly. This "New B", finally called C, introduced in addition, some other new concepts to the language like data types (char). 4 Copyright © 2008 by Dennis A. Fairclough all rights reserved.
C Language In 1973, Dennis Ritchie, had developed the basis of C. The inclusion of types, its handling, as well as the improvement of arrays and pointers, along with the later demonstrated capacity of portability without becoming a high-level language, contributed to the expansion of the C language. It was established with the book "The C Programming Language" by Brian Kernighan and Dennis Ritchie, known as the White Book, and that served as de facto standard until the publication of formal ANSI standard (ANSI X3J11 committee) in Copyright © 2008 by Dennis A. Fairclough all rights reserved.
C++ Language (C with Classes) In 1980, Bjarne Stroustrup, from Bell labs, began the development of the C++ language, that would receive formally this name at the end of 1983, when its first manual was going to be published. In October 1985, the first commercial release of the language appeared as well as the first edition of the book "The C++ Programming Language" by Bjarne Stroustrup. 6 Copyright © 2008 by Dennis A. Fairclough all rights reserved.
C++ Language Enhancements During the 80s, the C++ language was being refined until it became a language with its own personality. All that with very few losses of compatibility with the code with C, and without resigning to its most important characteristics. In fact, the ANSI standard for the C language published in 1989 took good part of the contributions of C++ to structured programming. 7 Copyright © 2008 by Dennis A. Fairclough all rights reserved.
C++0x From 1990 on, ANSI committee X3J16 began the development of a specific standard for C++. In the period elapsed until the publication of the standard in 1998, C++ lived a great expansion in its use and today is the preferred language to develop professional applications on all platforms. C++ has been evolving, and a new version of the standard, c++09 (C++0x), is being developed to be published before the end of 2009, with several new features. From 1990 on, ANSI committee X3J16 began the development of a specific standard for C++. In the period elapsed until the publication of the standard in 1998, C++ lived a great expansion in its use and today is the preferred language to develop professional applications on all platforms. C++ has been evolving, and a new version of the standard, c++09 (C++0x), is being developed to be published before the end of 2009, with several new features. 8 Copyright © 2008 by Dennis A. Fairclough all rights reserved.
C++ Programming Language (C with classes) Hybrid –Procedural (C part) + –Classes (Objects) Hybrid –Procedural (C part) + –Classes (Objects) 9 Copyright © 2008 by Dennis A. Fairclough all rights reserved.
C++ Language C Language CPL BCPL B 10Copyright © 2008 by Dennis A. Fairclough all rights reserved.
Anatomy of C++ Program int main() { return 0; } int main() { return 0; } entry point (start) exit point (end/return) start/end braces 11 Copyright © 2008 by Dennis A. Fairclough all rights reserved.
How does that work? int main() { return 0; } C++ Compiler C++ Linker Windows Operating System source file.cppobject file.obj program execution (DOS Window) executable file.exe 12Copyright © 2008 by Dennis A. Fairclough all rights reserved.
Hello world program #include int main() { std::cout << “Hello world!\n”; system(“pause”); return 0; } #include int main() { std::cout << “Hello world!\n”; system(“pause”); return 0; } 13 Copyright © 2008 by Dennis A. Fairclough all rights reserved.
The Art of Programming “The process of preparing programs for a digital computer is especially attractive because it not only can be economically and scientifically rewarding, it can also be an aesthetic experience much like composing poetry or music.” Donald Knuth, The Art of Computer Programming Volume I: Fundamental Algorithms, Addison-Wesley, Reading MA, 1969 “The process of preparing programs for a digital computer is especially attractive because it not only can be economically and scientifically rewarding, it can also be an aesthetic experience much like composing poetry or music.” Donald Knuth, The Art of Computer Programming Volume I: Fundamental Algorithms, Addison-Wesley, Reading MA, Copyright © 2008 by Dennis A. Fairclough all rights reserved.
Program Anatomy #include //include file for cout, << operator and system() using namespace std; //use standard namespace int main() //main() function header & return datatype { //opening brace cout << "Hello world!\n";//cout statement system("PAUSE");//pause console return 0; //return to OS } //closing brace #include //include file for cout, << operator and system() using namespace std; //use standard namespace int main() //main() function header & return datatype { //opening brace cout << "Hello world!\n";//cout statement system("PAUSE");//pause console return 0; //return to OS } //closing brace Copyright © 2008 by Dennis A. Fairclough all rights reserved. 15
Program Pieces //starts single line comment #include provides C++ code for –cout (object) –<< insertion operator –system(…) function using namespace std; –Opens up the namespace for “standard” //starts single line comment #include provides C++ code for –cout (object) –<< insertion operator –system(…) function using namespace std; –Opens up the namespace for “standard” Copyright © 2008 by Dennis A. Fairclough all rights reserved. 16
Program Pieces int main() – function header –int – return datatype must be an integer –main – function name (identifier) –() – empty parameter list int main() – function header –int – return datatype must be an integer –main – function name (identifier) –() – empty parameter list Copyright © 2008 by Dennis A. Fairclough all rights reserved. 17
Program Pieces { - opening brace to function body } – closing brace to function body cout << “Hello world\n”; –statement that insersts (<<) string into console stream { - opening brace to function body } – closing brace to function body cout << “Hello world\n”; –statement that insersts (<<) string into console stream Copyright © 2008 by Dennis A. Fairclough all rights reserved. 18
system(“PAUSE”); –Call to system() function to pause console return 0; –returns to Operating System with no error system(“PAUSE”); –Call to system() function to pause console return 0; –returns to Operating System with no error Copyright © 2008 by Dennis A. Fairclough all rights reserved. 19
DEMO Program Copyright © 2008 by Dennis A. Fairclough all rights reserved. 20