CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?

Slides:



Advertisements
Similar presentations
Chapter 2 - Problem Solving
Advertisements

Chapter 2 - Problem Solving
Overview Reference parameters Documenting functions A game of craps. Design, code, test and document.
This set of slides is provided by the author of the textbook1 Introductory Topics (Continued) l Computer Components l Basic Control Structures l Problem.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Computer Science 1620 Loops.
Conditional Operator (?:) Conditional operator (?:) takes three arguments (ternary) Syntax for using the conditional operator:
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
Overview creating your own functions calling your own functions.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Computer Science 1620 Programming & Problem Solving.
Copyright © 2003 Pearson Education, Inc. Slide 1.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
Software Engineering 1 (Chap. 1) Object-Centered Design.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
CSC 107 – Programming For Science. Announcements  Tutors available MTWR in WTC206/WTC208  Special lab (with Macs) & not in the Tutoring Center  Can.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
CSC 107 – Programming For Science. Today’s Goal  Discuss writing & using functions  How to declare them, use them, & trace them  Could write programs.
CSC 107 – Programming For Science. Spacing in a Program  C++ ignores spaces in a program  This also means where newlines placed ignored  #define &
Selection Structures (if & switch statements) (CS1123)
Problem of the Day  Why are manhole covers round?
CSC 107 – Programming For Science. Science Means Solving Problems  Physics -- How does an atom work?
Overview of Programming and Problem Solving Textbook Chapter 1 1.
CSC Programming for Science Lecture 16: Debugging.
Problem of the Day  Why are manhole covers round?
Current Assignments Homework 3 is due tonight. Iteration and basic functions. Exam 1 on Monday.
CSE1222: Lecture 3The Ohio State University1. Assignment Operations  The C++ assignment operator is: =  Examples: x = 3 * 5; y = x – 7; y = y + 4; Do.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Question of the Day  A landscaper plants 5 rows of 4 trees each, but only uses 10 trees. How is this possible?
Previously Repetition Structures While, Do-While, For.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
CSC 107 – Programming For Science. The Week’s Goal.
1 ELEC 206 Chapter 3 Control Structures 5-Step Problem Solving Methodology 1. State the problem clearly. 2. Describe the input and output. 3. Work a.
Generic Types  Recent release of Java added generics  Include type parameters in class definition  Like methods, parameters can change each time 
CSC 107 – Programming For Science. Today’s Goal  Become familiar with simple arrays  Declaring an array variable  Assigning data to array entries 
Control of flow We learned that default flow of instructions is sequential. Then, we learned how to control the flow using "if" and "switch." Now, we will.
1 CS161 Introduction to Computer Science Topic #8.
Structured Programming (4 Credits) HNDIT Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial,
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
Problem of the Day How can you make 16 right angles using 4 matchsticks WITHOUT breaking any of them?
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
CSC 107 – Programming For Science. Today’s Goal  Know how to write selections besides if-else  When each of the options makes sense  When each selection.
The Hashemite University Computer Engineering Department
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
PHY 107 – Programming For Science. Announcements  No week #5 weekly assignment  Take time to study for Friday’s midterm instead  No lab or office hours.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
PHY 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Fundamental Programming Fundamental Programming Data Processing and Expressions.
Software Engineering Algorithms, Compilers, & Lifecycle.
CSC 107 – Programming For Science. Today’s Goal  Write functions that take & return values  How parameters declared and how we call functions  What.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
Basic concepts of C++ Presented by Prof. Satyajit De
Introduction to Computer Programming
Engineering Problem Solving with C++, Etter/Ingber
Chapter 2.1 Control Structures (Selection)
CSC113: Computer Programming (Theory = 03, Lab = 01)
CSCI 161: Introduction to Programming
Compound Assignment Operators in C++
TIPS: How to Be Successful
The switch Statement When we want to compare a variable against several values to see which one it has, we can use the switch statement: switch (status)
Presentation transcript:

CSC 107 – Programming For Science

Science Means Solving Problems  Physics – How does an atom work?

