CS 1713 Introduction to Computer Programming II Ch 0 Overview - Problem solving

Similar documents
BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

Chapter 1: An Overview of Computers and Programming Languages. Objectives. Objectives (cont d.) Introduction

Chapter 1 Computer and Programming. By Zerihun Alemayehu

CSCE150A. Administrivia. Overview. Hardware. Software. Example. Program. Pseudocode. Flowchart. Control Structures. Hello World Program CSCE150A

Computer Science & Engineering 150A Problem Solving Using Computers

Problem Solving and Program Design - Chapter 1. Cory L. Strope

Week 0: Intro to Computers and Programming. 1.1 Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components

Fundamentals of Programming. Lecture 1: Introduction to C Programming

Machine Architecture and Number Systems CMSC104. Von Neumann Machine. Major Computer Components. Schematic Diagram of a Computer. First Computer?

Administration Computers Software Algorithms Programming Languages

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

Machine Architecture and Number Systems

CHAPTER 1 Introduction to Computers and Java

Computer Basics 1/6/16. Computer Organization. Computer systems consist of hardware and software.

Chapter 1: Introduction

EL2310 Scientific Programming

Lecture 1. A. Sahu and S. V. Rao. Indian Institute of Technology Guwahati

Computer Basics 1/24/13. Computer Organization. Computer systems consist of hardware and software.

CSI31 Introduction to Computer Programming I. Dr. Sharon Persinger Fall

Outline. Introduction to Programming (in C++) Introduction. First program in C++ Programming examples

Chapter 1 INTRODUCTION

! Learn how to think like a computer scientist. ! Learn problem solving. ! Read and write code. ! Understand object oriented programming

Introduction. Arizona State University 1

Fundamentals of Programming Session 1

Introduction to C Programming

Computer Principles and Components 1

Software Lesson 1 Outline

EKT 120/4 Computer Programming KOLEJ UNIVERSITI KEJURUTERAAN UTARA MALAYSIA

last time in cs recitations. computer commands. today s topics.

Programming 1. Lecture 1 COP 3014 Fall August 28, 2017

Chapter 1 Introduction to Computers and Programming

Fundamentals of Programming Session 1

Introduction to Computers. Joslyn A. Smith

Java and Software Design

8/16/12. Computer Organization. Architecture. Computer Organization. Computer Basics

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

Lecture 1: CS2400 Introduction to Computer Science

Chapter 1 Introduction to Computers and C++ Programming

EL2310 Scientific Programming

BITG 1113: Introduction To Computers And Programming Language LECTURE 1 LECTURE 1 1

Welcome to Computer Organization and Design Logic

What s next. Computer Systems A Programmer s Perspective

Elements of Computers and Programming Dr. William C. Bulko. What is a Computer?

Computer Fundamentals

0 Introduction: Computer systems and program development

18. Machine Language. Computer Systems. COMP1917: Computing 1. Machine Language Programming. History of Computer Technology

by Pearson Education, Inc. All Rights Reserved.

Software Project. Lecturers: Ran Caneti, Gideon Dror Teaching assistants: Nathan Manor, Ben Riva

Welcome to Computer Organization and Design Logic CS 64: Computer Organization and Design Logic Lecture #1 Winter 2018

3/13/2012. ESc101: Introduction to Computers and Programming Languages

Data types, variables, constants

Programming 1 - Honors

Chapter 1 & 2 Introduction to C Language

Computational Physics Operating systems

Fundamentals of Programming (C)

A B C D E F. = 1/3 1 divided by 3, that is, The product of cells A2 and C12. Cell C6 divided by the difference of D4 and E4

Lab 1 Introduction to UNIX and C

Lecture 1: Preliminaries

CSC180: Lecture 2. Wael Aboulsaadat.

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

CS120 Computer Science I. Instructor: Jia Song

Instructor. Mehmet Zeki COSKUN Assistant Professor at the Geodesy & Photogrammetry, Civil Eng. (212)

ENCM 501 Winter 2018 Assignment 2 for the Week of January 22 (with corrections)

OPERATING SYSTEMS CS136

1.1 Count, read, and write whole numbers to

Spring 2018 NENG 202 Introduction to Computer Programming

ENCM 501 Winter 2016 Assignment 1 for the Week of January 25

Introduction to Computer Systems

C++ Programming Language Lecture 1 Introduction

