1.3 Introduction to C++
A Sample C++ Program
A simple C++ program begins this way #include <iostream> using namespace std; int main() { And ends this way return 0; }
C++ History
C developed by Dennis Ritchie at AT&TBell Labs in the 1970s. Used to maintain UNIX systems Many commercial applications written in c C++ developed by Bjarne Stroustrup at AT&TBell Labs in the 1980s. Overcame several shortcomings of C Incorporated object oriented programming C remains a subset of C++
C++11
C++11 (formerly known as C++0x) is the most recent version of the standard of the C++ programming language. Approved on August 12, 2011 by the International Organization for Standardization. C++11 language features are not supported by older compilers Check the documentation with your compiler to determine if special steps are needed to compile C++11 programs e.g. with g++, use extra flags of -std=c++11
Run a Program
Obtain code in Display 1.10 Compile the code Fix any errors the compiler indicates and re-compile the code Run the program Now you know how to run a program on your system
Introduction to C++
Where did C++ come from? Derived from the C language C was derived from the B language B was derived from the BCPL language Why the '++'? ++ is an operator in C++ and results in a cute pun
Program statement cout
cout << "Press return after entering a number.\n"; cout (see-out) used for output to the monitor "<<" inserts "Press...a number.\n" in the databound for the monitor Think of cout as a name for the monitor "<<" points to where the data is to end up '\n' causes a new line to be started on the monitor
Variable declaration line
int number_of_pods, peas_per_pod, total_peas; Identifies names of three variables to name numbers int means that the variables represent integers