lecture04 - Object Orientation We dont think about it like...

Info icon This preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Object Orientation We don’t think about it like this, but such functions already exist for our basic data types… 1 + 1 3.14159 * 2.71828 From Java: “Hello ” + “World” System. out .println( “The answer is ” + 42); As written, these do not translate directly into C++. In C++, cout << “The answer is ” << 42 << endl;
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Object Orientation Programming then becomes about recognizing the distinct “objects” that need to exist within the system and coding them appropriately. This includes needed interactions among objects.
Image of page 2
C / C++ Compilation In Java (and many other modern languages), the compiler is designed to make multiple passes over code files during compilation. In doing this, the compiler first finds all objects, variables, and functions of interest that are available before beginning the actual computation.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C / C++ Compilation In C++, you are required to manually “declare” any object, variable, or function within a code file before using it. Note: “declaring” vs “defining.” “declare” – “function X exists.” “define” – “this is what function X does.” If you try to use something before it’s declared, a compiler error will result.
Image of page 4
C / C++ Compilation To simplify the process of declaring relevant code objects, C++ has two core file types. Header files: “*.h” Contains relevant declarations Source files: “*.cpp” (“*.c” in C.) Contains code definitions Source and header files then #include other header files with needed definitions.
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C++ Resources Like Java, C++ has a substantial amount of pre-coded resources for use in programs. This being said, Java’s built-in collection is far more extensive than C++’s. These are also utilized by use of #include , as opposed to Java’s import . However, built-in resources are included through <angle brackets> rather than “quotes.”
Image of page 6
C++ Resources Very common imports: <string> Includes the std::string class, a C++ counterpart to Java’s string.
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern