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

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

View Full Document Right Arrow Icon
1 Week 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Chapter 0: Introduction Outline: History of C++ High level differences Reasons to use C++ 2
Background 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
Background image of page 3

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

View Full DocumentRight 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 ).
Background 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.
Background image of page 5

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

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

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

View Full DocumentRight 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
Background 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
Background image of page 9

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

View Full DocumentRight 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
Background 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().
Background image of page 11

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

View Full DocumentRight 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
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/02/2011 for the course CS 1280 taught by Professor Forgotten during the Spring '09 term at National University of Singapore.

Page1 / 62

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

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online