220 likes | 294 Views
Today’s Class. Introductions About the Course Fundamentals Computer Program - Sequence Parts of a computer Parts of a CPU Writing a really short program Homework. I love programming. 20 year career, then went into something else My dad HATED programming
E N D
Today’s Class • Introductions • About the Course • Fundamentals • Computer • Program - Sequence • Parts of a computer • Parts of a CPU • Writing a really short program • Homework R. Smith - University of St Thomas - Minnesota
I love programming • 20 year career, then went into something else • My dad HATED programming • My own kids never really tried it • Some people will find they love it • Some will hate it, and some are in the middle • The GOAL: to be capableat programming R. Smith - University of St Thomas - Minnesota
Class Survey • Who is sitting next to you? • Their name? Major? • Why are they taking the course? • What computer skills do they bring to this class? R. Smith - University of St Thomas - Minnesota
Class Schedule • I’ll arrive about 5 minutes early or so every day • “Lectures” start at 9:55 AM, Tue/Thu • Ends at 11:35 • “Lab” starts at 10:55 AM M-W-F • Ends at Noon • Both Lecture and Lab will usually start with a new technique R. Smith - University of St Thomas - Minnesota
Syllabus • “Real” syllabus tomorrow • Learning C programming • The basic mechanics • Assignments and variables • Conditionals • Loops • Input/Output • Structure with multiple procedures • Arrays • Learning Matlab • Many of the same concepts • Built in features for mathematical problem solving • Lots and lots of programming R. Smith - University of St Thomas - Minnesota
Grading • I do it “by the numbers” • It’s easy to earn an A-like grade: do the work • It’s easy to flunk: don’t do the work • In between grades: if you skip homework or mess up on exams • General outline of the grade • Part goes to homework • Part goes to exam (a similar weight) • Part goes to final project • I’ll hand out grade sheets with your grade • NO LATE WORK as a rule • Need bona fide reason for late work R. Smith - University of St Thomas - Minnesota
How the class works • Memorization and programming • This is lots and lots of detail work • You work fast if you work from memory • Practice and remember “patterns” that work • Do the Reading! • It gives you another source for programming details • A different way of describing the same stuff • A place to go to answer questions • “Some” problem sets based on the reading • Labs = programming tasks to do • Try to finish DURING lab • If you don’t, then you have extra homework R. Smith - University of St Thomas - Minnesota
Fundamentals • Computer • Program - Sequence • Parts of a computer • Note they are built hierarchically • Parts of a CPU R. Smith - University of St Thomas - Minnesota
C Program • Always in a file • Always defines a ‘function’ to perform • Usually the function is named ‘main’ • We “compile” it to make it work R. Smith - University of St Thomas - Minnesota
Sample C Program #include <stdio.h> int main (void) { printf("Hello, world\n"); return 0; } R. Smith - University of St Thomas - Minnesota
Observations • Case sensitive: match cases “exactly” • Program is worked “in order” from start to end • “Sequences” are fundamental to computing • Curly braces mark “nested” components • “Hierarchies” are fundamental to computing • Learn the “patterns” of typical programming tasks • Setting up the program • Doing output R. Smith - University of St Thomas - Minnesota
“Compiling” - the mechanics • “Command Line” compiling • Should work the same on PCs and Macs • You have to “compile” programs to run them $ gcc hello.c $ • You simply command the computer to run the program $ hello Hello, world! $ R. Smith - University of St Thomas - Minnesota
Homework • Read Chapters 1 through 3 • Find a “C compiler” on a computer you can use • Already installed on 4th floor OSS • May be installed on other campus computers • You can download it and install it at home • For PC: use MinGW, that’s what’s installed here • Write a program that prints your name • Ideally, use your U: drive or a USB drive • Run it and see the result • Print the “C” file. Include an explanation of where you compiled and ran it, and note any problems you had. R. Smith - University of St Thomas - Minnesota
What’s happening next? • A “history” of C • Overview of Statements and Variables • Simple types • Printing out text • The nuts and bolts of compiling programs R. Smith - University of St Thomas - Minnesota
History of C • Interpreting expressions (1940s) • Sort/Merge Generator • A2 Compiler • Fortran • Algol • C R. Smith - University of St Thomas - Minnesota
Statements and Variables • Statements we’ll use • “Function declarations” like main • Always followed by a pair of parentheses, • and then curly braces • Other statements are followed by a “;” • Variable declarations • Assignment statements • Variables • Storage cells in your program • Each one is like a spreadsheet cell, only dumber R. Smith - University of St Thomas - Minnesota
Variable Naming • Naming Structure • First character: A-Z, a-z, _ or $ • Remaining: same plus digits • Style rules • Descriptive names • Usually start with lowercase letter • Camelback: use capitals to mark words • itemsOrdered, totalPayment • DO NOT USE $ to start a name R. Smith - University of St Thomas - Minnesota
“Types” of variables • First use: you say the type • int = “integer” • signed, no decimal part, less than 2G • Examples int sampleInt = 12; sampleInt = 25; R. Smith - University of St Thomas - Minnesota
Printing • The ‘printf()’ function • Syntax of ‘functions’ • Takes 1 or more ‘arguments’ or ‘parameters’ • First argument: “format string” • A string of characters to print • Embedded ‘signals’ to say what else to print (“%” character) • Each ‘signal’ corresponds to a subsequent parameter • Extra parameters • One per format signal R. Smith - University of St Thomas - Minnesota
Blanks, newlines, tabs • “ “ • “Hello” “There” • “Hello There” • \n, \t R. Smith - University of St Thomas - Minnesota
Compiling and Running • What is really happening? • How a program executes • Computer ‘Languages’ • Interpeting • Compiling • Running “real” instructions • What it looks like in RAM R. Smith - University of St Thomas - Minnesota
Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. R. Smith - University of St Thomas - Minnesota