c tour
play

C++ Tour About me: Piyush Kumar Phone: 645-2355 Email: - PDF document

Administrative Trivia C++ Tour About me: Piyush Kumar Phone: 645-2355 Email: piyush@cs.fsu.edu For : COP 3330. Object oriented Programming (Using C++) Office hours: Tuesday 4:30 to 5:30. http://www.cs.fsu.edu/~piyush/teach/3330 TAs:


  1. Administrative Trivia C++ Tour About me: Piyush Kumar Phone: 645-2355 Email: piyush@cs.fsu.edu For : COP 3330. Object oriented Programming (Using C++) Office hours: Tuesday 4:30 to 5:30. http://www.cs.fsu.edu/~piyush/teach/3330 TAs: Biswas Parajuli, Daniel Mock, More details on the course information sheet. Piyush Kumar James Parsons Administrative Trivia Your ID TAs: You have been assigned an ID on the Blackboard. You should know your ID. Biswas Parajuli, (Sec: 15, 17) You will use your FSU ID to setup your Daniel Mock, (Sec: 10, 16) bitbucket account. https://bitbucket.org/ James Parsons. (Sec: 2) Office hours will be held in MCH 315A. Subject to change. More details on the course information sheet. Announcement Announcement  First Quiz : Now  Blackboard Discussions already  Revise your previous C/C++ material. setup. - Your C++ background will be tested soon.  Make sure you submit the pre-req  Your first assignment is online. form today before you leave.  Will be due on Tuesday, 1/17/17.  Bitbucket setup of ssh keys.  You are required to setup your  ssh-keygen – t rsa –C “fsu email” bitbucket repository by this Thursday.  Add it to bitbucket ssh-keys (without The submission will use the adding \n) blackboard account.  hg clone project1 1

  2. Why learn C++? C++ Tour  Ubiquitous  Object Oriented  Easier large scale projects  Resuability  High Performance C++ Features When to use C++?  Large projects  Supports data security  System applications  Prevents accidents with data  Graphics  Helps code reuse.  Data Structures  Lets you use operators the way you  Speed is an issue? like.  Changes in functionality required.  Allows multiple functions/operators  Need exceptions and error handling? with the same name.  Want to speed up your scripts? When not to use C++? Important definitions  Algorithm: Ordered set of actions to  Small system programs. accomplish a certain task.  Fast prototyping.  Program: Implementation of  Web-based applications (Perl/Python) algorithms.  Compiler, function, library, bug.  Variables, constants.  Keywords (if, while, for,…)  Data Types. (long, int, …) 2

  3. Compiling/Running Lynda.com programs  Single source file code:  Up and running with vi  g++ -g – Wall – std=c++1y simple.cpp – o  By David D. Levine simple  Compilation / Editing Demo  1.5 hour video course in vim  Editors: vim / xemacs  Your homework for this weekend is to  Xemacs tutorial: int main() { watch and practice vim hanson.geog.udel.edu/cmg/Handouts/ xema return 0; cs _ tutorial .pdf }  Vi/vim tutorial : http://www.biochem.ucl.ac.uk/~mckenzie/vim /tutorial.html simple.cpp simple.cpp int main() // Function Declaration  On Unix: echo $? // Function body follows  On Windows: echo %ERRORLEVEL% { // Block of statements begins. return 0; } // Block ends. System dependent Simple.s (using g++ -O – S simple.cpp) Simple.s (using VC++ 05 compiler) //{ .file “simple.cpp" 00411360 push ebp .def ___main; .scl 2; .type 32; .endef 00411361 mov ebp,esp .text 00411363 sub esp,0C0h .align 2 00411369 push ebx .p2align 4,,15 0041136A push esi 0041136B push edi .globl _main 0041136C lea edi,[ebp-0C0h] .def _main; .scl 2; .type 32; .endef 00411372 mov ecx,30h _main: 00411377 mov eax,0CCCCCCCCh pushl %ebp ; Save base pointer 0041137C rep stos dword ptr es:[edi] movl $16, %eax // return 0; movl %esp, %ebp ; Set up stack frame for debugger 0041137E xor eax,eax subl $8, %esp ; Save space on the stack //} 00411380 pop edi andl $-16, %esp ; Align stack pointer 00411381 pop esi call __alloca ; Platform dependent call 00411382 pop ebx call ___main ; Platform dependent call 00411383 mov esp,ebp leave ; free space, pop ebp, esp… 00411385 pop ebp xorl %eax, %eax ; zero eax 00411386 ret ret ; return control to calling procedure. 3

  4. G++ Compilation. preprocessing (to expand macros) Introduction to C++  Try “ cpp simple.cpp > simple.i ”  compilation (from source code to assembly language)  Try “ g++ -Wall – S simple.i ”   assembly (from assembly language to machine code) Try “as simple.s -o simple.o ”  linking (to create the final executable)  Try “ gcc simple.o ”  Equivalent to “ ld -dynamic-linker /lib/ld-linux.so.2  /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc- lib/i686/3.3.1/crtbegin.o -L/usr/lib/gcc-lib/i686/3.3.1 hello.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /usr/lib/gcc- lib/i686/3.3.1/crtend.o /usr/lib/crtn.o ” $ file ./a.exe  Identify type of file generated (gcc on windows). ./a.exe: PE executable for MS Windows (console) Intel 80386 32-bit Organization C++ is a superset of C.  C++ = C + objects + …  Features present in C are also present in  Main Theme : Objects C++  Class Vs Object  C++ is a object oriented programming language ( C++ = c + objects + …)  Data Hiding and Abstraction  Encapsulation  OOP is about objects which contain data  Inheritance and functions to manipulate that data.  Operator and Function Overloading  A single unit that contains data and  Polymorphism. functions that operate on the data is called an object .  Generic Programming Main Theme: objects OOP  C++ enables you to focus on discrete  Based on concept of objects and objects that contain both data and classes. functions to manipulate that data.  Objects: Represent entities with  Instead of data and functions as related state and behaviour separate entities as was the case in  Instances of a class C.  Classes: Define common  Application = Collection of Objects. characteristics of similar objects.  Makes complex programs easy to code. 4

  5. Objects/Classes Object / Class Example Car Class  Objects are reusable self-contained Attributes: Behavior: Manufacturer Accelerate programming modules with data and Model Break Color Steer functions. Engine Tune Up  Classes are blue-print for objects with common properties, attributes, operations and behaviors. The principal building blocks of OO programs are classes and objects. Objects: Instantiations of classes. Another Object / Class Fundamental building block example of OOP: A Class  A class defines a data type, much like class Point { a struct would be in C. int _x, _y; // point coordinates  A class is a source code for an object public: // begin interface section (hence it has both data+ member void setX(const int val); functions) void setY(const int val); int getX() { return _x; } int getY() { return _y; } Attributes … }; Point tpoint; // defines an object tpoint class Methods … Fundamental building block Data Hiding of OOP: A Class  Objects contain information  You can imagine that int is a class that  Only part of the information contained has member functions called in the object might be presented to the operator++, etc. user.  An object usually means an instance  Rest is concealed. of a class  After the declaration int i; we say that Engine " i is an object of type int ." Interface 5

  6. Data Hiding Data Hiding  Internal dynamics are not visible to  Allows data to be accessed by certain the user. functions class Point { // private  Data hiding is done by using the // concealed info int _x, _y; // point coordinates “private” keyword in the class public: // begin interface section definition. void setX(const int val); void setY(const int val); int getX() { return _x; } int getY() { return _y; } Engine }; Interface Point tpoint; // defines an object tpoint tpoint._x = 5; // ILLEGAL Data Abstraction Data Encapsulation  DA is a programming technique where  Combine lower level elements to form one separates the interface from the a new higher level entity. implementation  Grouping of attributes and behaviors  Class designer worries about the to form an object. interface C++ vector type is an example of both data abstraction  Programmers implement and Data encapsulation String s; s.rfind(‘ \ ’); OOP : Inheritance Inheritance  Many classes have common attributes.  Children inherit traits from their  These classes can be arranged in a parents. hierarchy.  When a class is inherited all the  Inheritance enables you to reuse code and functions and data member are add data and functionality without making inherited, although not all of them will any changes to the existing code. be accessible by the member  For example, objects can inherit functions of the derived class. characteristics from other objects. 6

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend