Identify skills and personality traits of successful problem solving. Apply standard problem-solving techniques to aid in problem solving.

Similar documents
CC112 Structured Programming

Conditions and Logical Expressions. C Programming

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

Structured Programming. Dr. Mohamed Khedr Lecture 4

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

CHAPTER 3 BASIC INSTRUCTION OF C++

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Chapter 2: Overview of C. Problem Solving & Program Design in C

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Input/Output Week 5:Lesson 16.1

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

LECTURE 02 INTRODUCTION TO C++

C: How to Program. Week /Mar/05

Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Flow of Control. bool Data Type. Flow Of Control. Expressions. C++ Control Structures < <= > >= ==!= ! &&

Chapter 7 Arithmetic

ET156 Introduction to C Programming

Chapter 2 - Introduction to C Programming

Chapter 5. Conditions, Logical Expressions, and Selection Control Structures

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

Chapter 5 Topics. Chapter 5 Topics. Flow of Control. bool Data Type. Flow of Control. Chapter 5

AMCAT Automata Coding Sample Questions And Answers

Introduction to Computing Lecture 01: Introduction to C

Arithmetic Expressions in C

Chapter 3 Problem Solving and the Computer

printf( Please enter another number: ); scanf( %d, &num2);

CS 31: Intro to Systems Binary Arithmetic. Martin Gagné Swarthmore College January 24, 2016

Chapter 2. Lexical Elements & Operators

LAB 2.1 INTRODUCTION TO C PROGRAMMING

DEPARTMENT OF MATHS, MJ COLLEGE

BASIC ELEMENTS OF A COMPUTER PROGRAM

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Arithmetic type issues

Chapter 1 & 2 Introduction to C Language

Conditional Statement

Variables, Data Types, and Arithmetic Expressions Learning Objectives:

Chapter 2: Overview of C++

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

Control Structure: Loop

Midterm Exam. CSCI 2132: Software Development. March 4, Marks. Question 1 (10) Question 2 (10) Question 3 (10) Question 4 (10) Question 5 (5)

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

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

9/1/2015. Chapter 2 Using Objects. Objects and Classes. Using Objects. Using Objects. Using Objects. Classes. Ch. 1/2 Lab Time

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Building Java Programs

C - Basic Introduction

4. Inputting data or messages to a function is called passing data to the function.

Full file at C How to Program, 6/e Multiple Choice Test Bank

CS16 Exam #1 7/17/ Minutes 100 Points total

BRANCHING if-else statements

Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

H192 Midterm 1 Review. Tom Zajdel

2. Numbers In, Numbers Out

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

Programming Logic and Design Seventh Edition Chapter 2 Elements of High-Quality Programs

Fundamentals of Programming

Topic 4 Expressions and variables

Chapter 2 THE STRUCTURE OF C LANGUAGE

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

Flow Chart. The diagrammatic representation shows a solution to a given problem.

Programming for Engineers Arrays

Additional Questions

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

COMP 202 Java in one week

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Programming and Data Structures

Introduction to C Final Review Chapters 1-6 & 13

Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE

Course Outline Introduction to C-Programming

3 The L oop Control Structure

6.096 Introduction to C++ January (IAP) 2009

CS 31: Intro to Systems C Programming. Kevin Webb Swarthmore College September 13, 2018

Lab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering

Week 2 Introduction to Computer and Algorithm (Part 2)

Should you know scanf and printf?

2. Numbers In, Numbers Out

Computer System and programming in C

بسم اهلل الرمحن الرحيم

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

EC 413 Computer Organization

Decision Making -Branching. Class Incharge: S. Sasirekha

CSE 142, Summer 2015

1/25/2018. ECE 220: Computer Systems & Programming. Write Output Using printf. Use Backslash to Include Special ASCII Characters

Control Structure: Selection

Programming for Engineers Iteration

QUIZ: What value is stored in a after this

Transcription:

Identify skills and personality traits of successful problem solving. Apply standard problem-solving techniques to aid in problem solving. Apply problem-solving techniques to programming activities. Generate potential solutions to problems. Formulate and successfully communicate the solutions to problems.

10%: Homework and labs 30%: 2 quizzes and one exam 20%: 2 quizzes and one exam 40%: Final exam

Types of Problems Problem Solving Steps Problem Solving Strategies Algorithm Design Techniques Review Flowcharts Review C Language Basics (variables, data types, expressions, I/O, etc.). Decisions (if statement and switch statement)

Problems with Algorithmic Solutions Problems that can be solved with a series of actions Balancing checkbook, baking a cake Alphabetizing 10,000 names Problems with Heuristic Solutions Problem solution requiring reasoning based on knowledge and experience, and a process of trial and error Solutions cannot be reached through a direct set of steps How to buy the best stock or expand the company Difficult to evaluate the solution

People are better at solving heuristic problems Artificial intelligence is the field of computer science that deals with heuristic problems Computers are better at solving complicated calculus problems or alphabetizing 10,000 names This class deals with algorithmic solutions

Identify or Define the problem Analyze the problem (inputs, outputs, formulas, constants) Design the Solution (flowchart, algorithm, pseudo-code) Identify alternative ways to solve the problem Select the best way to solve the problem from the list of alternative solutions List instructions that enable you to solve the problem using selected solution Implement (program code) Evaluate

