Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cs-142:old-examples [2016/07/22 14:42] (current)
kseppi created
Line 1: Line 1:
 += Dr. Seppi'​s Fall 2015 In-Class Examples =
  
 +These may not run as is, some are used just to make an isolated point in class. In some cases they may contain purposefully bad examples, as discussed in class. Since I edit examples in class, these may not contain everything you saw in class.
 +
 +* [[Hello]] - This is a very basic example of a c++ program
 +* [[Bulb]] - Compute power cost using floats
 +* [[Types and assignment]] - These are just isolated lines of code demonstrating the use of variables, ints and doubles
 +* [[More data types work]] - rounding, formatting and strings
 +* [[Input and ifs]] - thinking about conditional execution (if's)
 +* [[Earthquakes]] - Tell the user about earthquakes
 +* [[Tax example]] - tax example from book
 +* [[Checking cin fail]] - dealing with bad input, if's only
 +* [[Cylinder]] - Volume of a simple cylinder
 +* [[Triangle function]] - Print a triangle
 +* [[Guessing Numbers]] - Computer picks a number and the user has to guess what it is.
 +* [[99 bottles on milk]] - loops, and ifs, and functions, oh my!
 +* [[Allowance with menu]] - More loops and menus
 +* [[Cube functions]] - Some examples of functions
 +* [[Reference parameters]] - Some examples of the use of reference parameters
 +* [[Scope]] - A bad example of scope
 +* [[Just Palindromes]] - Palindromes
 +* [[Fibonacci]] - Variations on Fibonocci
 +* [[House functions]] - Functions
 +* [[Array fun]] - fun with arrays
 +* [[2d array fun]] - introduce 2d arrays
 +* [[2d arrays and files]] - file ouput
 +* [[Reading with string streams]] - Using string streams to read files
 +* [[Old school vectors]] - Old school vector manipulations
 +* [[New school vectors]] - c++11 vector manipulations
 +* [[Short unique words]] - find and print unique words
 +* [[Student vectors]] - Sets of vectors as a motivation for classes
 +* [[Simple students]] - The beginnings of a very simple students example
 +* [[Cars]] - a very simple, perhaps even stupid class example
 +* [[Accounts]] - a better example of objects
 +* [[Fun with pointers]] - Using pointers in various ways. No real application
 +* [[Inheritance]] - Small example of inheritance involving animals, [[Inheritance2]] more complete, with separate files, [[Inheritance3]]
 +* [[Sort]] - The sort example from the book
 +* [[Maps and sets]] - Maps and Sets and Multisets, oh my!
 +
 +For later:
 +
 +* [[Grades]] - a grade conversion example with interesting input checking
 +* [[Sound]] - fun with sound
 +
 += Paul Bodily'​s Spring 2015 In-Class Examples =
 +
 + ​examples are intended to supplement those in the text book, not replace them. Most examples have the problem stated atop the code. Note that a proper solution would begin with a flow chart, which is missing from most of these solutions. Footnotes specify principles illustrated by each example.
 +
 +== If, If/else, Switch Statements == 
 +* [[Adding a missing area code]]† - Use input length to decide if phone number has area code or needs one added
 +* [[Cougar Cash]]† - Charge an expense without letting the balance go below 0
 +* [[Cougar Cash with input validation and user confirmation]]*†§ - Same as [[Cougar Cash]] but better
 +* [[Hot Peppers]]‡ - Multiple if statement to pick a pepper hotter than a certain threshold
 +* [[BYU Health Insurance]]†§ - Determine health insurance premium based on marital status and dependents
 +
 +<​nowiki>​*</​nowiki>​ - if without else, † - if with else, ‡ - multiple if, § - nested if
 +
 +== Booleans, Boolean operators ==
 +
 +* [[BYU Health Insurance with booleans]]* - Upgrade on [[BYU Health Insurance]] which uses declares, defines, and uses a boolean variable.
 +* [[Gene Finding via GC content]]† - Determine if a DNA sequence is a gene based on the number of C's and G's.
 +* [[Gene Finding via TATA box search]]*‡§ - Determine if a DNA sequence is a gene based on finding a special subsequence.
 +
 +<​nowiki>​*</​nowiki>​ - uses booleans, † - uses boolean ''​or'',​ ‡ - uses boolean ''​not'',​ § - uses boolean ''​and''​
 +
 +== While, For, Do-While Loops, Input Validation ==
 +
 +* [[Guessing Numbers]]*‡§‖ - Computer picks a number and the user has to guess what it is.
 +* [[Gene Finding via GC content]]† - Determine if a DNA sequence is a gene based on the number of C's and G's.
 +* [[Gene Finding via TATA box search]]* - Determine if a DNA sequence is a gene based on finding a special subsequence.
 +* [[Printing Times Tables]]†§ - Prints a square times table matrix.
 +* [[Longest and shortest words in a list]]† - Given a list of words, find the longest and shortest.
 +* [[GoFundMe]]* - A program to track donations in order to reach a fundraising goal.
 +* [[NWS Rainfall]]†§ - Simulate and report summary data average daily rainfall in the state of Utah.
 +* [[Is this list sorted?]]* - Given a list, checks if it is sorted or unsorted
 +
 +<​nowiki>​*</​nowiki>​ - while loop, † - for loop, ‡ - do-while loop, § - nested loops, ‖ - cin.fail(),
 +
 +== Common Loop Algorithms == 
 +
 +* [[Longest and shortest words in a list]]‡§ - Given a list of words, find the longest and shortest.
 +* [[GoFundMe]]*†‡§ - A program to track donations in order to reach a fundraising goal.
 +* [[NWS Rainfall]]*†‡ - Simulate and report summary data average daily rainfall in the state of Utah.
 +* [[Is this list sorted?​]]§‖ - Given a list, checks if it is sorted or unsorted
 +
 +<​nowiki>​*</​nowiki>​ - summing, † - find average, ‡ - finding max/min, § - uses sentinel, ‖ - comparing adjacent numbers
 +
 +== Random numbers == 
 +
 +* [[Guessing Numbers]]* - Computer picks a number and the user has to guess what it is.
 +* [[Generating random doubles]]† - Demonstrates simply how to generate a random floating-point number between two bounds.
 +* [[GoFundMe]]† - A program to track donations in order to reach a fundraising goal.
 +* [[NWS Rainfall]]† - Simulate and report summary data average daily rainfall in the state of Utah.
 +
 +<​nowiki>​*</​nowiki>​ - random integers, † - random doubles
 +
 +== Functions == 
 +
 +* [[Find the max of three integers]] - Uses max() to find max of three ints
 +* [[Do you wanna build a snowman?​]]†‡§‖ - Calculate volume of snow needed to build snowballs, snowmen
 +* [[How much wood?​]]*†‡§‖ - Calculate the area of wood needed to construct certain 2D structures
 +
 +<​nowiki>​*</​nowiki>​ - functions within functions, ​
 +† - functions with separate declaration and definition,
 +‡ - function with void return type, 
 +§ - function with no parameters, ​
 +‖ - function reused in multiple places
 +
 +== Arrays == 
 +
 +* [[Weight on other planets]]†‡ - Calculates a weight on celestial spheres, allowing the user to choose to exclude Pluto
 +* [[BYU ACM Tournament Tracker]]†§‖ - Add, remove, edit, sort, and display names in a sorted list
 +* [[Tic Tac Toe]]*¶ - Fully functional Tic Tac Toe game
 +* [[Minesweeper]]*¶ - Simplified Minesweeper game
 +
 +All examples demonstrate arrays as function parameters
 +
 +<​nowiki>​*</​nowiki>​ - fill an array, ​
 +† - linear search of an array, ​
 +‡ - removing an element from a non-sorted list, 
 +§ - copy an array, ​
 +‖ - swapping elements and selection sort, 
 +¶ - 2d array
 +
 +== Vectors ==
 +
 +* [[Help queue]]*†‡¶ - A queue in which students can add their names or choose to help students on the queue
 +* [[Missionary Referral Manager]]*†‡§‖¶ - Add to, sort, import, and export a list of referral names
 +
 +<​nowiki>​*</​nowiki>​ - passing vector as reference parameter, ​
 +† - const reference parameter, ​
 +‡ - using getline,
 +§ - character functions, ​
 +‖ - read and write to/from a file, 
 +¶ - using cin.sync()
 +
 +== Recursion == 
 +
 +* [[Printing Pedigrees]] - prints a blank pedigree x generations deep
 +* [[Substrings and Palindromes]] - two examples of recursion to summarize properties of a string
 +
 +== Classes and Objects ==
 +
 +* [[Managing a movie collection]] - Build a Movie class, with a title, a duration, and a rating; then test it
 +* [[Facespace]] - Build a Comment class, with a comment, commenter name, and like count; then test it
 +
 +== Pointers ==
 +* [[Family Feud]] - use an int* to point to the team score to which we want to add scored points
 +* [[Super Smash Brothers]] - use Player* to point to which player is currently attacking and which is currently defending
 +* [[Airplane Seating and Checking]] - use vector and 2D array of Passenger* to view and edit passenger'​s seating and checked baggage information
 +
 +== Inheritance and Polymorphism ==
 +* [[Degree and Non-degree seeking students]]† - A student base class from which is derived a degree-seeking student
 +* [[Shapes]]*† - An abstract shape base class and two derived classes, Rectangle and Circle
 +
 +<​nowiki>​*</​nowiki>​ - pure virtual function/​abstract class, † - static class variable
 +
 += Dr. Seppi'​s Examples from Fall 2014 = 
 +
 +These may not run as is, some are used just to make an isolated point in class. In some cases they may contain purposefully bad examples, as discussed in class. Since I edit examples in class, these may not contain everything you saw in class.
 +
 +* [[Hello]] - This is a very basic example of a c++ program
 +* [[Bulb]] - Compute power cost using floats
 +* [[Types and assignment]] - These are just isolated lines of code demonstrating the use of variables, ints and doubles
 +* [[More data types work]] - rounding, formatting and strings
 +* [[Input and ifs]] - thinking about conditional execution (if's)
 +* [[Earthquakes]] - Tell the user about earthquakes
 +* [[Tax example]] - tax example from book
 +* [[Checking cin fail]] - dealing with bad input, if's only
 +* [[Cylinder]] - Volume of a simple cylinder
 +* [[Triangle function]] - Print a triangle
 +* [[99 bottles on milk]] - loops, and ifs, and functions, oh my!
 +* [[Allowance with menu]] - More loops and menus
 +* [[Cube functions]] - Some examples of functions
 +* [[Fibonacci]] - Variations on Fibonocci
 +* [[House functions]] - Functions
 +* [[Array fun]] - fun with arrays
 +* [[2d array fun]] - introduce 2d arrays
 +* [[2d arrays and files]] - file ouput
 +* [[Old school vectors]] - Old school vector manipulations
 +* [[New school vectors]] - c++11 vector manipulations
 +* [[Student vectors]] - Sets of vectors as a motivation for classes
 +* [[Simple students]] - The beginnings of a very simple students example
 +* [[Cars]] - a very simple, perhaps even stupid class example
 +* [[Accounts]] - a better example of objects
 +* [[Fun with pointers]] - Using pointers in various ways. No real application
 +* [[Inheritance]] - Small example of inheritance involving animals, [[Inheritance2]] more complete, with separate files, [[Inheritance3]]
 +* [[Sort]] - The sort example from the book
 +* [[Maps and sets]] - Maps and Sets and Multisets, oh my!
 +
 +For later:
 +
 +* [[Grades]] - a grade conversion example with interesting input checking
cs-142/old-examples.txt · Last modified: 2016/07/22 14:42 by kseppi
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0