Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Programming Mr. José A. Ortiz Morris. Computer Language  Languages that the computer understands.  They are low level languages. (BINARY 1.

Similar presentations


Presentation on theme: "Computer Programming Mr. José A. Ortiz Morris. Computer Language  Languages that the computer understands.  They are low level languages. (BINARY 1."— Presentation transcript:

1 Computer Programming Mr. José A. Ortiz Morris

2 Computer Language  Languages that the computer understands.  They are low level languages. (BINARY 1 / 0)  People used to program computers using them.

3 Low level languages  Language that only the computer’s CPU and other processing components can understand.  They are very difficult to understand by human beings.  Ex. 01101110  Programmers used to program in this type of language.

4 High level language  Language that is similar to regular human languages.  A CPU can’t understand it and it is used by programmers to program software.  Ex. System.out.println(“Hello World!”);  This type of language is sent to a compiler so that it can be turned to a low level language so that the computer can understand it.

5 Starting to Program  When we start to program the first thing that we have to understand is that the computer needs specific instructions to be able to perform the specific tasks it has to do.  Computers are not intelligent. They just do whatever the programmer tells it to do.

6 Giving instructions to the computer…  When a programmer gives instructions to the computer he/she used a high-level programming language to give them and its written down in a source code (Group of instructions that form a computer program).  The different instructions activate different components of the computer.

7 Using different tools to help with programming…  Since understanding a high-level computer language is difficult at first, pseudocodes and flowcharts to help understand the process the program has to do before writing down the source code.

8 Flowcharts Start End Display = “Hello!” Display = “Goodbye!”

9 Pseudocode Start Display = “Hello!”; Display = “Goodbye!”; End

10 Understanding each instruction…  In the previous examples of flowcharts and pseudocode we can see only 1 type of instruction. The Display instruction is used to send information to a monitor or any other type of output device to present it.  Start and End are just there to know that the program’s source code starts and ends at those specific points.

11 Other types of instructions…  Get = this instruction is used to acquire information from an input device. In this class we will always assume is from a keyboard.  Ex. Get = name;

12 Explaining the basic form of instructions…  In the last example we had an instruction: Get = name;  This instruction has 4 components:  The function ( Get )  An assigning operator ( = )  A variable ( name )  And an end mark ( ; )

13 Example… Start Display = “Please enter your name”; Get = name; Display = name; End

14 Variable Data Types  For the remainder of this topic we are going to use different types of variables and each type of variable has different data types:  String = stores text.  Ex. “Anthony”  Integer = stores whole numbers.  Ex. 25  Real = stores real numbers.  Ex. 25.5  Boolean = stores true or false (used for logical comparisons)  Ex. true

15 To use variables…  When you are going to use a variable in a computer program code you have to define them so that the computer will know what type of value they will store and to reserve the space in memory.  The format in this class to define a variable is: DEF name : string;

16 Reviewing previous code…  The last code that we wrote had an error. We didn’t define the variable to be able to use it. The correct way to write it would be the following: Start DEF name : string; Display = “Please enter your name”; Get = name; Display = name; End

17 Exercise… Write a program that: 1. Asks the user his name 2. Asks the user his age. 3. Asks the user 2 grades. 4. Calculates the average of the 2 grades. 5. Displays the result as the following: Hello, John Doe You are 12 years old Your grade average is 75.3

18 Start DEF name : string; DEF age : integer; DEF grade1, grade2, average : real; Display = “Please enter your name: ”; Get = name; Display = “Please enter your age: ”; Get = age; Display = “Please enter your first grade: ”; Get = grade1; Display = “Please enter your second grade: ”; Get = grade2; average = (grade1 + grade2)/2; Display = “Hello, ” + name; Display = “Your age is ” + age; Display = “Your grade average is ” + average; End

19 Exercise 2… Write a program that: 1. Asks the user his name 2. Asks the user his last name 3. Asks the user his age. 4. Asks the user 3 grades. 5. Asks the user his phone number. 6. Calculates the average of the 3 grades. 7. Displays the result as the following: Hello, John Doe You are 12 years old Phone#: 7872536894 Your grade average is 75.3

20 Start DEF name, lname : string; DEF age, phone : integer; DEF grade1, grade2, grade3, average : real; Display = “Please enter your name: ”; Get = name; Display = “Please enter your last name: ”; Get = lname; Display = “Please enter your age: ”; Get = age; Display = “Please enter your phone #: ”; Get = phone; Display = “Please enter the 1st grade: ”; Get = grade1; Display = “Please enter the 2nd grade: ”; Get = grade2; Display = “Please enter the 3rd grade: ”; Get = grade3; average = (grade1 + grade2 + grade3)/3; Display = “Hello, ” + name + “ ” + lname; Display = “You are ” + age “ years old.” Display = “Phone#: ” + phone Display = “Your grade average is ” + average; End

21 The If Statement function…  Programs have a need to be dynamic to be able to perform different functions for the user.  The if statement helps the programmer create something that can do 1 of 2 or more things.

22 If statement example…  If you have a program that has already asked the user his name, his last name and his marital status (single or married) and gender(Male or Female). You can show the different marriage status title before the name (Mr., Ms., or Mrs.)  Here is how it would be coded: If gender = “Male” Display= “Hello, Mr. ” + name + “ ” + lname Else Display= “Hello, Mrs. ” + name + “ ” + lname;

23 Example with Marital Status… Start. If gender = “Male” Display= “Hello, Mr. ” + name + “ ” + lname Else if mstatus = “single” Display= “Hello, Ms. ” + name + “ ” + lname Else Display = “Hello, Mrs. “ + name + “ ” + lname;. End

24 Grade Homework  Create a program that:  Modifies the previous program about the grade average and adds the grade letter to the average display depending on the average. Hello, John Doe You are 12 years old Phone#: 7872536894 Your grade average is 75.3 C


Download ppt "Computer Programming Mr. José A. Ortiz Morris. Computer Language  Languages that the computer understands.  They are low level languages. (BINARY 1."

Similar presentations


Ads by Google