pz01dx

Upload: jimmy-gupta

Post on 06-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 PZ01DX

    1/8

    PZ01DX Programming Language design and Implementation -4th EditionCopyrightPrentice Hall, 2000

    1

    PZ01DX - Overview of C and C++

    Programming Language Design and Implementation (4th Edition)

    by T. Pratt and M. Zelkowitz

    Prentice Hall, 2001

    Section 1.5

    Section 6.5

    Appendix A.2

    Appendix A.3

  • 8/2/2019 PZ01DX

    2/8

    PZ01DX Programming Language design and Implementation -4th EditionCopyrightPrentice Hall, 2000

    2

    C overview

    C developed in 1972 by Dennis Ritchie and Ken Thompson

    at AT&T Bell Telephone Laboratories

    Developed as language to implement UNIX on a DEC PDP-

    11. UNIX was a then small operating system to

    compete with the large Multics of MIT and GE.

    C is more of an environment than a simple language:

    The C language

    The C preprocessor (#include, #if, ...)

    The C interface assumptions (.h include files)

    The C library (Built-in functions like printf,

    malloc, ...

  • 8/2/2019 PZ01DX

    3/8

    PZ01DX Programming Language design and Implementation -4th EditionCopyrightPrentice Hall, 2000

    3

    C program structure

    C program is a sequence of procedures and globaldeclarations

    Each procedure contains local declarations, imperative

    statements, which can call other procedures

    Most data are integer data. This allows full

    flexibility since almost everything is an integer.

    More about C data storage later in semester.

    Today C and to some extent C++ have become the dominant

    language used to develop systems software (operating

    systems, compilers, utility programs, video games,etc.)

  • 8/2/2019 PZ01DX

    4/8

    PZ01DX Programming Language design and Implementation -4th EditionCopyrightPrentice Hall, 2000

    4

    C example

    1 #include

    2 const int maxsize=9;

    3 main()

    4 {int a[maxsize];

    5 int j,k;

    6 while( (k=convert(getchar())) != 0) {

    7 for(j=0;j

  • 8/2/2019 PZ01DX

    5/8

    PZ01DX Programming Language design and Implementation -4th EditionCopyrightPrentice Hall, 2000

    5

    C example

    1 #include

    2 const int maxsize=9;

    3 main()

    4 {int a[maxsize];

    5 int j,k;

    6 while( (k=convert(getchar())) != 0) {

    7 for(j=0;j

  • 8/2/2019 PZ01DX

    6/8

    PZ01DX Programming Language design and Implementation -4th EditionCopyrightPrentice Hall, 2000

    6

    C++ overview

    Developed by Bjarne Stroustrup at AT&T in 1986 as an

    extension to C.

    C++ includes essentially all of C (both good and bad

    features)

    Improves on C by adding strong typing

    Goal was to keep efficiency of C execution, while

    adding new features

    C++ adds concept of a class (borrowed from Simula,

    which was a simulation language developed from

    Algol).

    Data was defined local to a class

    Functions (methods) could access this local data

    Implemented concept of inheritance of classes

  • 8/2/2019 PZ01DX

    7/8

    PZ01DX Programming Language design and Implementation -4th EditionCopyrightPrentice Hall, 2000

    7

    C++ example

    1 #include

    2 classDataConvert {

    3 protected: int convert(char ch) {return ch-'0';}};

    4 classDataStore: DataConvert{

    5 public:

    6 int initial(char a)

    7 {ci=0; return size = convert(a);};

    8 void save(char a) {store[ci++]=convert(a);};

    9 int setprint() { ci=0; return size;};10 int printval() { return store[ci++];};

    11 int sum()

    12 {int arrsum;

    13 arrsum=0;

    14 for(ci=0;ci

  • 8/2/2019 PZ01DX

    8/8

    PZ01DX Programming Language design and Implementation -4th EditionCopyrightPrentice Hall, 2000

    8

    C++ example (continued)

    21 main()

    22 {int j,k;

    23 DataStore x;

    24 while((k=x.initial(cin.get()))!=0)

    25 {for(j=0;j0;j--)cout