Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1 Welcome everyone to Visual Logic. We will use this book and the next couple of weeks to learn to solve problems, develop a visual representation.

Similar presentations


Presentation on theme: "Chapter 1 Welcome everyone to Visual Logic. We will use this book and the next couple of weeks to learn to solve problems, develop a visual representation."— Presentation transcript:

1 Chapter 1 Welcome everyone to Visual Logic. We will use this book and the next couple of weeks to learn to solve problems, develop a visual representation of those solutions to create a kind of computer program and run the program to see if our logic was correct. We are using Visual Logic as a way to concentrate on solving problems with our computer without being concerned with the language and its requirements. I want to tell you that you are learning to speak another language, the language of computers. Just like learning to speak Spanish, French, Chinese, or any other language, it take time and lot of effort. There are many companies that sell you software that allows you to learn to speak a language, in our case Java, without learning to read or write the language. That is what we are doing. We are learning to speak computer language and will then learn the syntax, grammar rules, of Java. For the next couple of weeks we will be using Visual Logic. We will revisit it at the very end of the courses. I am so sorry my Mac Users but this software only works on a PC. You will either need to run parallels or borrow a computer for a couple of weeks. I began using Visual Logic as a way of increasing our retention and it worked. Students do much better in the Java portion of the class once they have completed this brief introduction. If you purchased your text with a pin code, you will be able to save your work and submit the files that you created to me. If you only purchased the book, you will be able to create the program, run the program but not save it. My solution to this problem, is that you can take a screen shot of the work, past it into a word processing document and then submit. If you go this route, you really need to take care to save your work for future reference. You should be sure that your load Visual Logic on you machine. If you go under the tab Resources and Links, you will find directions for installing Visual Logic. They are also included with your pin code that your purchased with the book. Please note: if you purchased a used pin code, it will not work. OK, lets get started. Visual Logic

2 Computer Program Solution to a problem. Most do 3 things
How can my customer purchase products from the Internet? Most do 3 things Input data Process data Output data So exactly what is a computer program.? The simple answer is that it is a solution to a problem. Like in the example on this slide – How can my customer purchase products from the Internet.? The question is the problem and we as programmers must find a way to solve the problem. What do we need to do in order to be able to see customers product from the internet. In order to solve this problem, there is some information that we will need, we will need to do something to that data, and we will need to output the data. A slightly more complicated answer to the question “What is a computer program?” is a solution to a problem, that allows the user to input data, process data, and output data. I would ask at this point, well if it doesn’t do one of these things is it still a computer program. The answer is yes, but generally speaking you will need to perform these 3 functions in some way. Y A computer program is a solution to a problem that allows for data input and data output and processes the data in some fashion. Input Process Output

3 Writing a Computer Program
Determining what the problem is Creating a logical solution to solve a problem Implementing that solution Verify the solution is correct Everyday examples of algorithms Directions to bake a cake Direction for game So when we begin to write a computer program, we first determine what the problem is. I can’t emphasize enough how important this step is. You must understand the problem to know if you are correctly solving the problem. We will be working in this course with smaller problems but you still should take the time to make sure you understand all the issues of that problem. What do I need my computer to do, where will my input come from, what will my output look like. These are all questions for which you should know the answers before you being. After you have determined what the problem is you should create a logical solution to solve the problem. What do I need as input to my program and where will it come from? What is the solution for my program? You might find that you have more than one but one may run faster than the others. Next you want to implement that solution. In the case of Visual Logic, choose the correct flowcharting symbols to accomplish your task. Lastly you must verify that your solution is correct. Sorry guys but there is only one way to do that. Work the solution out by hand first and then compare the results. Let’s go back a moment and look at algorithms again. What are some common algorithms. How about baking a cake. We have a receipt we follow – a set of directions – an algorithms. If we follow those directions, we should come out with a good cake. But its it? Did I leave something out? How do I know, I taste the cake or verify the solution and make sure my cake is what I expected it to be.

