Download presentation
Presentation is loading. Please wait.
Published byCollin Hudson Modified over 9 years ago
1
CSC 107 – Programming For Science
2
Science Means Solving Problems Physics – How does an atom work?
3
Science Means Solving Problems Physics – How does an atom work? Engineering – Will the bridge hold?
4
Science Means Solving Problems Physics – How does an atom work? Engineering – Will the bridge hold? Biology – What is crawling up my leg?
5
Science Means Solving Problems
6
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
7
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
8
Solving Problems With Code
11
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?
12
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
13
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
14
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
15
Brian Kernighan, Creator of C
16
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
17
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
18
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; }
19
Tracing switch Statement float temp = -40; float convert; char c; cin >> c; switch (toupper(c)) { case ‘K’: temp = temp – 273.15; 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;
20
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
21
Your Turn Get in groups & work on following activity
22
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
23
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.