1 / 38

Welcome to Programming Practicum

Welcome to Programming Practicum. Waiting for the snow enveloping you on Route 5 N to melt. “Putting the C into CS”. University of St. Petersburg. Engineering dept. On the 405, in traffic, being chased by police (and TV) helicopters. You aren’t here. writing clinic reports. Lecture.

layne
Download Presentation

Welcome to Programming Practicum

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Welcome to Programming Practicum Waiting for the snow enveloping you on Route 5 N to melt “Putting the C into CS” University of St. Petersburg Engineering dept. On the 405, in traffic, being chased by police (and TV) helicopters. You aren’t here writing clinic reports Lecture rebooting turing coding chunky strings reading requests clinic liaison phone call Mailing something at the Claremont Post Office the dumpster

  2. What is this course about? • A chance to “improve” your C/C++ …

  3. What is this course about? • A chance to “improve” your C/C++ … Unofficial course name: CS -70

  4. What is this course about? • A chance to “improve” your C/C++ … Unofficial course name: CS -70 Code commenting Using globals Building classes STL Memory Leaks

  5. What is this course about? • A chance to “improve” your C/C++ … CS 70 Unofficial course name: CS -70 Code commenting Using globals Building classes STL Memory Leaks

  6. What is this course about? • A chance to “improve” your C/C++ … CS 70 Unofficial course name: CS -70 Code commenting Using globals Building classes STL Memory Leaks • Problem Insight and Execution ... • Preparation for the ACM competition ...

  7. 2000 ACM Teams

  8. Organization a must! Solving problems in teams • 3 team members, more or less • 2 problems/week, more or less • submission through /cs/ACM/acmSubmit • class web page at www.cs.hmc.edu/ACM

  9. Grading P/F by default -- but it can be graded • 1.75 problems/week => A • 1.25 problems/week => B • 0.75 problems/week => C • 0.25 problems/week => D Coding Guidelines • share coding tasks within teams, not among them • discussion of algorithms always OK • start from scratch each time!

  10. Course Outline Sep 11 continental fare Sep 18 slim jims Sep 25 Pepperedge Farm Oct 2 Krispy Kreme Oct 9 Drake’s coffee cake Oct 16 baklava Oct 23 (fall break) Oct 30 HMCContest - 9:00 pm to 1:00 am ? Nov 6 popcorn Nov 10 (Sat) -- ACM Contest at Riverside Com. Col. Nov 13 Wrap-up and problem discussion

  11. ACM topics Topic Contest CS Standard Library (STL) Algorithms/data structures Overlearning the above Coding/Contest strategies

  12. ACM topics Topic Contest CS Standard Library (STL) Algorithms/data structures Overlearning the above Coding/Contest strategies

  13. ACM topics Topic Contest CS Standard Library (STL) Algorithms/data structures Overlearning the above Coding/Contest strategies

  14. ACM topics Topic Contest CS Standard Library (STL) Algorithms/data structures Overlearning the above Coding/Contest strategies

  15. Problems The “digital root” problem. (digroot.cc) starting... The “unscramble” problem. (unscramble.cc) sorting... The “echo” problem. (echo.cc) Input: Intergalactic IRC strings stdin hehelllloo spamanyspamone howstheweather

  16. Problems The “digital root” problem. (digroot.cc) starting... The “unscramble” problem. (unscramble.cc) sorting... The “echo” problem. (echo.cc) Input: Intergalactic IRC strings stdin hehelllloo spamanyspamone howstheweather An echo string with buffer size ten Not an echo string, but still consistent Not consistent with the theory Output: Status Report stdout

  17. Resources... http://www.sgi.com/tech/stl/ Both good overall references Online STL refs http://www.dinkumware.com/htm_cpl/index.html http://www.josuttis.com/libbook/ Example code Useful stuff for this week’s problems string t, s = “Hawaii 2002”; getline(cin,t); // suppose t is “Harvey Mudd” if (t > s) … // comparison (==, !=, …) t += ‘ ’ + ‘i’ + “n ” + s; // concatenation s = t.substr(7,4); // s is “Mudd” s[1]; // s[1] is ‘u’ s.length(); // returns 4 t.find(‘a’); // returns 1 (where ‘a’ is) t.find(‘a’,2); // returns 16 (starts at 2) // find returns a value of type string::size_type // if what is sought isn’t there, find returns string::npos string #include <string>

  18. Resources... typedef pair<string, string> PS; PS mypair = make_pair(“hello”,“world”); mypair.first; // these are public members mypair.second; struct MYLESS : public less< PS > { bool operator()(PS x,PS y) { return x.second < y.second; // etc. } }; MYLESS mybad; PS* psArray = new PS[1000]; // array of PS // putting mybad to work... sort( psArray, psArray+n ); // default sort sort( psArray, psArray+n, mybad ); pair #include <utility> function objects “less” #include <functional> sort #include <algorithm>

  19. Resources... typedef pair<string, string> PSS; PSS mypair = make_pair(“hello”,“world”); mypair.first; // these are public members mypair.second; vector<PSS> v; // typedefs ~ good v.reserve(10); // assure 10 spots v.push_back(mypair); // mypair -> last item v.back(); // returns mypair v.pop_back(); // removes last element v.size(); // # of elements v[i]; // ith element sort( v.begin(), v.end() ); // default sort sort( v.begin(), v.end(), mycompare ); pair #include <utility> vector #include <vector> sort #include <algorithm>

  20. Intro STL Data Structure The “split pea” problem (also see the webpage) The number of configurations the # of cups to follow the # of peas in each cup # of cups # of peas ... 2 5 1 3 0 3 0 3 7 0 7 Input: stdin input 3 2 Output: The # of transitions from a root configuration to the given one. stdout output shaken or stirred?

  21. Intro Problem The “NAND” problem (also see the webpage) file to create: nand.cc NAND Problem x y x|y 0 0 1 0 1 1 1 0 1 1 1 0 NAND gates can specify any logical function. Consider two N-bit binary numbers, A and B. There is a logical function mapping A and B to the overflow bit of their sum. A = 10 B = 11 A+B = 101 the overflow bit -- it’s a function of the input bits

  22. Intro Problem The “NAND” problem (also see the webpage) file to create: nand.cc Problem: NAND gates can specify any logical function. Consider two N-bit binary numbers, A and B. There is a logical function mapping A and B to the overflow bit of their sum. 1 10 10 20 Input: Lines with two integers > 0. Same lines, plus the max # of steps to get to 1 in the given range. 1 10 20 10 20 21 Output:

  23. Topics Outline Sep 5 Basic coding strategies (ACM style) Sep 12 Dynamic programming ’n’ data structures Sep 19 Search algorithms ’n’ data structures Sep 26 Numerical algorithms: DEs, equations Oct 3 I/O in C/C++ = building parsers quickly Oct 10 Built-in string functions: strcmp, strtok, and the like Oct 24 Built-in math functions: atan vs. atan2, precision issues, ... Oct 31 Geometric algorithms ‘n’ data structures Nov 7 Contest strategies, logistics, preparing materials

  24. What is this course about? A chance to “improve” your C/C++ … prog practice Preparation for the ACM competition ... Problem Insight and Execution ... 2 1 Anxiety! Get into the minds of the judges

  25. Get into the minds of the judges Key Skill #1: mindreading

  26. Key Skill #2: anxiety Anxiety!

  27. What, no contest!? We will have a mock contest at the end of the term. • tentatively Tuesday, April 17 • four hours (from 4:15 to 8:15) • contest conditions will apply • dinner will be provided... This will be the final class session except we’ll stretch team size to 1-4 people... - only written material can be used - only one machine per team - (we will have a chair for each team member) - minimal feeback from submissions - time penalties for incorrect submssions

  28. Data Structures Sep 11 make_pair string Sep 18 map, multimap, set, multiset Sep 25 vector, deque, list Oct 2 bitset, stack, ... Oct 9 algorithms I Oct 16 algorithms II Oct 23 (fall break) Oct 30 HMCContest - 9:00 pm to 1:00 am ? Nov 6 I/O tips Nov 10 (Sat) -- ACM Contest at Riverside Com. Col. Nov 13 Wrap-up and problem discussion

  29. printed version after this one

  30. Welcome to Programming Practicum Waiting for the snow enveloping you on Route 5 N to melt “Putting the C into CS” University of St. Petersburg Engineering dept. On the 405, in traffic, being chased by police (and TV) helicopters. You aren’t here writing clinic reports Lecture rebooting turing coding chunky strings reading requests clinic liaison phone call Mailing something at the Claremont Post Office the dumpster

  31. What is this course about? • A chance to “improve” your C/C++ … • Problem Insight and Execution ... • Preparation for the ACM competition ... Solving problems in teams • 3 team members, more or less • 2 problems/week, more or less • submission through /cs/ACM/acmSubmit • class web page at www.cs.hmc.edu/ACM

  32. Grading P/F by default -- but it can be graded • 1.75 problems/week => A • 1.25 problems/week => B • 0.75 problems/week => C • 0.25 problems/week => D Coding Guidelines • share coding tasks within teams, not among them • discussion of algorithms always OK • start from scratch each time!

  33. ACM topics Topic Contest CS Standard Library (STL) Algorithms/data structures Overlearning the above Coding/Contest strategies

  34. “Problems” The “digital root” problem. (digroot.cc) starting... The “unscramble” problem. (unscramble.cc) sorting... The “echo” problem. (echo.cc) Input: Intergalactic IRC strings stdin hehelllloo spamanyspamone howstheweather

  35. “Problems” The “digital root” problem. (digroot.cc) starting... The “unscramble” problem. (unscramble.cc) sorting... The “echo” problem. (echo.cc) Input: Intergalactic IRC strings stdin hehelllloo spamanyspamone howstheweather An echo string with buffer size ten Not an echo string, but still consistent Not consistent with the theory Output: Status Report stdout

  36. Resources... http://www.sgi.com/tech/stl/ Both good overall references Online STL refs http://www.dinkumware.com/htm_cpl/index.html http://www.josuttis.com/libbook/ Example code Useful stuff for this week’s problems string t, s = “Hawaii 2002”; getline(cin,t); // suppose t is “Harvey Mudd” if (t > s) … // comparison (==, !=, …) t += ‘ ’ + ‘i’ + “n ” + s; // concatenation s = t.substr(7,4); // s is “Mudd” s[1]; // s[1] is ‘u’ s.length(); // returns 4 t.find(‘a’); // returns 1 (where ‘a’ is) t.find(‘a’,2); // returns 16 (starts at 2) // find returns a value of type string::size_type // if what is sought isn’t there, find returns string::npos string #include <string>

  37. Resources... typedef pair<string, string> PS; PS mypair = make_pair(“hello”,“world”); mypair.first; // these are public members mypair.second; struct MYLESS : public less< PS > { bool operator()(PS x,PS y) { return x.second < y.second; // etc. } }; MYLESS mybad; PS* psArray = new PS[1000]; // array of PS // putting mybad to work... sort( psArray, psArray+n ); // default sort sort( psArray, psArray+n, mybad ); pair #include <utility> function objects “less” #include <functional> sort #include <algorithm>

More Related