Hello World 2
description
Transcript of Hello World 2
![Page 1: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/1.jpg)
Hello World 2What does all that mean?
![Page 2: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/2.jpg)
The Evolution of Programming Languages
• Early computers programmed in machine language
• To calculate wages = rate * hours in machine language:
100100 010001 //Load
100110 010010 //Multiply
100010 010011 //Store
![Page 3: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/3.jpg)
The Evolution of Programming Languages (cont’d.)
• Assembly language instructions are mnemonic • Assembler: translates a program written in
assembly language into machine language
![Page 4: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/4.jpg)
The Evolution of Programming Languages (cont’d.)
• High-level languages – Express algorithms at a more abstract level:int wages = rate * hours;
– Ex: Basic, FORTRAN, COBOL, Pascal, C, C++, C#, and Java• http://oreilly.com/news/graphics/prog_lang_poster.pdf• http://www.digibarn.com/collections/posters/tongues/tongues.jpg
• Current popularitieshttp://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
![Page 5: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/5.jpg)
The Evolution of Programming Languages (cont’d.)
• Compiler: translates a program written in a high-level language into machine language
![Page 6: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/6.jpg)
Processing a C++ Program (cont’d.)
• To execute a C++ program:– Create a text source program in C++– Preprocessor directives begin with # and are
processed by the preprocessor– Compiler:• Checks that the program obeys the language rules• Translates into machine language (object program)
![Page 7: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/7.jpg)
Processing a C++ Program (cont’d.)
• To execute a C++ program (cont'd.):– Linker: • Combines object program with other programs
provided by the SDK to create executable code• Library: contains prewritten code you can use
![Page 8: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/8.jpg)
How the code works:
• # : preprocessor directive– Instructions to do before compiling– Bring the code from the library iostream into this
file
![Page 9: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/9.jpg)
How the code works:
• Use all the names that are in the "standard" grouping in my program
• Alternative:
![Page 10: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/10.jpg)
How the code works:
• ; statement terminator– Ends a "sentence of code"
![Page 11: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/11.jpg)
How the code works:
• int main()– The starting point of our program– Program instructions go inside { }
![Page 12: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/12.jpg)
How the code works:
• Comment : computer ignores– // : rest of line is comment– /* : everything is comment until */– /** : special comment – machine readable
![Page 13: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/13.jpg)
Documentation
• Every file should have comment like this at top:
![Page 14: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/14.jpg)
How the code works:
• cout : console output
![Page 15: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/15.jpg)
How the code works:
• cout : console output<< "send to output"
![Page 16: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/16.jpg)
How the code works:
• cout : console output<< "send to output""Hello" : a string – piece of text
![Page 17: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/17.jpg)
How the code works:
• cout : console output<< "send to output""Hello" : a string – piece of textendl : symbol representing "end of line"
![Page 18: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/18.jpg)
How the code works:
• return 0– Program ran successfully– Anything BUT 0 indicates error
![Page 19: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/19.jpg)
Working with numbers
• We can output numbers to console:
• Can do math using + - / *– Division may give interesting results…
![Page 20: Hello World 2](https://reader036.fdocuments.us/reader036/viewer/2022082520/5681671e550346895ddb9901/html5/thumbnails/20.jpg)
Everything Counts
• Indentation & Style matter (to humans)• Spelling & Capitalization matter (to humans &
computers)