1 / 12

Objects which communicate through messages and which represent a model of the re

C++ language first designed or implemented In 1980 by Bjarne Stroustrup , from Bell labs. that would receive formally this name at the end of 1983.

Download Presentation

Objects which communicate through messages and which represent a model of the re

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++ language first designed or implemented In 1980 by BjarneStroustrup, from Bell labs. that would receive formally this name at the end of 1983

  2. The design goals of C++ were the easier development of C programs and an improved support for programmers. The new fundamental concepts in C++ are: • Objects which communicate through messages and which represent a model of the re • al world through their relations. • The class concept defines user specific data types, related operators, and access functions. The data encapsulation guarantees that private objects can exclusively be accessed through specified methods. • Inheritance allows the specification of relations between classes in the sense of abstraction or specialization. Inheritance also helps to avoid multiple implementations. • A strong type concept inhibits undesired side effects for implicit type conversions like in C. The programmer has to specify a type conversion explicitly in C++. • Function and operator overloading allow to define existing functions for additional parameter types. The strong type concept allows a function call only with the parameter types defined for the function. • Efficiency: except for virtual functions, the conceptual extensions in C++ do not cause any runtime delays compared to C. Even for heavily used virtual functions in class libraries there is only a small loss in efficiency.

  3. Programming and Systax

  4. The main function This is where your code begins execution int main(int argc, char** argv); Number of arguments Array of strings argv[0] is the program name argv[1] through argv[argc-1] are command-line input

  5. Strings A string in C++ is an array of characters char myString[20]; strcpy(myString, "Hello World"); Strings are terminated with the NULL or '\0' character myString[0] = 'H'; myString[1] = 'i'; myString[2] = '\0'; printf("%s", myString); output: Hi

  6. Parameter Passing pass by value Make a local copy of a and b int add(int a, int b) { return a+b; } int a, b, sum; sum = add(a, b); pass by reference Pass pointers that reference a and b. Changes made to a or b will be reflected outside the add routine int add(int *a, int *b) { return *a + *b; } int a, b, sum; sum = add(&a, &b);

  7. Organizational Strategy image.h Header file: Class definition & function prototypes void SetAllPixels(const Vec3f &color); image.C .C file: Full function definitions void Image::SetAllPixels(const Vec3f &color) { for (inti = 0; i < width*height; i++) data[i] = color; } main.C Main code: Function references myImage.SetAllPixels(clearColor);

  8. Constructors Constructors can also take parameters Image(int w, int h) { width = w; height = h; data = new Vec3f[w*h]; }

  9. Passing Classes as Parameters If a class instance is passed by value, the copy constructor will be used to make a copy. bool IsImageGreen(Image img); Computationally expensive It’s much faster to pass by reference: bool IsImageGreen(Image *img); or bool IsImageGreen(Image &img);

  10. The Copy Constructor Image(Image *img) { width = img->width; height = img->height; data = new Vec3f[width*height]; for (inti=0; i<width*height; i++) data[i] = img->data[i]; } A default copy constructor is created automatically, but it is often not what you want: Image(Image *img) { width = img->width; height = img->height; data = img->data; }

  11. BY • KritheeSirisith ID 49540255

More Related