<<

CIT 166 Programming Using An Introduction to Computers What are the main components of a computer

 Processor (microprocessor, CPU –Central Processing Unit)  Memory (RAM –Random Access Memory)  Hard Disk Drive (HDD)  Several device cards: graphics card, sound card, network card, modem  Input/Output (I/O) Devices: keyboard, mouse; monitor, printer

Hardware, Software and Servers Hardware  Refers to physical components of the computer  Includes all components (even I/O)

Software  All the programs written for a particular computer or for any computers

Servers vs. Personal computer  Term “Personal computer” indicates that the machine is operated by one person at a time  Term “Server” indicates that the computer provides resources to other computers Make a computer understand To create software for a computer, you will need to use a Computer language  Lowest level: Machine Language (coded in binary) (110100100)  : symbolic representation of Machine Code. You need to learn the symbols in order to write the code.  High-level (Human –readable)Language: Visual Basic, , ++ It consists of instructions to which people can relate (Click, if, do, etc…)

Communication protocol Human-Readable to Machine-Readable Computer Programs  A computer is a machine that does ONLY what it is instructed to do. The code must be broken down into a sequence of instructions . This sequence is called a program

What is a program? Collection of instructions that:  Accepts input  Process Data  Outputs results

What is a Programming Language?  At the lowest level we have Machine Language. o Machine Language is a system of instructions and data executed directly by a computer's central processing unit.  What we will be using is a Higher-Level Language o Higher-Level Languages consists of instruction that people can understand. o Examples of Higher-Level Languages:  C  C++  Java  Python  Visual Basic

Why Visual Basic? Allows you to make programs easily • Lets you focus on problem at hand • Creates GUI’s () not ugly command line • Interactive with user as an -Driven programming language

Higher Level Languages Use IDE’s Integrated Development Environment (IDE) is a software application that provides drag and drop capabilities with some prewritten programming code that makes programming a lot easier.

So how do we get from VB to a Running Program? 1) First, write program, which is a collection of instructions for the computer to follow. 2) Then we must have the program translated into machine language by using one of two ways. • A compiler that translates high-level language such as VB in Machine Language all at one time before executing(running) the program. o NOTE: The compiler also detects certain types of errors during the translation process and will sometimes keep the program from running until the errors are fixed. o A compiler creates a machine language version of your program (usually and .exe file) that permits you to rerun the program without recompiling. • An interpreter, which translates and executes the program one line at a time. o Languages that use an interpreter must reinterpret the program ever time you want to run the program 3) Finally, we can run the program, which means to execute the instructions given in the program.

Program Development Cycle When Developing a program in both the real world AND in this class, there are 6 steps • Analyze the problem • Plan a solution • Design an interface • Write the code • Test and debug • Document the program • (Not done in this class) Maintain the program

To be successful in this class, you must perform each of these steps.

Analyze the Problem Understand what the problem is and what the solution should be. Keep in mind what the End User should be able to see and do. • User – Anyone who uses the program. • End User – The person you designed the program for

Aways keep in mind what the CORRECT solution to the problem is. • This needs to be done before ANY of the following steps can take place. • People have this job in real life: http://en.wikipedia.org/wiki/Software_analyst

Plan a Solution Once you understand the problem, you can develop an algorithm. • An Algorithm is the precise steps for the entire flow of the program written in steps or in flowchart form (to be discussed later). Usually in the form of: a. Get Input b. Validate Input c. Process Input d. Output Solution • Every detail should be covered in the algorithm. • Consider what is logical and illogical for the . • Think about what situations can happen in the problem. • In real-world software projects, this is often done by committee

Design the Interface • An interface is how two components interact with each other. • User Interface – How the user interact with your program. a. Think about how you allow the end user to interact with your program. b. Consider how the user inputs data and views results. c. Think about what makes sense to the end user. *For this course, this includes windows, buttons, text boxes, etc. • Again, this is a job in real life: http://en.wikipedia.org/wiki/User_interface_design

Write the Code Coding: translating the algorithm you developed into a programming language (or Code). This is where knowledge of a programming language (VB in our case) is used. • Again, this is a real-world job: http://en.wikipedia.org/wiki/Software_developer http://en.wikipedia.org/wiki/Software_engineer

.

Testing and Debugging Even experienced software engineers make mistakes, so it is important to test your program for errors (known as bugs). A Bug – is an error, flaw, mistake, failure, or fault in a computer program Two Kinds (of many) of Errors: a. Syntax Error – Error in typing the program. b. Logical Error – Inconsistency between what you want the program to do and what it actually does. *It’s important to consider all normal and abnormal inputs for the program. Actual Job: http://en.wikipedia.org/wiki/Software_tester

Complete the Documentation Documentation – Organizing all the material that describes the program. Documentation includes: • Comments inside of the code document that describes to whoever reads it what specific sections do. • Comments inside of the code that describe the who the author is, when it was written, and any other relevant information • In commercial settings (industry) this includes user manuals that describe how to use the program. This may seem annoying, but it is a very important requirement for this course.

You may find it easier to document code WHILE writing it, instead of completing it once you finished writing your code.

Developing an Algorithm Consider the problem of finding out how many stamps you need to put on an envelope to mail it. The rule here is that you need 1 stamp for every 5 sheets of paper in the envelope. So the algorithm looks something like this: • Get the number of sheets from the user. (Input) • Divide the number of sheets by 5 (Process) • Round the result from step 2 the highest whole number (Process) • Output the number of stamps (Output)

Testing an Algorithm (Example) (Stamp Counting Take 1) Testing your algorithm with some real numbers. • The user inputs 16 sheets of paper • Dividing 16 by 5 results in 3.2 • Rounding 3.2 up results in 4 • Output 4 stamps • Simple enough, right? What could go wrong? • What if the user inputs “Banana” sheets of paper?

Revising an Algorithm (Stamp Counting Take 2) • Get the number of sheets from the user. (Input) • Check to see if the input is a positive number. (Validate) • Divide the number of sheets by 5 (Process) • Round the result from step 2 the highest whole number (Process) • Output the number of stamps (Output)

Modeling Tools To help understand the steps of an algorithm, use a variety of tools • Three that will help us in this class are: a. Flowcharts – Graphically depict the logical steps to carry out a task and show how the steps relate to each other b. Pseudocode – English-like phrases with some Visual Basic terms to outline the task c. Hierarchy Charts – Show how the different parts of a program relate to each other. Now that our algorithm is set, lets see how the modeling tools work.

Hierarchy Charts • Good for showing the structure of the algorithm • Good at breaking down the algorithm into components • Not too great at showing the order of events • Flow Charts are better at showing the order in which the components execute.

Pseudocode • This will become more clear when you understand VB terms better. • Pseudocode is good for listing the steps of an algorithm in a form that is easier to translate into VB. • Important: There is NO SPECIFIC FORM to pseudocode, it can look as much like VB or English as you want. The more VB you learn, the more VB-like pseudocode you can write.

Pseudocode (Sample) Program: Determine the proper number of steps for a letter

Read sheets if sheets is a positive integer Stamps = Sheets/5 Whole Stamps = Stamps rounded to next whole number Output Whole Stamps else Display Error