CSC111A Week of February 15th Notes
CSC111A Week of February 15th Notes CSC 111A
Popular in Intro CS-Genl Purpose Java
Popular in ComputerScienence
This 3 page Class Notes was uploaded by Amanda Howard on Thursday February 18, 2016. The Class Notes belongs to CSC 111A at Wake Forest University taught by Prof Daniel A. Canas in Winter 2016. Since its upload, it has received 29 views. For similar materials see Intro CS-Genl Purpose Java in ComputerScienence at Wake Forest University.
Reviews for CSC111A Week of February 15th Notes
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/18/16
FEBRUARY 16, 2016 NO CLASS FEBRUARY 18, 2016 Conditional Expression Shorthand for if statements Variable=(condition) ? expWhenTrue : expWhenFalse Basically if the condition is met then the first exp is printed, if not than the second is printed Example: o If the grade is greater than 70 the program will print “Passed” o If the grade is less than 70 the program will print “Failed” Double/Float Comparison Doubles and floats are not exact, for example: Expected (or entered) value Actual (how it is actually stored) 0.7 0.699999999999999999994512575 0.3 0.29999999999999999999974578 0.0 0.000000000000000000000555123 This inaccuracy is due to the fact that these decimals cannot be correctly represented in binary by the computer This makes it difficult to have an if statement with the condition being that a float or double is equal to 0.0 o To fix this take the absolute value of the double minus 0.0 and then ask if it is less than . 001 o Basically you’re asking if the difference between the variable and the number you want is less than .001, instead of asking if they’re the same because they won’t be Loops Repeats a series of instructions For example: when grades are calculated the instructions might be to average grades and those instructions would be continued until there are no more grades Loops use while statements to execute their instructions Example: o In this case adding 1 to the counter each time a grade is entered allows the program to keep track of the number of grades in the system until the desired number is reached o The program will continue to loop back and continue adding grades to the total until it has all the grades, or until counter=5 this case o Here would be an example of the finished program to calculate your final grade o Variations on this are possible, for example: numberOfGrades can be made a scanner that will read the number of grades inputted by the user
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'