SlideShare uma empresa Scribd logo
1 de 44
Lecture 1- Introduction and Review
 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.
 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
8
9
 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.
 Brute-force
 Divide and Conquer
 Greedy
 Brute-Force:
◦ Try all possibilities
 Divide and Conquer:
1. Divide: Break the given problem into sub problems
of same type.
2. Conquer: Recursively solve these sub problems
3. Combine: Appropriately combine the answers
Merge Sort is also a sorting algorithm. The algorithm
divides the array in two halves, recursively sorts them and
finally merges the two sorted halves.
 Greedy:
◦ Find the local optimal step at each stage.
◦ Not necessarily globally optimal.
◦ Example:
◦ With a goal of reaching the largest-sum, at each step, the
greedy algorithm will choose what appears to be the optimal
immediate choice, so it will choose 12 instead of 3 at the
second step, and will not reach the best solution, which
contains 99.
23
Function Header
Function Body
◦ 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
4
25
SYNTAX
Examples :
26
printf( format string , print list ) ;
Printf(format string);
printf("That equals %f kilometers. n", kms);
printf("enter the distance in miles> ");
printf( "Hello, World?n");
Place holder
Escape sequence
27
SYNTAX
Examples :
28
scanf( format string , input list ) ;
scanf("%lf", &miles);
Place holder
Ampersand
29
 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 m2.
30
#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
treesn", no_of_tree);
return(0);
}
31
Programming Examples
• 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 has value 2.75
11 / 4.0 has value 2.75
15 / 3 has value 5
16 / 3 has value 5
32
• 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
33
 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
34
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
35
 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)
36
if ( Expression )
StatementA
else
StatementB
NOTE: StatementA and StatementB each
can be a single statement, a null
statement, or a block.
3
7
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
8
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
0
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
1
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 ");
}
Lecture 01 - Introduction and Review.ppt

Mais conteúdo relacionado

Semelhante a Lecture 01 - Introduction and Review.ppt

Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2Dhiviya Rose
 
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...ronistgdr
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
c++ computer programming language datatypes ,operators,Lecture 03 04
c++ computer programming language datatypes ,operators,Lecture 03 04c++ computer programming language datatypes ,operators,Lecture 03 04
c++ computer programming language datatypes ,operators,Lecture 03 04jabirMemon
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageDr.Florence Dayana
 
Cse115 lecture03problemsolving
Cse115 lecture03problemsolvingCse115 lecture03problemsolving
Cse115 lecture03problemsolvingMd. Ashikur Rahman
 
Application of Machine Learning in Agriculture
Application of Machine  Learning in AgricultureApplication of Machine  Learning in Agriculture
Application of Machine Learning in AgricultureAman Vasisht
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators pptViraj Shah
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001Ralph Weber
 
Fundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptxFundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptxEyasu46
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchartSachin Goyani
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsTech
 

Semelhante a Lecture 01 - Introduction and Review.ppt (20)

3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
c-programming
c-programmingc-programming
c-programming
 
Control All
Control AllControl All
Control All
 
Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2
 
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
 
C++ for beginners
C++ for beginnersC++ for beginners
C++ for beginners
 
C programming language
C programming languageC programming language
C programming language
 
C Language Part 1
C Language Part 1C Language Part 1
C Language Part 1
 
c++ computer programming language datatypes ,operators,Lecture 03 04
c++ computer programming language datatypes ,operators,Lecture 03 04c++ computer programming language datatypes ,operators,Lecture 03 04
c++ computer programming language datatypes ,operators,Lecture 03 04
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 
Cse115 lecture03problemsolving
Cse115 lecture03problemsolvingCse115 lecture03problemsolving
Cse115 lecture03problemsolving
 
Application of Machine Learning in Agriculture
Application of Machine  Learning in AgricultureApplication of Machine  Learning in Agriculture
Application of Machine Learning in Agriculture
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators ppt
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
Fundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptxFundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptx
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
C program
C programC program
C program
 
