Download presentation

Presentation is loading. Please wait.

Published byCody Last Modified about 1 year ago

1
1 Turgay Korkmaz Office: SB Phone: (210) Fax: (210) web: CS 2073 Computer Programming w/Eng. Applications Ch 1

2
2 Lecture++; NameAddrContent Lecture2

3
3 Ch1: Engineering Problem Solving Read Section 1.1 from the textbook Recent Engineering Achievements Microprocessor Moon landing Satellites Computer-aided design (CAD) and manufacturing Jumbo jet Advance computer materials Computerized axial tomography Genetic engineering Lasers Optical fiber Changing Engineering Environment Communication skills (oral, written) Concept-Design-process-manufacture Interdisciplinary teams Word marketplace Analyzing-Synthesizing Societal Context

4
4 Ch1: Engineering Problem Solving (cont’d) Section 1.2: Computing Systems Computer: a machine that is designed to perform operations (set of instructions called program) to achieve a specific task (e.g., 3+4) Hardware: computer equipment (e.g., keyboard, mouse, terminal, hard disk, printer) Software: programs that describe the steps we want the computer to perform.

5
5 Computer Hardware CPU - Central processing unit ALU - Arithmetic and logic unit ROM - Read only memory RAM - Random access memory CPU Internal Memory External Memory InputOutput Processor ALU In this sense, do you think we are like a computer? Yes + we have intelligence

6
6 Computer Software Operating System - Provides an interface with the user unix, windows, linux,... Software Tools word processors (MicrosoftWord, WordPerfect,...) spreadsheet programs (Excel, Lotus1-2-3,...) mathematical computation tools (MATLAB, Mathematica,...) Computer Languages machine language assembly language binary language high level languages (C, C++, Ada, Fortran, Basic, java) WE WILL STUDY C PROGRAMMING LANGUAGE General purpose, machine-independent language Developed at Bell Labs in 1972 by Dennis Ritchie American National Standards Institute(ANSI) approved ANSI C standard in 1989

7
7 Executing a Computer Program Compiler Converts source program to object program Linker Converts object program to executable program

8
8 Some Key Terms and Software Life-Cycle Phases Source Program printable/Readable Program file Object Program nonprintable machine readable file Executable Program nonprintable executable code Syntax errors reported by the compiler Linker errors reported by the linker Execution/Run-time errors reported by the operating system

9
9 PROBLEM SOLVING Very Important

10
10 Ch 1.3 Problem Solving Methodology (must read) 1. State the problem clearly 2. Describe the input/output information 3. Work the problem by hand, give example 4. Develop a solution (Algorithm Development) and Convert it to a program (C program) 5. Test the solution with a variety of data

11
11 Example 1 1. Problem statement Compute the straight line distance between two points in a plane 2. Input/output description Point 1 (x1, y1) Point 2 (x2, y2) Distance between two points (distance) (x1,y1) (x2, y2)

12
12 3. Hand example Example 1(cont’d) side1 = = 3 side2 = = 2

13
13 Example 1(cont’d) 4. Algorithm development and coding a. Generalize the hand solution and list/outline the necessary operations step-by-step 1) Give specific values for point1 (x1, y1) and point2 (x2, y2) 2) Compute side1=x2-x1 and side2=y2-y1 3) Compute 4) Print distance b. Convert the above outlined solution to a program using any language you want (see next slide for C imp.)

14
14 Example 1(cont’d)

15
15 Example 1(cont’d) 5. Testing After compiling your program, run it and see if it gives the correct result. Your program should print out The distance between two points is 3.61 If not, what will you do?

16
16 Modification to Example 1 x1=2, y1=5, x2=10, y2=8, How will you find the distance between two other points (2,5) and (10,8)?

17
17 Few Issues We will study the details of this program and C language later… The programming language is not the main part of problem solving! Main part is to figure out the necessary steps and their orders (if you can develop solution then coding is easy) For the same problem, we may come up with different and yet correct solutions. Computers cannot think or develop a solution, they just follow your instructions and do the operations faster Then how do computers do many things? Even play a game, for example chess?

18
18 Simple examples to develop solutions

19
19 Compute the area of a triangle 1. State problem 2. I/O 3. Hand example 4. Develop solution and Coding 5. Testing area xyxy x=3 cm y=4 cm area = ½ * 3 *4 = 6 cm 2 1.Get values of x and y 2.Compute area = ½*x*y 3.Print area

20
20 Given two complex numbers z1=a1+b1*i and z2=a2+b2*i, find z3= z1+z2 1. State problem 2. I/O 3. Hand example 4. Develop solution and Coding 5. Testing a3 a1 b1 a2 b2 b3 1.Get a1 b1 a2 b2 2.Compute a3 = a1 + a2 3.Compute b3 = b1 + b2 4.Print z3 = a3 + b3 * i

