CS 110 D PROGRAMMING LANGUAGE I Computer Science




![Books and references 5 [1] Java. TM Programming: From Problem Analysis to Program Design Books and references 5 [1] Java. TM Programming: From Problem Analysis to Program Design](https://slidetodoc.com/presentation_image_h2/7653ea7ee179090de6c9eb7a3846b0e4/image-5.jpg)











![17 That’s all for Today!! Text book [1] chapter 1 (pages 13 -16) Dr. 17 That’s all for Today!! Text book [1] chapter 1 (pages 13 -16) Dr.](https://slidetodoc.com/presentation_image_h2/7653ea7ee179090de6c9eb7a3846b0e4/image-17.jpg)






























![48 That’s all for Today!! Text book [1] chapter 1 (pages 1 -13) dr. 48 That’s all for Today!! Text book [1] chapter 1 (pages 1 -13) dr.](https://slidetodoc.com/presentation_image_h2/7653ea7ee179090de6c9eb7a3846b0e4/image-48.jpg)
- Slides: 48
CS 110 D: PROGRAMMING LANGUAGE I Computer Science department Lecture 1: Introduction to computers & problem solving
Lecture Contents 2 Course Info. Problem Solving Techniques � Pseudocode � Algorithm � Flow charts Examples Elements of a Computer system. Evolution of programming languages The code Life Cycle dr. Amal Khalifa, Fall 14
Course info 3 Books and references Course plan Assessment methods and grading Labs and practical assignments Practical exam
4 Assessment methods and grading Assessment method Assessment Week Grade Percentag e from overall grade Mid Term 1 Week 7 EXAM DAY 18/6/1438 6 March 2018 15 15% Mid Term 2 Week 11 EXAM_DAY 17/7/1438 3 April 2018 15 15% Lab Work Weekly 5 5% Assignments Weekly 5 5% Practical Exam Week 14 20 15% Final Exam After 15 40 40%
Books and references 5 [1] Java. TM Programming: From Problem Analysis to Program Design (Introduction to Programming) 5 th Edition [1] https: //www. amazon. com/Java. TMProgramming-Problem-Analysis. Introduction/dp/111153053 X [2] Deitel P. J. , Deitel H. M. - Java. How to Program, 10 th Edition http: //staff. cs. psu. ac. th/iew/cs 344481/Java%20 How%20 to%20 Program%20 9 th%20 Edition. pdf [2]
How People Solve Problems 6 A Problem exists when what we have (Data) is not the same as what we want (information) People create a solution (called an Algorithm) which manipulates Data into Information People do this quickly and often in a complex way Dr. Amal Khalifa, 2014
7 How Computers Solve Problems Computers also use Algorithms to solve problems, and change data into information Computers can only perform one simple step at a time Complex “Human” Algorithms must be broken down into simple step-by-step instructions BEFORE they can be translated into computer code Dr. Amal Khalifa, 2014
Algorithms 8 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 1. 2. 3. 4. 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
Problem Solving 9 Problem Solving is the ability to understand what you have, what you want, and creating a set of instructions to change what you have into what you want Good Problem Solving Skills are based on knowledge, experience and logic Good Programmers NEVER make assumptions Dr. Amal Khalifa, 2014
Problem Solving Approach 10 In the programming environment, the problemsolving 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
11 Problem analysis–coding–execution cycle Dr. Amal Khalifa, 2014
Expressing the Algorithms 12 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
Pseudo Code 13 “Pseudo” means “pretend” or “false” Pseudo Code is pretend or false computer code; generic English-like terms that are somewhat like computer code 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
Pseudocode (wikipedia) 14 Pseudocode (derived from pseudo and code) is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of programming languages, but omits detailed subroutines, variable declarations or languagespecific syntax. The programming language is augmented with natural language descriptions of the details, where convenient. Dr. Amal Khalifa, 2014
Example 15 Write an algorithm to find the area and the perimeter of a rectangle dr. Amal Khalifa, Fall 14
16 Pseudo Code Example design an algorithm to find the perimeter and area of a rectangle Dr. Amal Khalifa, 2014
17 That’s all for Today!! Text book [1] chapter 1 (pages 13 -16) Dr. Amal Khalifa, 2014
Flowcharts 18 Graphical representations of algorithms Tool to translate algorithms into software 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
Flowchart Symbols 19
flowcharting 20 Dr. Amal Khalifa, 2014
Example 21 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
Pseudocode 22 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
Algorithm 23 Flowchart Step 1: Input Lft Step 2: Lcm Lft x 30 Step 3: Print Lcm START Input Lft Lcm Lft x 30 Print Lcm STOP Dr. Amal Khalifa, 2014
Example 2 24 Write an algorithm and draw a flowchart that will read the radius of a circle and calculate its area. Dr. Amal Khalifa, 2014
Example 2 25 Pseudocode Input the radius (r) of a circle Calculate the area (A) : A Pi x r Print A Dr. Amal Khalifa, 2014
Example 2 26 Algorithm Step 1: Input r Step 2: A Pi x r Step 3: Print A START Input r A Pi x r Print A STOP Dr. Amal Khalifa, 2014
Example 3 27 Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation Hint: the roots are: x 1 = (–b + d)/2 a and x 2 = (–b – d)/2 a where, d = sqrt ( ) Dr. Amal Khalifa, 2014
Example 3 START 28 Algorithm: Input a, b, c Step 1: Input the coefficients (a, b, c) of the quadratic equation Step 2: d sqrt ( Step 3: x 1 (–b + d) / (2 x a) Step 4: x 2 (–b – d) / (2 x a) Step 5: Print x 1, x 2 ) d sqrt(b x b – 4 x a x c) x 1 (–b + d) / (2 x a) X 2 (–b – d) / (2 x a) Print x 1 , x 2 STOP
29 Elements of a Computer System Hardwar e Comput er Software dr. Amal Khalifa, Fall 14
Hardware 30 dr. Amal Khalifa, Fall 14
Memory Unit 31 Ordered sequence of cells or locations Bits & Bytes Stores instructions and data in binary Types of memory � Read-Only Memory (ROM) � Random Access Memory (RAM) dr. Amal Khalifa, Fall 14
Central Processing Unit (CPU) 32 Executes stored instructions Arithmetic/Logic Unit (ALU) � Performs arithmetic and logical operations Control Unit � Controls the other components � Guarantees instructions are executed in sequence dr. Amal Khalifa, Fall 14
Input and Output Devices 33 Interaction with humans Gathers data (Input) Displays results (Output) dr. Amal Khalifa, Fall 14
Software 34 System 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. Application programs perform specific tasks Examples : � � � Word processors spreadsheets, and games Both operating systems and application programs are written in programming languages. dr. Amal Khalifa, Fall 14
Are Computers Intelligent? 35 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 _____. dr. Amal Khalifa, Fall 14
36 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. dr. Amal Khalifa, Fall 14
Computer Languages 37 A set of � Symbols (punctuation), � Special words or keywords (vocabulary), � And rules (grammar) used to construct a program. dr. Amal Khalifa, Fall 14
38 Evolution of Programming Languages differ in � Size (or complexity) � Readability � Expressivity (or writability) � "Level" closeness to instructions for the CPU dr. Amal Khalifa, Fall 14
Machine Language 39 Binary-coded instructions Used directly by the CPU Lowest level language Every program step is ultimately a machine language instruction Address Contents 2034 10010110 2035 11101010 2036 00010010 2037 1010 2038 10010110 2039 11101010 2040 1111 2041 0101 2042 10101101 dr. Amal Khalifa, Fall 14
Assembly Language 40 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 Mnemonic Instruction ADD 10010011 MUL ADD STO SUB X, 10 X, Y Z, 20 X, Z dr. Amal Khalifa, Fall 14
41 Examples of Instructions in Assembly Language and Machine Language dr. Amal Khalifa, Fall 14
High-Level Languages 42 Closer to natural language Each step maps to several machine language instructions � Easier to state and solve problems Compiler: A program that translates a program written in a high-level language into the equivalent machine dr. Amal Khalifa, Fall 14
43 Examples of High-Level Languages Language Pascal C++ FORTRAN PERL Primary Uses Learning to program General purpose Scientific programming Web programming, text processing Java Web programming, application programming COBOL Business dr. Amal Khalifa, Fall 14
The java Language 44 source program. Saved in File Class. Name. j ava dr. Amal Khalifa, Fall 14
The Code life Cycle!! 45 Edit compile run dr. Amal Khalifa, Fall 14
46 Processing a java program dr. Amal Khalifa, Fall 14
IDE 47 The programs that you write in Java are typically developed using an integrated development environment (IDE). dr. Amal Khalifa, Fall 14
48 That’s all for Today!! Text book [1] chapter 1 (pages 1 -13) dr. Amal Khalifa, Fall 14