Introduction
IntroductionIntroduction
Introduction
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 

Mais de MaiGaafar

Modeling&Simulation_Ch01_lecture 2.pptx
Modeling&Simulation_Ch01_lecture 2.pptxModeling&Simulation_Ch01_lecture 2.pptx
Modeling&Simulation_Ch01_lecture 2.pptxMaiGaafar
 
Introduction to Time Series Analysis.pptx
Introduction to Time Series Analysis.pptxIntroduction to Time Series Analysis.pptx
Introduction to Time Series Analysis.pptxMaiGaafar
 
Modeling_Simulation_ch3_lecture_1.pptx
Modeling_Simulation_ch3_lecture_1.pptxModeling_Simulation_ch3_lecture_1.pptx
Modeling_Simulation_ch3_lecture_1.pptxMaiGaafar
 
strategic-planning_chp (1).pptx
strategic-planning_chp (1).pptxstrategic-planning_chp (1).pptx
strategic-planning_chp (1).pptxMaiGaafar
 
BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx
BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptxBU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx
BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptxMaiGaafar
 
HU200-Introduction-2020-2021.pptx
HU200-Introduction-2020-2021.pptxHU200-Introduction-2020-2021.pptx
HU200-Introduction-2020-2021.pptxMaiGaafar
 
sm-161216124538.pptx
sm-161216124538.pptxsm-161216124538.pptx
sm-161216124538.pptxMaiGaafar
 
Modeling&Simulation_Ch01_part 3.pptx
Modeling&Simulation_Ch01_part 3.pptxModeling&Simulation_Ch01_part 3.pptx
Modeling&Simulation_Ch01_part 3.pptxMaiGaafar
 
HU200-Supply-modified2020.pptx
HU200-Supply-modified2020.pptxHU200-Supply-modified2020.pptx
HU200-Supply-modified2020.pptxMaiGaafar
 
BU_FCAI_SCC430_Modeling&Simulation_Ch03.pdf
BU_FCAI_SCC430_Modeling&Simulation_Ch03.pdfBU_FCAI_SCC430_Modeling&Simulation_Ch03.pdf
BU_FCAI_SCC430_Modeling&Simulation_Ch03.pdfMaiGaafar
 
BU_FCAI_SCC430_Modeling&Simulation_Ch06.pptx
BU_FCAI_SCC430_Modeling&Simulation_Ch06.pptxBU_FCAI_SCC430_Modeling&Simulation_Ch06.pptx
BU_FCAI_SCC430_Modeling&Simulation_Ch06.pptxMaiGaafar
 
Modeling&Simulation_Ch04 (1). part 2pptx.pptx
Modeling&Simulation_Ch04 (1). part 2pptx.pptxModeling&Simulation_Ch04 (1). part 2pptx.pptx
Modeling&Simulation_Ch04 (1). part 2pptx.pptxMaiGaafar
 

Mais de MaiGaafar (12)

Modeling&Simulation_Ch01_lecture 2.pptx
Modeling&Simulation_Ch01_lecture 2.pptxModeling&Simulation_Ch01_lecture 2.pptx
Modeling&Simulation_Ch01_lecture 2.pptx
 
Introduction to Time Series Analysis.pptx
Introduction to Time Series Analysis.pptxIntroduction to Time Series Analysis.pptx
Introduction to Time Series Analysis.pptx
 
Modeling_Simulation_ch3_lecture_1.pptx
Modeling_Simulation_ch3_lecture_1.pptxModeling_Simulation_ch3_lecture_1.pptx
Modeling_Simulation_ch3_lecture_1.pptx
 
strategic-planning_chp (1).pptx
strategic-planning_chp (1).pptxstrategic-planning_chp (1).pptx
strategic-planning_chp (1).pptx
 
BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx
BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptxBU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx
BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx
 
