Download presentation
Presentation is loading. Please wait.
1
CS110D: Programming Language I
Computer Science department Lecture 1: Introduction to computers & problem solving
2
Lecture Contents Course Info. Problem Solving Techniques Examples
Pseudocode Algorithm Flow charts Examples Elements of a Computer system. Evolution of programming languages The code Life Cycle dr. Amal Khalifa,Fall14
3
Course info Books and references Course plan
Assessment methods and grading Labs and practical assignments Practical exam
4
Books and references [1] JavaTM Programming: From Problem Analysis to Program Design (Introduction to Programming) 5th Edition Programming-Problem-Analysis- Introduction/dp/ X [2] Deitel P.J., Deitel H.M. - Java. How to Program, 9th Edition 481/Java%20How%20to%20Program%209t h%20Edition.pdf [1] [2]
5
How Computers Solve Problems
Create a solution (called an Algorithm) which manipulates Data into Information Computers use Algorithms to solve problems, and change data into information Computers can only perform one simple step at a time Dr. Amal Khalifa, 2014
6
Algorithms Example: Accelerating in a car
Algorithm: A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time Example: Accelerating in a car Move right foot to gas pedal Apply pressure to gas pedal with right foot If speed is too high, apply less pressure. If speed is too low, apply more pressure. Dr. Amal Khalifa, 2014
7
Problem Solving Approach
Problem-solving process involves the following steps: 1. Analyze the problem and outline the problem and its solution requirements. 2. Design an algorithm to solve the problem. 3. Implement the algorithm in a programming language, such as Java. 4. Verify that the algorithm works. 5. Maintain the program by using and improving it, and modifying it if the problem domain changes. Dr. Amal Khalifa, 2014
8
Expressing the Algorithms
A “Standard” way of describing an algorithm must exist if we expect our solution to be understood by others easily There are standards in programming: PSEUDOCODE FLOWCHARTS Dr. Amal Khalifa, 2014
9
Pseudo Code “Pseudo” means “pretend” or “false”
Pseudo Code is pretend or false computer code; uses generic English-like terms Pseudo Code is not as standardized as flowcharts, and does not facilitate the breaking down of problems as well as a flowchart does Dr. Amal Khalifa, 2014
10
Example Write an algorithm to find the area and the perimeter of a rectangle dr. Amal Khalifa,Fall14
11
Pseudo Code Example design an algorithm to find the perimeter and area of a rectangle Dr. Amal Khalifa, 2014
12
That’s all for Today!! Text book [1] chapter 1 (pages 13-16)
Dr. Amal Khalifa, 2014
13
Flowcharts Graphical representations of algorithms or a tool to translate algorithm A Flowchart uses easy-to-understand symbols to represent actions on data and the flow of data Flowcharts aid in breaking down a problem into simple steps Dr. Amal Khalifa, 2014
14
Flowchart Symbols Dr. Amal Khalifa, 2014
15
flowcharting Dr. Amal Khalifa, 2014
16
Example Example 1: Write an algorithm and draw a flowchart to convert the length in feet to centimeter. hint: I feet = 30 cm Dr. Amal Khalifa, 2014
17
Pseudocode Input the length in feet (Lft)
Calculate the length in cm (Lcm) by multiplying LFT with 30 Print length in cm (LCM) Dr. Amal Khalifa, 2014
18
Algorithm Step 1: Input Lft Step 2: Lcm Lft x 30 Step 3: Print Lcm
Flowchart START Input Lft Lcm Lft x 30 Print Lcm STOP Dr. Amal Khalifa, 2014
19
Example 2 Write an algorithm and draw a flowchart that will read the radius of a circle and calculate its area. Dr. Amal Khalifa, 2014
20
Example 2 Input the radius (r) of a circle Calculate the area (A) :
Pseudocode Input the radius (r) of a circle Calculate the area (A) : A Pi x r x r Print A Dr. Amal Khalifa, 2014
21
Example 2 Algorithm Step 1: Input r Step 2: A Pi x r x r
Step 3: Print A START Input r A Pi x r x r Print A STOP Dr. Amal Khalifa, 2014
22
Example 3 Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation Hint: the roots are: x1 = (–b + d)/2a and x2 = (–b – d)/2a where, d = sqrt ( ) Dr. Amal Khalifa, 2014
23
Example 3 START Input a, b, c d sqrt(b x b – 4 x a x c) Print x1 ,x2 STOP x1 (–b + d) / (2 x a) X2 (–b – d) / (2 x a) Algorithm: Step 1: Input the coefficients (a, b, c) of the quadratic equation Step 2: d sqrt ( ) Step 3: x1 (–b + d) / (2 x a) Step 4: x2 (–b – d) / (2 x a) Step 5: Print x1, x2
24
Elements of a Computer System
Hardware Software Computer dr. Amal Khalifa,Fall14
25
Hardware dr. Amal Khalifa,Fall14 Dr. Amal Khalifa - Spring 2012
In my opinion, the students will have a better understanding of what they are doing if they have a little background on the major pieces of a computer and how they work. This is pretty simple and straightforward right now. There's no mention of this being the von Neuman architecture right now, but that should be considered in a revision of these notes. The blue box represents the core pieces of a computer. The input and output devices are peripheral but important additions. dr. Amal Khalifa,Fall14 Dr. Amal Khalifa - Spring 2012
26
Memory Unit Ordered sequence of cells or locations
Stores instructions and data in binary Types of memory Read-Only Memory (ROM) Random Access Memory (RAM) Bits & Bytes Memory is probably the most important unit for students to understand. This is a brief introduction, but we'll be revisiting memory in future classes. It'll be important for students to see the link between variables and memory. dr. Amal Khalifa,Fall14
27
Binary Data Bit: A binary digit 0 or 1.
Here are the numbers!! Binary Data Bit: A binary digit 0 or 1. A sequence of eight bits is called a byte. dr. Amal Khalifa,Fall14
28
ASCII Code Every letter, number, or special symbol (such as * or {) on your keyboard is encoded as a sequence of bits, each having a unique representation. The most commonly used American Standard Code for Information Interchange (ASCII). What about letters/characters? dr. Amal Khalifa,Fall14
29
Central Processing Unit (CPU)
Executes stored instructions Arithmetic/Logic Unit (ALU) Performs arithmetic and logical operations Control Unit Controls the other components Guarantees instructions are executed in sequence Explain each functional unit in more detail. dr. Amal Khalifa,Fall14
30
Input and Output Devices
Interaction with humans Gathers data (Input) Displays results (Output) Input and output devices are the pieces of the computer we interact with the most. The students should be familiar with each of these peripherals. In fact, it's a good idea to let the students know that if they aren't familiar with these peripherals that they should be taking the computer literacy class instead. dr. Amal Khalifa,Fall14
31
Software perform specific tasks Examples : Word processors
System programs Application programs loads first when you turn on your PC Also called the operating system. The operating system monitors the overall activity of the computer and provides services, such as memory management, input/output activities, and storage management. perform specific tasks Examples : Word processors spreadsheets, and games Both operating systems and application programs are written in programming languages. dr. Amal Khalifa,Fall14
32
Are Computers Intelligent?
Do we really need to be involved in programming computers? They have beaten world chess champions. They help predict weather patterns. They can perform arithmetic quickly. So, a computer has an IQ of _____. Again, try to motivate the students to question why they are in this class. It's not simply to make lots of money, but computers are just plain dumb. The IQ of a computer is 0. dr. Amal Khalifa,Fall14
33
What is Computer Programming?
Planning or scheduling a sequence of steps for a computer to follow to perform a task. Basically, telling a computer what to do and how to do it. A program: A sequence of steps to be performed by a computer. Expressed in a computer language. Now, apply programming to computers. dr. Amal Khalifa,Fall14
34
Computer Languages A set of used to construct a program.
Symbols (punctuation), Special words or keywords (vocabulary), And rules (grammar) used to construct a program. Relate computer languages back to natural languages. Students need to appreciate the similarities between the two. Yes, computer languages are somewhat more strict about punctuation and grammar. However, students need to get rid of their fear of the difficulties with the languages. dr. Amal Khalifa,Fall14
35
Evolution of Programming Languages
Languages differ in Size (or complexity) Readability Expressivity (or writability) "Level" closeness to instructions for the CPU dr. Amal Khalifa,Fall14
36
Machine Language Binary-coded instructions Used directly by the CPU
Lowest level language Every program step is ultimately a machine language instruction Address Contents 2034 2035 2036 2037 2038 2039 2040 2041 2042 Be sure to define "binary" here. Also include definitions of bits and bytes in the discussion as well. Not included on the slide to save space and also it's not important for the students to memorize at this point. Remember, we're just introducing things to the students. Don't expect them to memorize all of this stuff. dr. Amal Khalifa,Fall14
37
Assembly Language Each CPU instruction is labeled with a mnemonic.
Very-low level language Almost 1 to 1 correspondence with machine language Assembler: A program that translates a program written in assembly language into an equivalent program in machine language. Sample Program I wonder if this might be getting too gory. Still, I think it's kind of useful. MUL X,10 ADD X,Y STO Z,20 SUB X,Z Mnemonic Instruction ADD dr. Amal Khalifa,Fall14
38
Examples of Instructions in Assembly Language and Machine Language
dr. Amal Khalifa,Fall14
39
High-Level Languages Closer to natural language
Compiler: A program that translates a program written in a high-level language into the equivalent machine language. dr. Amal Khalifa,Fall14
40
Examples of High-Level Languages
Primary Uses Pascal Learning to program C++ General purpose FORTRAN Scientific programming PERL Web programming, text processing Java Web programming, application programming COBOL Business dr. Amal Khalifa,Fall14
41
The java Language source program. Saved in File ClassName.ja va
dr. Amal Khalifa,Fall14
42
The Code life Cycle!! Edit compile run dr. Amal Khalifa,Fall14
In the Java programming language, all source code is first written in plain text files ending with the .java extension. Those source files are then compiled into .class files by the javac compiler. A .class file does not contain code that is native to your processor; it instead contains bytecodes — the machine language of the Java Virtual Machine1 (Java VM). The java launcher tool then runs your application with an instance of the Java Virtual Machine. An overview of the software development process. dr. Amal Khalifa,Fall14
43
Processing a java program
dr. Amal Khalifa,Fall14
44
IDE The programs that you write in Java are typically developed using an integrated development environment (IDE). dr. Amal Khalifa,Fall14
45
That’s all for Today!! Text book [1] chapter 1 (pages 1-13)
dr. Amal Khalifa,Fall14
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.