We are going to define a computer, and yes, all the devices you see in the slide are computers, some more specialized than others, but all computers.

Integer Operations. Summer Packet 7 th into 8 th grade 1. Name = = = = = 6.

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

CS240: Programming in C

Computer Organisation IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

COMP163. Introduction to Computer Programming. Introduction and Overview of the Hardware

1a Computers, Problem Solving!

ECS15, Lecture 10. Goals of this course 2/8/13. Mini-Review & Topic 3.2 Software. Today s agenda

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York

IB Computer Science Topic.2-

An Introduc+on to Computers and Java CSC 121 Spring 2017 Howard Rosenthal

Basic Computer Programming for ISNE. Santi Phithakkitnukoon ผศ.ดร.ส นต พ ท กษ ก จน ก ร

Chapter 1: Introduction to Computers and Programming

EXCEL BASICS: MICROSOFT OFFICE 2007

Problem Solving With C++ Ninth Edition

CSC231 C Tutorial Fall 2018 Introduction to C

CMSC131. Hardware and Software. Hardware

CMSC131. Hardware and Software

Chris Riesbeck, Fall Introduction to Computer Systems

Chapter 1 Introduction to Computers and C++ Programming

Dalhousie University CSCI 2132 Software Development Winter 2018 Lab 8, March 22

II Esercitazione: S.O. & Fortran 90

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Computer Programming-1 CSC 111. Chapter 1 : Introduction

Cost of Your Programs

CPS104 Computer Organization Lecture 1. CPS104: Computer Organization. Meat of the Course. Robert Wagner

CSC111 Computer Science II

SCSP Programming Technique C

EECE 321: Computer Organization

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

Transcription:

CS 1713 Introduction to Computer Programming II Ch 0 Overview - Problem solving Turgay Korkmaz Office: SB 4.01.13 Phone: (210) 458-7346 Fax: (210) 458-4437 e-mail: korkmaz@cs.utsa.edu web: www.cs.utsa.edu/~korkmaz 1

What is the goal of a programmer? Solve problems using computing systems 2

Problem Solving Main part of problem solving is to figure out Algorithms (necessary steps/instructions and their orders) and Appropriate data structures Then to code the algorithm and the data structure in some programming language (we will use C) Computers cannot think or develop a solution! You do! Computers just follow your instructions and do the operations faster Then how do computers do many things? Even play a game, for example chess! For the same problem, we may come up with different and yet correct solutions. Efficiency vs. Cost 3

Computing System 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., computer, keyboard, mouse, terminal, hard disk, printer) Software: programs that describe the steps we want the computer to perform. 4

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

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 abstractions 6

What is C? General purpose, machine-independent, highlevel programming language Developed at Bell Labs in 1972 by Dennis Ritchie American National Standards Institute (ANSI) approved ANSI C standard in 1989 Source file 7

Hello World! in Linux Login to a linux machine SSH Secure Shell (e.g., elk03.cs.utsa.edu) elk03 :> mkdir myprog elk03 :> cd myprog elk03 :> pico hello.c Type your program and save it (ctrl-o) Compile and execute your program elk03 :> gcc hello.c o hello elk03 :> hello 8

PROBLEM SOLVING Very Important If you can develop solution, then coding in C is easy So, before studying C, let us C a few examples of problem solving 9

Problem Solving Methodology 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 10

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

Example 1 (cont d) 3. Hand example side1 = 4-1 = 3 side2 = 7-5 = 2 distance 2 side1 side2 2 distance side1 2 side2 2 distance 3 2 2 2 distance 13 3.61 12

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 2 distance side1 4) Print distance side2 b. Convert the above outlined solution to a program using any language you want (see next slide for C imp.) 2 13

Example 1 (cont d) 14

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? 15

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

Simple examples to develop solutions 17

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

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 total_sec H M S 3675 seconds can be written as 1 hour 1 min 15 sec 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 19

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

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? 21

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? y x 22

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? 23

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 24

Assign letter grades Suppose I have your grades as follows name final midterm avg_hw quizze letter aaaa 30 20 30 4? bbbb 20 15 40 10? How can I assign letter grades? 25

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

Ten heuristics for problem solving How to Solve it: Modern Heuristics by Michalewicz and Fogel. Springer 2004. 1. 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 27

Ten heuristics for problem solving How to Solve it: Modern Heuristics by Michalewicz and Fogel. Springer 2004. 6. 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! 28