90 likes | 229 Views
Welcome to: CSC234 C and Unix. Paul Hatalsky www.csc.calpoly.edu/~phatalsk/234/csc234.html. What You Will (hopefully) Learn About. Unix An operating system Command-line based Suite of tools Editors, compilers, Programming concepts Apply to (nearly) ALL programming languages
E N D
Welcome to:CSC234C and Unix Paul Hatalsky www.csc.calpoly.edu/~phatalsk/234/csc234.html
What You Will (hopefully) Learn About • Unix • An operating system • Command-line based • Suite of tools • Editors, compilers, • Programming concepts • Apply to (nearly) ALL programming languages • Decision statements (if statements), Functions, Loops, Arrays, Strings, Structures, design, etc. • C • Widely used, fast, umm, required for this course • Many annoying minute details • Error prone!
Operating Systems • What’s an operating system? • Interface between programs and machine hardware • What’s a command-based operating system? • The interface to the computer is through typed commands • In windows, we call it a dos window • In Unix, we call it a shell (or a terminal window)
Labs • 14-255, 14-257, 14-232, 14-301, 14-302, 14-303 • Structure: • Each of you will have your own account
What is a program? • Program = software = application = executable • Executables are in binary so that computers can understand them. • Simply a series of commands • We cannot easily understand them 10001110011101010 10101001000001111 … … 00111000101010001
What is a program? (continued) • A program is an ordered list of instructions to the computer, written in a certain programming language. • Just like making mac and cheese: • Boil water • Add pasta • Cook for 8 minutes • Drain water • Add cheese powder, milk, butter • Stir ingredients • EAT!
Program Example – Burrito making Robot • Set of commands it understands • LT() – Lay down tortilla • FT() – Fold tortilla • AI(ingredient) – Add ingredient to the burrito • Set of possible values for ingredient • Beans • Cheese • Chicken • Rice • Salsa • Beef • Sour Cream
What is code? • Also known as “source code” or “source” • Code is written in text so that we can understand it. Well…sort of… • #include <stdio.h> • #define CALORIES_PER_BEAN 4.0 • #define CALORIES_PER_HOUR 750.0 • #define MIN_PER_HOUR 60 • int main(void) • { • int beansEaten, calConsumed; • double minCycling; • /* User input */ • printf("How many jelly beans did you eat?\n"); • scanf("%d", &beansEaten); • /* Calculations */ • calConsumed = beansEaten * CALORIES_PER_BEAN; • minCycling = calConsumed/CALORIES_PER_HOUR*MIN_PER_HOUR; • /* Output */ • printf("You ate %08d beans, consumed %d calories\n", beansEaten, calConsumed); • printf("You and should cycle for %f minutes\n", minCycling); • return 0; • }
How do we make our code execute (run)? • Code must first be compiled, then it can be run. int main (void) { c = a+b; return c; } Compiler 10001110011101010 10101001000001111 … … 00111000101010001