C++ - Programming in C+ Logistics Introductions Go over...

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

View Full Document Right Arrow Icon
Programming in C++
Background image of page 1

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

View Full DocumentRight Arrow Icon
Logistics Introductions Go over syllabus About programming and languages A little history About C++ as a language How to write and compile a simple program How to write programs in general
Background image of page 2
What is Programming? Computers are dumb - making them do useful things involves telling them exactly what to do, step by step. Programming is the process of taking a program and breaking it down into a sequence of steps the computer can handle (CPU instructions). CPU instructions are very simple: e.g. add two numbers, fetch a number from memory, see if a number is equal to zero, etc.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Low Level Language Usually this refers to assembly code Each code instruction becomes a single CPU instruction Hard to write, hard to read, hard to maintain Not portable between different CPU families ... but great for control freaks, and can result in very efficient code
Background image of page 4
High Level Languages Most programming languages are high-level (C++, C, Perl, PHP, Java, Pascal, Python. ..) Easy to write, easy to read (easi er , anyway) Not (usually) machine specific Must be translated into assembly language ... meaning it often loses something in 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
A Bit ‘o History Before C++ came C, in the early 1970s C was originally invented (no kidding) to play Space Travel, a video game Developed along with UNIX C was designed to be minimalist: Easy to compile into fast machine code Nothing “behind the scenes” Low level access to memory
Background image of page 6
...and then came C++ C++ is an extension to C, from the early 1980s C++ is “C with classes”, and a few extra language features ... but still with most of the low-level-ness of C (no hand-holding) Fast, powerful, standardized, and very popular ... but error prone if you are not careful!
Background image of page 7

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

View Full DocumentRight Arrow Icon
C++ is: Compiled (translated into machine code in advance, before run-time) Strongly typed , meaning that each variable has a type associated with it (float, int, whatever) High level ... but still pretty low Portable - the same code can often be compiled on many different kinds of computers with little or no modification
Background image of page 8
Writing a C++ program Programs can be written in any text editor On the lab machines try gedit, nedit, emacs, KDevelop, etc. Via SSH (linux.cs.uiowa.edu) try pico Use whatever text editor or platform or compiler you are most comfortable with, but your program must compile on Linux using g++!
Background image of page 9

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

View Full DocumentRight Arrow Icon
// a sample program, by Greg #include <iostream> using namespace std; int main() { int baz = 2; int foo = 21; int result; // multiply some stuff result = foo * baz; // output the result cout << “Hello world: ” << result << endl; return 0; }
Background image of page 10
Compiling/Running it 1. Compile with g++ 2. If it works, run the resulting executable 3. Like this: [gbnichol@serv16 ~/cpp]$ ls main.cpp [gbnichol@serv16 ~/cpp]$ g++ -o program main.cpp [gbnichol@serv16 ~/cpp]$ ls main.cpp program [gbnichol@serv16 ~/cpp]$ ./program Hello world: 42 [gbnichol@serv16 ~/cpp]
Background image of page 11

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

View Full DocumentRight Arrow Icon
Errors are problems with your program
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.

Page1 / 49

C++ - Programming in C+ Logistics Introductions Go over...

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