170 likes | 187 Views
CS 102. Programs/Algorithms. Overview. Computer Architecture What is a computer program? Flow chart Data states Data Variables History – Why VB? Procedural programming Object oriented programming Visual programming Example: Hello world. Computer Architecture. Drawn in figure 1-1
E N D
CS 102 Programs/Algorithms
Overview • Computer Architecture • What is a computer program? • Flow chart • Data states • Data • Variables • History – Why VB? • Procedural programming • Object oriented programming • Visual programming • Example: Hello world
Computer Architecture • Drawn in figure 1-1 • Main components: • CPU • Main memory • Secondary storage • Input devices • Keyboard • Mouse • Scanner • Camera (still/video/webcam)
Computer Architecture • Main components (contd): • Output devices • Monitor • Printer • Software • Operating System • Application Programs
What Is A Computer Program? • Set of tasks/instructions • Related? • How? • Set of data (states) • Can be in main memory (temporary) • Can be persistent • Long-term • Often stored in a database or data file
Flow Charts • Help visualize the flow of the program. Shows mainly the instructions and decisions • Is a blueprint for the logic in how to write the program • Historically, different symbols used for different types of logic • Variable assignment • Decisions
Flow Charts • Symbols: • Start/End of program: Ovals • Flow of control: Arrows • Actions: Rectangle • Input/Output: Parallelogram • Conditional: Diamond
State of Data: Variable • Variables are ESSENTIAL in programming • Variables hold things • Data • State • Variables typically have names that are meaningful • Descriptive is better • Older languages only allowed one letter • i, j, etc… • Now they can be as long as needed
Variable Names • Sometimes use underscore (_) • sum_total • number_of_tries • “CamelCasing” • Start each word with a capital letter • No underscores • Ex: • SumTotal • NumberOfTries
Examples • Hello World • No data • No states • Just a control flow • Gross pay calculator • Data: Hours worked, hourly pay rate • Ask them to exit • Or exit button (control)
Examples • Create flowchart on board • Demo of example programs
Programming Methods • Procedural programming • Original style • Set of steps (including Input/Output) • Goes from “Start” to “End” • Can be shown in a flow chart easily • More difficult to reuse code
Programming Methods • Object-Oriented programming • Current style • Create “objects” that mimic real-world things • Ex: Automobile • Objects have properties (data) • Objects have methods (actions) • Car example. What are properties, methods • Properties: Color, Location, Speed, Direction • Actions: Honk horn, Speed up, slow down, turn to right
Visual Programming • Graphical User Interface (GUI) • Many, many objects have been created for visual objects • Makes it easier to program • Looks great • Don’t have to “reinvent the wheel” • Graphical environment to write programs • Graphical environment to debug programs
Event-Driven Programming • GUI programming is event-driven • Screen “sits there” in a loop, waiting for user action • You write “event handlers” that handle each action that might be taken • Button clicks • Typing text • Check a checkbox • Only have to write a little bit of code at a time • Much, much easier to debug!
Demo • Demonstrate graphical version of the two example programs