{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Week 1 - Week 1 1 Chapter 0 Introduction Outline History of...

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

View Full Document Right Arrow Icon
1 Week 1
Image of page 1

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

View Full Document Right Arrow Icon
Chapter 0: Introduction Outline: History of C++ High level differences Reasons to use C++ 2
Image of page 2
3 History In 1972 Dennis Ritchie designed and implemented C to write unix. In 1979 Bjarne Stroustrup started work on C++ to have “C with classes” Around 1994 James Gosling developed Java
Image of page 3

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

View Full Document Right Arrow Icon
4 Big Differences C++ programs are turned into Completely compiled binary code run on a real machine , but Java programs are turned into partially compiled bytecode interpreted by a virtual machine . Java is more for safety but C++ is more for efficiency . Java supports native multithreading but C++ does not . Java provides comprehensive application support with packages but C++ gives container support with the standard template library ( STL ).
Image of page 4
5 Why C++ C++ programming is a skill in high demand. C++ provides templates for generic programming . C++ supports operator overloading to operate on objects. C++ allows conditional compilation. C++ distinguishes between accessors and mutators. C++ aims for time and space efficiency.
Image of page 5

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

View Full Document Right Arrow Icon
Chapter 1: Basic types Outline: First program Primitive Types Minor Syntactic Differences 6
Image of page 6
7 First Program #include <iostream> using namespace std; int main() { cout << "Hello world" << endl; return 0; }
Image of page 7

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

View Full Document Right Arrow Icon
8 Compile and Execute $cd $mkdir cs1280 $cd cs1280 $mkdir lect $cd lect $mkdir 1 $cd 1 $ vi 1 .cpp $ ls 1.cpp $ g++ 1.cpp $ ls 1.cpp a.out $ a.out Hello world $ echo $? # check return value of main() 0 $ rm a.out rm: remove a.out (yes/no)? y $ ls 1.cpp
Image of page 8
9 #include <iostream> The system header file iostream ( < iostream > ) is inserted into the source as directed by the preprocessing directive ( #include ). iostream contains declarations and definitions for the standard I/O classes and objects. Explore : To see these declarations and definitions, enter g++ -E 1.cpp
Image of page 9

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

View Full Document Right Arrow Icon
10 using namespace std The using namespace directive is like a Java import statement std is the name of a namespace using namespace std; allows the abbreviation of std:: cout as cout and std:: endl as endl
Image of page 10
11 int main() A C++ program starts execution at the main() function The main() function should return an int value The return value of main() is stored in the shell variable $? main() may have up to three parameters A java executable starts execution at the static void main() method that returns nothing. To return a value to the system a java executable calls System.exit().
Image of page 11

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

View Full Document Right Arrow Icon
12 cout, endl The object cout is of class ostream that represents the standard output stream, one of the three standard I/O streams of unix. The insertion operator << inserts its right operand to its left operand. The manipulator endl inserts a newline character and flushes the buffer. 1. The expression cout << operand evaluates to cout and the operator << is left-associative.
Image of page 12
Image of page 13
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