21
21 Given the number of seconds, find number of hours, minutes and seconds 1. State problem 2. I/O 3. Hand example 4. Develop solution and Coding 5. Testing 3675 seconds can be written as 1 hour 1 min 15 sec H total_sec M S 1.Get total_sec 2.H = total_sec / 3600 (integer division) 3.M = (total_sec – (H*3600)) / 60 M = (total_sec mod 3600) / 60 4.S = total_sec – (H*3600) – (M*60) 5.Print H hour, M min, S sec

22
22 A little bit difficult examples to develop solutions Some problems are from How to Solve it: Modern Heuristics by Michalewicz and Fogel. Springer 2004.

23
23 Example: Average speed Suppose a car goes from city A to city B with speed of 40 mph and immediately comes back with the speed of 60 mph. What is the average speed? Can you generalize this solution and outline step by step to find average speed when the speed from A to B is X and the speed from B to A is Y?

24
24 Quiz: Dimensions of a rectangle ranch? A farmer has a rectangular ranch with a perimeter of P=110 meters and an area of A=200 square meters. What are the dimensions of his ranch? What are the dimensions for any P and A? x y

25
25 Example: Make a triangle with maximum area Suppose you have a stick with the length of L meters. You want to divide it into three pieces with the length of x, y, and z meters, and make a triangle Find x, y, z such that the area of that triangle is maximum. x y z L

26
26 Example: Climbing a wooden post A snail is climbing a wooden post that is H=10 meters high. During the day, it climbs U=5 meters up. During the night, it falls asleep and slides down D=4 meters. How many days will it take the snail to climb the top of the post? Given that H > U > D. Can you generalize your solution for any H, U, and D?

27
Minimum number of coins Suppose you want to give x=67 cents to a person, what is the minimum number of coins You have many 25, 10, 5, 1 cents 27

28
28 Example: Assign letter grades Suppose I have your grades as follows name final midterm avg_hw quizze letter aaaa ? bbbb ? … How can I assign letter grades?

29
29 Example: Sum of numbers Given n (for example n=1000), compute sum = …+n sum_odd = …+(2n+1) ln2=1- 1/2 + 1/3 - 1/4 +… 1/n

30
30 If you want this course to be easy, you must learn how to act like a computer Develop necessary step-by-step instructions to perform the following real-life tasks like a computer Driving a car Following a direction to find an address Cook something Search a word in a dictionary Make a phone call Now, its your turn to think of a problem and give STEP-BY-STEP instructions… For the same problem, we may have different and yet correct solutions. So, …

31
31 Ten heuristics for problem solving How to Solve it: Modern Heuristics by Michalewicz and Fogel. Springer Don’t rush to give an answer, think about it 2. Concentrate on the essentials and don’t worry about the noise (tiny details) 3. Sometimes finding a solution can be really easy (common sense), don’t make it harder on yourself 4. Beware of obvious solutions. They might be wrong 5. Don’t be misled by previous experience

32
32 Ten heuristics for problem solving How to Solve it: Modern Heuristics by Michalewicz and Fogel. Springer Start solving. Don’t say “I don’t know how” Most people don’t plan to fail, they just fail to plan! 7.Don’t limit yourself to the search space that is defined by the problem. Expand your horizon 8.Constraints can be helpful to focus on the problem at the hand 9.Don’t be satisfied with finding a solution, look for better ones 10.Be patient. Be persistent!

33
A Checklist for Engineering Reasoning 1. All engineering reasoning expresses a purpose. Take time to state your purpose clearly. Distinguish your purpose from related purposes. Check periodically to be sure you are still on target. Choose realistic and achievable purposes. 33

34
2. All engineering reasoning seeks to figure something out, to settle some question, solve some engineering problem. Take time to state the question at issue clearly and precisely. Express the question in several ways to clarify its meaning and scope. Break the question into sub-questions. Determine if the question has one right answer, or requires reasoning from more than one hypothesis or point of view. 34

35
3. All engineering reasoning requires assumptions. Clearly identify your assumptions and determine whether they are justifiable. Consider how your assumptions are shaping your point of view. Consider the impact of alternative or unexpressed assumptions. Consider the impact of removing assumptions. 35

36
4. All engineering reasoning is done from some perspective or point of view. Identify your specific point of view. Consider the point of view of other stakeholders. Strive to be fair-minded in evaluating all relevant points of view. 36

37
5. All engineering reasoning is based on data, information, and evidence. Validate your data sources. Restrict your claims to those supported by the data. Search for data that opposes your position as well as alternative theories. Make sure that all data used is clear, accurate, and relevant to the question at issue. Make sure you have gathered sufficient data. 37

38
6. All engineering reasoning is expressed through, and shaped by, concepts and theories. Identify key concepts and explain them clearly. Consider alternative concepts or alternative definitions of concepts. Make sure you are using concepts and theories with care and precision. 38

39
7. All engineering reasoning entails inferences or interpretations by which we draw conclusions and give meaning to engineering work. Infer only what the data supports. Check inferences for their internal and external consistency. Identify assumptions that led you to your conclusions. 39

40
8. All engineering reasoning leads somewhere or has implications and consequences. Trace the implications and consequences that follow from your data and reasoning. Search for negative as well as positive implications (technical, social, environmental, financial, ethical). Consider all possible implications. 40

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google