4 Difference Between Data and Information
500 Data is numbers, character, and/or images without context Order 500 t-shirts Information is data that has been processed We use the terms data and information interchangeably. Are they the same? The answer is no. Data is numbers, characters or images without context. If I say 500 does it convey any meaning to you. Probably not and if it does, the meaning to you and to me might be very different. The number 500 could represent t-shirts or dollars or flowers. Without the context any meaning is uncertain. Why do I bring that up in this discussion. Simple, we need to be sure an note our output so that it provides context. If your answer is 500, 500 what. Give your output context so the meaning is not lost.

5 Logic and Syntax Compare building software application to a house.
What are the requirements Design Construct Check Algorithm – logical blueprint for software Visual Logic Graphics of flowcharts (graphical representation of algorithm Utility of pseudo code ( min. syntax description of algorithm) When we think of writing a computer program, there are really two things we think about, logic and syntax. Logic is the how to we solve the problem. It is the well thought out rational behind the decisions made. Syntax on the other hand can be compared to the grammar of a language – where to put the commas, semicolons, etc. Each language has its own set of syntax. I like to building a computer program to building a house. In the words of Mary Poppins. “You start at the very beginning. It’s a vey god place to start.” As beginning programmers, we want to skip the first step and jump into the middle. We don’t want to plan and take the time required to develop a logical blueprint for the software or the algorithm. Can you image building a house by simply picking up lumber and beginning to hammer nails and building without a blueprint. My Uncle was a carpenter and I often watched him build. It always amazed how he could turn a stack of lumber into a house. BUT he didn’t do that without a blueprint, a design of what the house would look, what was required after it was built. I am equally amazed at the number of students who sit at a computer and try to build a computer program without that algorithm. Often you will attempt to build a solution without fully understanding the problem. Don’t do that. Create your blueprint, or in computer language, your algorithm. Visual Logic is a software package that allows you to design our algorithm and produce a graphical representation of that algorithm using flow charts symbols. This tool can be used effectively after you are no longer using it. Another way of creating your algorithm is to use pseudo code which is English words that says what you want to do.

6 Errors Two Kinds Syntax Logic Violate the rules of the language
More difficult to do with Visual Logic than Java Begin with the easy more to more difficult Logic Violate the rules of the problem Your thinking is off You can do this anytime When we are programming there are two types of errors that you will encounter. Notice that I said you will not that you might. When programming we all make errors. It is just a given. Errors fall into two categories, syntax and logic. Syntax errors violate the rules of the language. Think about them as a violation of the grammar of English. In writing a sentence, you say I am at the end of the sentence by putting a period. That is a rule of the language or a syntax. This is not a big issue in Visual Logic because we will be using flowchart symbols and they help with this. There are places where it is an issue. For example if you are entering text, you must put it in “ “. I forget this all the time. The program will catch this mistake and tell you the error has occurred. Syntax becomes a bigger issue with Java and that is one of the reasons we being with Visual Logic. We don’t have to worry about it. Logic errors on the other hand are violations of the rules of the problem. You basically are thinking about the solution in a wrong way. Let’s go back to the comparison to English. There is a difference in leaving off a period at the end of the sentence and talking about the wrong thing. What if I suddenly discussing an ethical theory in an attempt to teach you to program. My logic would be off. Better still what if I were teaching you to program and began to teach you to ride a bike. Somewhere I solved the problem, how to teach computer science, incorrectly. This is a logic error. You can and will do this all the time. Sometimes, these logic errors can be very difficult to find because they made sense the first time and we have to look at the problem differently.

7 Hello World First Program
OK – it is time for us to begin to program our first program. We will do Hello World. Why that you might ask. Well it is simple. We should begin with simple. Secondly, it is almost a have to experience for programmers. We all began with a Hello World program. I am going to walk you through this step by step. This is where it might be good to print off your notes, have two windows open, or even have two devices. Let’s get started. You will need to open your visual logic program. There are some instruction on doing that under the Resources and Links tab.

8 Flowchart Symbols If you have Visual Logic open you should see a slide with two boxes. One that says being and one that says end. They are connected by a red arrow. The begin box signals that we are going to begin and program and the end box says we are going to end the program. All of our program will go between these two boxes. What you see on this page is a listing of the various flowchart symbols we will use through out the next couple of weeks. Take a couple of minutes to look at them and familiarize yourself with these symbols. The titles pretty much identify what each are and we will talk about what they do in the coming sessions. We are going to begin with the output symbol. We need to output some data to print the words “Hello World”. Lets move to the next slide to see how to pull up that box and use the Output symbol.

9 Creating Hello World You need to open your Visual Logic page and click on the red arrow between the Begin and End box. You should have seen a list of flowchart symbols appear that looked like those on the previous slide. You not will select the box entitled Output and you should see something similar to what is on this screen. Now I want you to double click on the box that says Output.

10 Next Step Type “Hello World” When finished hit OK
Your screen should look like this. In the white area in the box in the middle of the page, type “Hello World” and hit OK. When finished hit OK

11 Almost There You should have a picture such as this. We are now ready to run the program. Do you see a set of buttons at the top of the page that remind you of VCR controls. Well I want you to hit the rightward pointing arrow.

12 You Did It Way to go. You have just created and run your first computer program.

13 Input Input Statement Variable Accepts data and stores into a variable
Storage location Can be accessed and changed by developer code Has a name and a value

14 Second Program Hello Name

15

16 Program Formats Value Written Format Programming Format Comment String
Hello World “Hello World” Use quotes to delimit strings Percent 15% 0.15 Use decimal format Dollars $300 300 Dollar signs not allowed Large numbers 12,345,678 Commas not allowed

17 Weekly Paycheck Program

18 Weekly Paycheck Program Specifics
Accepts the hours worked Accepts the hourly rate for an employee Will calculate and display the appropriate pay amount due Step 1: Input What is the input needed Hours and Rate Step 2: Processing What calculation must be performed Hours * Rate Step 3: Output

19 Expressions A value-returning code element X = A + B
Assignment statements are use to perform calculations and store the results Expression is evaluated and stored in a variable

20 Operator Precedence Operation Operator Expression 1 Result 1 Expression 2 Result 2 Exponentiation ^ 5 ^ 2 + 1 26 5 ^ (2 + 1) 125 Multiplication * 1 + 3 * 7 22 (1 + 3) * 7 28 Division / / 2 10 (8 + 4) / 2 6 Integer division \ 12 \ 4 3 17 \ 3 5 Integer remainder Mod 12 Mod 4 17 Mod 3 2 Addition and subtraction + - 4 – 5 + 2 1 4 – (5 + 2) -3 Java will handle exponentiation and division differently

21 Weekly Paycheck Program

22 Intrinsic Functions Predefined commands that provide developers with common, helpful functionality

23 Function for Visual Logic
Example Result FormatCurrency(12345) $12,345.00 FormatCurrency(.02) $0.02 FormatPercent(0.0625) 6.25% FormatPercent(0.75) 75.00% Abs(-3.3) 3.3 Abs(5.67) 5.67 Int(3.8) 3 Round(3.8) 4 Random(5) A random integer between 0 and 4 Random(100) + 1 A random integer between 1 and 100 Java handles these differently

24 Rose by Any Other Name Paulette has just planted a large rose garden that she wants to fertilize. She knows the area of her rose garden in square feet, but the fertilizer is measured by the square yard. Write a program that converts square feet to square yards.


Download ppt "Chapter 1 Welcome everyone to Visual Logic. We will use this book and the next couple of weeks to learn to solve problems, develop a visual representation."

Similar presentations


Ads by Google