Science Means Solving Problems  Physics – How does an atom work?  Engineering – Will the bridge hold?

Science Means Solving Problems  Physics – How does an atom work?  Engineering – Will the bridge hold?  Biology – What is crawling up my leg?

Science Means Solving Problems

Solving Problems With Code  Simple trick to this issue: good programs work  Everything else is secondary and much less important  Must have focus on creating working solution

Solving Problems With Code good programs work  Simple trick to this issue: good programs work  Everything else is secondary and much less important  Must have focus on creating working solution

Solving Problems With Code

Problem Solving Method 1. Clearly define the problem Will splitting an atom cause unstoppable explosion? Must translate series of digits into number, how? What bet in Vegas gives me best odds of winning?  What are winning numbers in tonight's lottery?  Am I pretty enough to become Miss America?

Problem Solving Method 2. Describe input and output information Input: U 235 Output: Input: Degree of angle Output: Angle's cosine Input: Car design Output: Fuel efficiency Input: Models of monster Output: Hair movement

Problem Solving Method 3. Develop algorithm or flowchart of solution before Check algorithms before sitting down to code Better be careful, double-check algorithms work Triple-check algorithms work just to be certain Do this by following example of Manhattan Project

Problem Solving Method 3. Develop algorithm or flowchart of solution before Check algorithms before sitting down to code Better be careful, double-check algorithms work Triple-check algorithms work just to be certain Do this by following example of Manhattan Project

Brian Kernighan, Creator of C

Tracing a Solution  Flowchart or pseudocode “run” like computer  Can use any inputs you want – choose range of values  Double-check that its results match expectations  Tracing simplifies development by ignoring stuff  Only flowchart or pseudocode; syntax unimportant  Adds variables anytime & without using a type  Record values during run to enable fixing bugs  Eventually match run to trace to discover error

Starting a Memory Trace  Paper holds 3 areas separated by vertical lines  Program stack drawn on left part of page  Right side of page holds the program heap  Program output shown outside the stack & heap  Draw frame in stack labeled main to show start  Fancy name for box labeled with method name  Each variable & its value shown inside this box

Tracing if - else Statement #include using namespace std; int main() { int dcScore = 22, stlScore = 21; if (dcScore > stlScore) { cout << "Prof. Hertz happy" << endl; cout << "His team won" << endl; } else { cout << "His team lost." << endl; cout << "He gives out Fs"; dcScore += 100; if (dcScore < stlScore) { cout << "Ouch. That's Buffalo bad." <<endl; } } cout << "And now code continues" << endl; return 0; }

Tracing switch Statement float temp = -40; float convert; char c; cin >> c; switch (toupper(c)) { case ‘K’: temp = temp – ; case ‘C’: convert = ((temp / 5) * 9) + 32; break; case ‘F’: convert = ((temp - 32) / 9) * 5; break; default: cout << “Amoronsayswhat?” << endl; } cout <<“Converted temp: ” << convert << endl;

Problem Solving Method 4. Rewrite flowchart as comments in code in file 5. Write code solving first part of problem Test just this code to be certain free from bugs Frequently testing gives bugs fewer places to hide Bug MUST be in code – already tested algorithm! Debugging simple – look for mismatch w/flowchart 6. Once first part done, write second part of code Focus on reducing bugs to make process easier Grow by continue building slowly upon tested code

Your Turn  Get in groups & work on following activity

For Midterm  You can use on this midterm:  Always use your textbook & notes IF  Printout of slides IF has notes on that day's slides  At the same time, you may NOT use:  Computer, calculator, cell phone, or similar  Printed copies of daily activities and/or solutions  Friends, Romans, countrymen or their ears  To be certain rules are followed, when test ends  All printed material submission may be requested

How to Prepare for Midterm DODON'T  Make cheat sheets for the test  Converting to & from decimal  Add post-its to important pages  Review what parts of C++ do  Assume notes replace studying  Waste time memorizing  Drink case of 40s before test  Use post-its as clothing