1. Problem: Your boss wants you to convert a list of miles to kilometers. Since you like programming, so you decide to write a program to do the job. 2. Analysis We need to get miles as input We need to output kilometers We know 1 mile = 1.609 kilometers 3. Design 1. Get distance in miles 2. Convert to kilometers 3. Display kilometers 9

10

Abstraction Brainstorming Divide and conquer Trial-and-error We need to THINK!

We need to read it till we understand every detail We need to dissect the problem into its component parts (e.g. problems and sub-problems) We need to remove any ambiguity, extra information We need to determine our knowns and our unknowns We need to be aware of any assumptions we are making.

A car has a fuel capacity of 12 gallons and a fuel consumption of 45 miles per gallon. Gas costs 2.56 a gallon. How far can the car travel on 16.64 worth of petrol?). What are the knowns and the unknowns? Where, if anywhere, is there ambiguity? What are the component parts of the problem? What information is extraneous to the problem solution? What assumptions have you made about the problem?

Brute-Force: Try all possibilities Divide and Conquer: Requires a way of breaking the problem into sub-problems, of solving the trivial cases and of combining sub-problems to the original problem (Merge Sort). Sub-problems are independent. Greedy: Find the local optimal step at each stage. Not necessarily globally optimal. Traveling salesman problem.

Function Header Function Body 24

An identifier must consist only of letters, digits, and underscores. An identifier cannot begin with a digit. A C reserved word cannot be used as an identifier. A standard identifier should not be redefined. C compilers are case sensitive. (Rate, rate and RATE are viewed as different identifiers) Valid identifiers: letter1, inches, KM_PER_MILE Invalid identifiers: 1letter, Happy*trout,return 2 5

26

SYNTAX printf( format string, print list ) ; Printf(format string); Examples : Place holder printf( That equals %f kilometers. \n, kms); printf( enter the distance in miles> ); printf( Hello, World?\n ); Escape sequence 27

28

SYNTAX scanf( format string, input list ) ; Examples : Place holder scanf( %lf, &miles); Ampersand 29

30

Write a program to ask the user for the width and length of a piece of land and then tell him how many orange trees he can grow on it. Given that each orange tree requires 4 m 2. 31

Programming Examples #include <stdio.h> # define one_tree_space 4 int main() { int length,width, area, no_of_tree; printf( Enter length of the land> ); scanf( %d, &length); printf( Enter width of the land> ); scanf( %d, &width); area = length * width; no_of_tree = area / one_tree_space; printf( The available number of trees is %d trees\n, no_of_tree); return(0); } 32

the result of the division operator depends on the type of its operands if one or both operands has a floating point type, the result is a floating point type. Otherwise, the result is an integer type Examples 11 / 4 has value 2 11.0 / 4.0 11 / 4.0 has value has value 2.75 2.75 15 / 3 has value 5 16 / 3 has value 5 33

the modulus operator % can only be used with integer type operands and always has an integer type result its result is the integer type remainder of an integer division EXAMPLE 3 % 5 = 3 5 % 3 = 2 4 % 5 = 4 5 % 4 = 1 5 % 5 = 0 6 % 5 = 1 7 % 5 = 2 8 % 5 = 3 15 % 6 = 3 15 % 5 = 0 34

Most conditions that we use to perform comparisons will have one of these forms: variable relational-operator variable e.g. a < b variable relational-operator constant e.g. a > 3 variable equality-operator variable e.g. a = = b variable equality-operator constant e.g. a!= 10 35

Operator Meaning Type < less than relational > greater than relational <= less than or equal to relational >= greater than or equal to relational == equal to equality!= not equal to equality 36

logical expressions - expressions that use conditional statements and logical operators. && (and) A && B is true if and only if both A and B are true (or) A B is true if either A or B are true! (not)!(condition) is true if condition is false, and false if condition is true This is called the logical complement or negation Example (salary < 1000) (dependents > 5) (temperature > 30.0) && (humidity > 90)!(temperature > 90.0) 37

if ( Expression ) StatementA else StatementB NOTE: StatementA and StatementB each can be a single statement, a null statement, or a block. 3 8

Write a program to calculate the total price of a certain purchase. There is a discount and shipping cost: The discount rate is 25% and the shipping is 10.00 if purchase is over 100.00. Otherwise, The discount rate is 15% and the shipping is 5.00 pounds. 3 9

if ( purchase > 100.00 ) { discountrate =.25 ; shipcost = 10.00 ; } else { discountrate =.15 ; shipcost = 5.00 ; } totalbill = purchase * (1.0 - discountrate) + shipcost ;

Used to select one of several alternatives BASED on the value of a single variable. This variable may be an int or a char but NOT a float ( or double). 4 1

char grade ; printf( Enter your letter grade: ); scanf( %c, &grade); switch ( grade ) { case A : printf( Excellent Job ); break; case B : printf ( Very Good ); break; case C : printf( Not bad ); break; case F : printf( Failing ); break; default : printf( Wrong Input ); } 4 2

Write a program to ask the user for the brightness of a light bulb (in Watts), and print out the expected lifetime: Brightness Lifetime in hours 25 2500 40, 60 1000 75, 100 750 otherwise 0

int bright ; printf( Enter the bulb brightness: ); scanf( %d, &bright); switch ( bright ) { case 25 : printf( Expected Lifetime is 2500 hours ); break; case 40 : case 60 : printf ( Expected Lifetime is 1000 hours ); break; case 75 : case 100 : printf( Expected Lifetime is 750 hours ); break; default : printf( Wrong Input ); }