310 likes | 454 Views
Intro to Art of Programming. Math 130 Lecture # 01 01/24/05. B Smith: Reconsider these topics upon completion of lecture. Overview. Programming Style. Brace placement White space Indentation Comments. Interesting style. What does it do?. Obfuscated code output. Obfuscated code.
E N D
Intro to Art of Programming Math 130Lecture # 0101/24/05
B Smith: Reconsider these topics upon completion of lecture Overview
Programming Style • Brace placement • White space • Indentation • Comments
Obfuscated code • That was an extreme example of bad style • The code works beautifully, but I feel sorry the person who inherits Ed's code after he moves on • White space is important
White space • Program structure should make sense without having to study each line of code for 2 hours • Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate. Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate. Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for co mprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate.Whitespace is important for comprehending most any information that one wishes to communicate.
Comments • Explanatory remarks within a program • Used to clarify intention of program • /* and */ can be placed anywhere within a program • On your own, try placing a comment in the middle of your “hello there world” output line. • Comments can not be nested! • /* starts out ok /* goes wrong */ here . Kaboom */
Top Down Program development • Start w/ the end; detemine the desired output • Determine inputs • Select an algorithm and verify the logic • Write the program • Test program with data
_ Basic data types in C • Integer • Floating point • Double precision • Character
Storage requirements • 1 byte = +/- 127 • 2 bytes = +/- 32k • 4 bytes = +/- 2 Gigabytes
Other data types • The beauty of C • Abstraction
The sizeof() function • Mac vs PC
Lab 02 – Overview • The Integrated Development Environment (IDE) • MS Visual Studio • Blackboard • overall layout • Submitting assignments • Checking your grades • Communication and feedback
An example • The canonical “hello world”: #include <stdio.h> int main() { printf("Hello there world!"); return 0; }
Entering a program • Edit the program • Save with appropriate filename • *.c, *.cc, *.C, *.cppetc. • Compile • Link (sometimes done automatically) • Run the program