HU200-Introduction-2020-2021.pptx
HU200-Introduction-2020-2021.pptxHU200-Introduction-2020-2021.pptx
HU200-Introduction-2020-2021.pptx
 
sm-161216124538.pptx
sm-161216124538.pptxsm-161216124538.pptx
sm-161216124538.pptx
 
Modeling&Simulation_Ch01_part 3.pptx
Modeling&Simulation_Ch01_part 3.pptxModeling&Simulation_Ch01_part 3.pptx
Modeling&Simulation_Ch01_part 3.pptx
 
HU200-Supply-modified2020.pptx
HU200-Supply-modified2020.pptxHU200-Supply-modified2020.pptx
HU200-Supply-modified2020.pptx
 
BU_FCAI_SCC430_Modeling&Simulation_Ch03.pdf
BU_FCAI_SCC430_Modeling&Simulation_Ch03.pdfBU_FCAI_SCC430_Modeling&Simulation_Ch03.pdf
BU_FCAI_SCC430_Modeling&Simulation_Ch03.pdf
 
BU_FCAI_SCC430_Modeling&Simulation_Ch06.pptx
BU_FCAI_SCC430_Modeling&Simulation_Ch06.pptxBU_FCAI_SCC430_Modeling&Simulation_Ch06.pptx
BU_FCAI_SCC430_Modeling&Simulation_Ch06.pptx
 
Modeling&Simulation_Ch04 (1). part 2pptx.pptx
Modeling&Simulation_Ch04 (1). part 2pptx.pptxModeling&Simulation_Ch04 (1). part 2pptx.pptx
Modeling&Simulation_Ch04 (1). part 2pptx.pptx
 

Último

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 

Último (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

Lecture 01 - Introduction and Review.ppt

  • 2.  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.
  • 3.  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)
  • 4.  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
  • 5.  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
  • 6.  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
  • 7.
  • 8. 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 8
  • 9. 9
  • 10.  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.
  • 11.
  • 12.
  • 13.  Brute-force  Divide and Conquer  Greedy
  • 14.  Brute-Force: ◦ Try all possibilities  Divide and Conquer: 1. Divide: Break the given problem into sub problems of same type. 2. Conquer: Recursively solve these sub problems 3. Combine: Appropriately combine the answers Merge Sort is also a sorting algorithm. The algorithm divides the array in two halves, recursively sorts them and finally merges the two sorted halves.
  • 15.  Greedy: ◦ Find the local optimal step at each stage. ◦ Not necessarily globally optimal. ◦ Example: ◦ With a goal of reaching the largest-sum, at each step, the greedy algorithm will choose what appears to be the optimal immediate choice, so it will choose 12 instead of 3 at the second step, and will not reach the best solution, which contains 99.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 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 4
  • 25. 25
  • 26. SYNTAX Examples : 26 printf( format string , print list ) ; Printf(format string); printf("That equals %f kilometers. n", kms); printf("enter the distance in miles> "); printf( "Hello, World?n"); Place holder Escape sequence
  • 27. 27
  • 28. SYNTAX Examples : 28 scanf( format string , input list ) ; scanf("%lf", &miles); Place holder Ampersand
  • 29. 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 m2. 30
  • 31. #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 treesn", no_of_tree); return(0); } 31 Programming Examples
  • 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 has value 2.75 11 / 4.0 has value 2.75 15 / 3 has value 5 16 / 3 has value 5 32
  • 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 33
  • 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 34
  • 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 35
  • 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) 36
  • 37. if ( Expression ) StatementA else StatementB NOTE: StatementA and StatementB each can be a single statement, a null statement, or a block. 3 7
  • 38. 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 8
  • 39. if ( purchase > 100.00 ) { discountRate = .25 ; shipCost = 10.00 ; } else { discountRate = .15 ; shipCost = 5.00 ; } totalBill = purchase * (1.0 - discountRate) + shipCost ;
  • 40.  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 0
  • 41. 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 1
  • 42. 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
  • 43. 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 "); }