L02_Intro to C++ - C++ Basics First example program...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C++ Basics First example program entifiers Introduction to C++ Introduction to C++ EECS 183 University of Michigan Lecture 02 Intro to C++ Mary Lou Dorf Identifiers Data types Variables and constants C++ Libraries C++ Libraries C++ provides a base set of built-in capabilities Many additional features are provided in standard libraries Example: the standard I/O library iostream defines features for input and output eeds to be specifically included to be used EECS 183 University of Michigan Lecture 02 Intro to C++ Mary Lou Dorf needs to be specifically included to be used The Start of a Program The Start of a Program int main ( void) { return 0; } EECS 183 University of Michigan Lecture 02 Intro to C++ Mary Lou Dorf Lets add Output Lets add Output #include <iostream> // name using namespace std; // where to find it int main ( void) { cout << Hello World! << endl; EECS 183 University of Michigan Lecture 02 Intro to C++ Mary Lou Dorf return 0; } Completing the Program Completing the Program //Program to output a message // Author: ML Dorf // Date: 09.14.2009 #include <iostream> using namespace std; int main ( void) EECS 183 University of Michigan Lecture 02 Intro to C++ Mary Lou Dorf { cout << Hello World! << endl; return 0; } Advice Advice Always have a program that compiles/runs (even if it doesnt do anything yet) Compile and run your program often check that it works You dont want to add a lot of lines and then discover something is wrong! (why???) EECS 183 University of Michigan Lecture 02 Intro to C++ Mary Lou Dorf Doing Calculations Doing Calculations Common operators or symbols to do calculations are: + Add 2 numbers- Subtract 2 numbers * Multiply 2 numbers ivide one number by another EECS 183 University of Michigan Lecture 02 Intro to C++ Mary Lou Dorf / Divide one number by another % Remainder with INTEGER division (MOD) Doing Calculations Doing Calculations #include <iostream> using namespace std; int main(void) EECS 183 University of Michigan Lecture 02 Intro to C++ Mary Lou Dorf { cout << Hello World! << endl; cout << 3 + 4 * 7 << endl; return 0; } Doing Calculations Doing Calculations #include <iostream> using namespace std; int main(void) { EECS 183 University of Michigan Lecture 02 Intro to C++ Mary Lou Dorf cout << Hello World! << endl; cout << 3 + 4 * 7 << endl; return 0; } Note: There are no quotes around the calculation. This will output the number 31 on the screen. OPERATOR ASSOCIATIVITY HIGH- done first...
View Full Document

This note was uploaded on 02/12/2010 for the course EECS 183 taught by Professor Dorf during the Fall '08 term at University of Michigan.

Page1 / 39

L02_Intro to C++ - C++ Basics First example program...

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

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