9/3 Monday, September 1, 2014 5:43 PM Don't vandalize the classroom csc104ma Page 1 9/8 Monday, September 08, 2014 1:53 PM Quiz: What sentence was tweeted to #shercsc104 (also announced on blackboard Computers can be fun! Life is fun Fun starts with F F is the first letter in firefighters Firefighters are awesome Flying is awesome Computer science is awesome Its awesome when planes fly by I hate going by the swamp Swamps are nasty Your nasty shoes are in the way Sometimes in traffic people get in the way I was going down the highway and I realized I was going the wrong way Way to go Vinnie Vinnie is a name! His name was unknown. This is unknown territory This is mustang territory In my territory I reign king HW Write instructions to go to NCC from home If you are adventurous try to follow them tommorow and see if you actually ge tto school Read Day 3 notes on handout page 8. csc104ma Page 2 9/10 Wednesday, September 10, 2014 2:06 PM Write instructions for writing your initials. You must describe all the lines and curves. You can not say what letters. From <https://twitter.com/search?q=%23shercsc104&src=typd> • From the top left corner draw a downward stroke of length 1 inch • Draw a 1/2 inch wide arc to the right of the stroke, starting at the top and ending on the bottom • From the top and 1.5 inches to right draw a left facing arc of width .5 inch and height .5 inch • From the bottom of the arc just drawn, draw a right facing arc .5 inch wide downward .5 inch Project 1 due (to be emailed by): 9/20 Email to: [email protected] and [email protected] csc104ma Page 3 Bill, Ken, and Mark are, not necessarily in this order, a kicker, a receiver, and a quarterback. The kicker, who is the shortest of the three, has never been married. Bill, who is Ken's father-inlaw, is taller than the receiver. Who plays in which position? From <http://matcmp.ncc.edu/sherd/classdoc/csc104/notes.htm> Matrix logic problem. . Bill Kicker X Receiver X quarterback O Ken Mark X O X O X X Ted, Ken, Allyson and Janie (two married couples) each have a favorite sport: running, swimming, biking and golf. Given the following clues, determine who likes which sport. 1. Ted hates golf. 2. Ken wouldn’t run around the block if he didn’t have to, and neither would his wife. csc104ma Page 4 neither would his wife. 3. Each woman’s favorite sport is featured in a triathlon. 4. Allyson bought her husband a new bike for his birthday to use in his favorite sport. SPORTS NAMES Running Swimming Biking Golf Ted X X O X Ken X X X O Allyson O X X X Janie X O X X Tom, John, Fred and Bill are friends whose occupations are (in no particular order) nurse, secretary, teacher and pilot. They attended a picnic recently, and each one brought his favorite meat (hamburger, chicken, steak and hot dogs) to barbecue. From the clues below, determine each man’s occupation and favorite meat. 1. Tom is neither the nurse nor the teacher. (Tom/Teacher, Tom/Nurse) 2. Fred and the pilot play in a jazz band together. (Fred/Pilot) 3. The burger lover and the teacher are not musically inclined. (Burger/Teacher) Also: Fred/Burger, Fred/Teacher, Pilot/Burger 4. Tom brought the hot dogs. (X in rows, columns for Tom/Hot Dog) 5. Bill sat next to the burger fan and across from the steak lover. (Bill/Burger, Bill/Steak KNOW ALL MEATS Also: Burger lover is not teacher or pilot -> john bought burgers -> john not teacher or pilot KNOW BILL IS TEACHER, TOM IS PILOT 6. The secretary does not play an instrument or csc104ma Page 5 6. The secretary does not play an instrument or sing. (Fred/Secretary) KNOW FRED IS NURSE, JOHN IS SECRETARY From <http://matcmp.ncc.edu/sherd/classdoc/csc104/notes.htm> Use the matrix below to work this problem. Use “X” to represent a “No” and “O” to represent a “Yes”. OCCUPATIO NS MEAT Nurse Scty Tchr Pilot Burg Chkn Steak HDog NAMES Tom X X X O X X X O John X O X X O X X X Fred O X X X X X O X Bill X X O X X O X X O X X X O X X X X O MEAT Burg Chkn X Steak O HDog From <http://matcmp.ncc.edu/sherd/classdoc/csc104/notes.htm> From <http://matcmp.ncc.edu/sherd/classdoc/csc104/notes.htm> csc104ma Page 6 9/15 Monday, September 15, 2014 2:03 PM Quiz . Sara Katherine Mallory 4 5 6 Number 5 11 0 15 Abby O X X X X O 1 1 1 0 1 2 0 1 0 1 Jessica X X O O X X 4 1 0 0 1 Eliana X O X X O X 8 0 1 0 1 4 X X O 16 0 0 0 0 csc104ma Page 7 5 X O X 32 0 0 0 0 6 O X X 64 0 0 0 0 Mother Daughter Age Sara Abby Katherine Eliana Mallory Jessica 128 0 0 0 0 6 5 4 Every number from 0 to 255 Can be expressed as the sum Of some of these Start with largest # to translate X 0 15 143 200 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 Start with largest # to translate X X # HW Translate into binary 11 49 192 Put 1 in # column and subtract # from X Put 0 in # column Go to next largest # csc104ma Page 8 9/17 Wednesday, September 17, 2014 1:55 PM quiz translate 73 into binary (show work) 432 From <https://mobile.twitter.com/Math4Sher/status/511635548403171328?p=v> Number 128 64 73 0 1 9 32 0 16 0 8 1 1 4 0 2 0 1 1 0 Number 128 64 192 1 1 64 0 32 0 16 0 8 0 4 0 2 0 1 0 Systematic Lists Variables Values Mary has to make appointments on Monday, Tuesday and Wednesday with a doctor, lawyer and contractor. She only wants to make one appt. a day list all the ways she can do this: Mon Tues Wed D L C D C L 8 1 1 1 1 1 1 1 1 0 0 0 0 csc104ma Page 9 4 1 1 1 1 0 0 0 0 1 1 1 1 2 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 Number 15 14 13 12 11 10 9 8 7 6 5 4 D L L C C C D C D L L C D L D 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 1 0 1 0 4 3 2 1 0 You have quarters dimes nickles and pennies. How many ways can you have $1.12? Quarters Dimes Nickles Pennies 0 0 0 112 0 0 1 107 0 0 2 102 0 0 3 97 0 0 4 92 0 0 5 87 0 0 6 82 0 0 7 77 0 0 8 72 0 0 9 67 0 0 10 62 0 0 11 57 0 0 12 52 0 0 13 47 0 0 14 42 0 0 15 37 0 0 16 32 0 0 17 27 0 0 18 22 csc104ma Page 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 19 20 21 22 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 17 12 7 2 102 97 92 87 82 77 72 67 62 57 52 47 42 37 32 27 22 17 12 7 2 csc104ma Page 11 1. Give initial values to each column that satifies constraint 2. Go through all the possible values for the rightmost column leaving the rest of the columns the same 3. Change the next column to the left to the next possible value 4. Do steps 2 and 3 until all the values for the right columns are done 5. Then we change the next column … How many ways can we make $0.28 Q D N P 0 0 0 28 0 0 1 23 You have 4 topics in a course: Ancient, Medieval, Renaissance , Current 0 0 2 18 You have to do a report on two of these 0 0 3 13 topics. How many ways can you do that. 0 0 4 8 0 0 5 3 Ancient Medieval Renaissance Current 0 1 0 18 N N Y Y 0 1 1 13 N Y Y N 0 1 2 8 N Y N Y 0 1 3 3 Y N N Y 0 2 0 8 Y N Y N 0 2 1 3 Y Y N N 1 0 0 3 HW: Systematically list every way you can have $36 using 1s, 5s, 10s and 20s You have 4 topics in a course: Ancient, Medieval, Renaissance , csc104ma Page 12 You have 4 topics in a course: Ancient, Medieval, Renaissance , Current You have to do a report on three of these topics. How many ways can you do that. csc104ma Page 13 9/22 Monday, September 22, 2014 2:01 PM quiz Systematically list all the way to make $55 from $1,$5, $10,$20,and $50. From <https://mobile.twitter.com/Math4Sher/status/513739347959750657?p=v> $1 55 50 45 40 35 30 25 20 15 10 5 0 45 40 35 30 25 20 15 10 5 $5 0 1 2 3 4 5 6 7 8 9 10 11 0 1 2 3 4 5 6 7 8 $10 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 $20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 $50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 csc104ma Page 14 5 0 35 30 25 20 15 10 5 0 25 20 15 10 5 0 15 10 5 0 5 0 35 30 25 20 15 8 9 0 1 2 3 4 5 6 7 0 1 2 3 4 5 0 1 2 3 0 1 0 1 2 3 4 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 csc104ma Page 15 15 10 5 0 25 20 15 10 5 0 15 10 5 0 5 0 15 10 5 0 5 0 5 0 4 5 6 7 0 1 2 3 4 5 0 1 2 3 0 1 0 1 2 3 0 1 0 1 0 0 0 0 1 1 1 1 1 1 2 2 2 2 3 3 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 Choices If statement It is raining csc104ma Page 16 Choices If statement It is raining If relationship or logic then consequence false If it is raining then I need an umbrella Need umbrella Raining True False False Need Umbrella Umbrella Other Number values relations = < > <> not equal (visual basic) <= less than or equal to >= If(time > 2) then late for class Else Not late End if Time > 2 false Not late Time Late csc104ma Page 17 true late Time Late >2 True <= 2 false HW Write flow chart and systematic list for If blue then Sad End if If age > 21 then Drinks End if csc104ma Page 18 9/24 Wednesday, September 24, 2014 2:01 PM quiz use a systematic list to show all the ways to get $18 from $1,$3, and $7 bills From <https://mobile.twitter.com/Math4Sher/status/514179882897915904?p=v> $1 18 15 12 9 6 3 0 11 8 5 2 4 1 $3 0 1 2 3 4 5 6 0 1 2 3 0 1 $7 0 0 0 0 0 0 0 1 1 1 1 2 2 start Is it raining? Are we home If ( raining) then say("its yukky out") if(home) then wear raincoat else wear umbrella end if raining csc104ma Page 19 raining wear umbrella end if Else wear a smile say("happy day!") End if true false Say "its yukky out" Wear smile say "happy day!" home True Wear raincoat false Wear Umbrella end Raining True False True False Home True True False False Say Its yukky out Happy day Its yukky out Happy day Wear Raincoat A smile Umbrella A smile Logical operators NOT reverses truth happy If(happy) then csc104ma Page 20 NOT reverses truth happy If(happy) then if(not happy) then say "Your insane!" end if End if Happy Say False Nothing True Nothing true false Not happy true false insane AND both are true If(happy AND knowIt) then Do Clap Else Do Snarl End Happy True False True False knowIt True True False False Do Clap Snarl Snarl Snarl OR means at least 1 is true If(rich or pretty) then Get good table Else csc104ma Page 21 Else Get kicked out End if Rich True False True False Pretty True True False False Get Good table Good table Good table Kicked out HW Draw flow chart and systematic list for this code: If(Married and baby) Then be busy if(happy) then call home else call lawyer end if else if(happy and Not baby) Then call airline else if(baby) Then call home end if be bad End if csc104ma Page 22 9/29 Monday, September 29, 2014 1:55 PM Quiz married date Baby and Happy lulaby Married True True True True False False False False Baby True True False False True True False False Happy True False True False True False True False Do Lulaby Lawyer Sing Lawyer Date Date Date Date If(Married and baby) Then be busy if(happy) then call home else call lawyer end if else if(happy and Not baby) Then call airline else if(baby) Then call home end if csc104ma Page 23 Not happy lawyer sing end if be bad End if Married Baby Happy Be Call True True True busy Home True True False Busy Lawyer True False True bad Airline True False False Bad -----False True True bad Home False True False Bad Home False False True Bad Airline False False False Bad ------If(Married OR baby) Then be busy if(happy) then call home else call lawyer end if else if(happy and Not baby) Then call airline else if(baby) Then call home end if be bad End if Married Baby Happy Be Call True True True busy Home True True False Busy Lawyer True False True busy Home True False False Busy Lawyer False True True Busy Home False True False Busy Lawyer False False True Bad Airline False False False bad ------ csc104ma Page 24 Get number Called N Number from 1 to 10 N>10 Output "too large" Output "enter another number" N<1 Output "too small" Output "enter another number" csc104ma Page 25 10/1 Wednesday, October 01, 2014 2:00 PM Quiz Systemic list for: if(weird OR wonderful) then if(wierd) then say "whoa" else if(wonderful and slick) then say "cool" else if(slick) the say "wow" else say "hmmm" end if end if endif else if(wierd OR slick)then say "wooka" else say "why not" end if end if Weird T T T T F F F F Wonderful T T F F T T F F Slick T F T F T F T F From <https://ncc.sln.suny.edu/webapps/blackboard/execute/announcement?method=edit&editMode=true&viewChoice=2 &searchSelect=_20799_1&context=course&course_id=_20799_1&internalHandle=cp_announcements&announcementId=_51618_1> If(employer="school" and not job="teacher") then If(happy) then do whistle Else do moan End if Else If(employer="fast food" or job="server") then if(happy)then do smile else do spit end if else if(not (employer="school" or employer="fast food")) then if(happy) then do dance else do leave end if # no else!! End if End if End if csc104ma Page 26 Employer School School School School School School Fast food Fast food Fast food Fast food Fast food Fast food Other Other Other Other Other Other Job Teacher Teacher Server Server Other Other Teacher Teacher Server Server Other Other Teacher Teacher Server Server Other Other Happy True False True False True False True False True False True False True False True False True false Do … … whistle moan whistle moan smile spit Smile Spit Smile Spit Dance leave Smile Spit Dance leave Say whoa whoa whoa whoa cool hmmm wooka Why not Other csc104ma Page 27 Other false leave 10/6 Monday, October 06, 2014 2:10 PM Practice Exam 1 For Csc104.Docx A October 14 Show your work on each problem 1. 20 pts Given the following decimal number, determine its binary equivalent. Show all work. 27 128 64 0 0 27 27 ____ ____ ____ ____ ____ ____ ____ ____ 2. 35 pts Translate this if statement to a flow chart and write a systematic list of all its variable values. if(important)then take notes if(topic=”news” or location=”here”)then write dispatch else write memo end if else if(topic=”sports” and location=”foreign”) then take vacation else if(not topic=”news”) then take break else take heart write home end if 3. 20 pts Use a systematic list to show all combinations of quarters,dimes,nickles and pennies that make up 42¢ 4. 25 pts. On a party boat sailing out of Captree, four fishers (Irene, Julio, Kate and Lenny) caught prize fish. Each of the four caught a different type of fish (bluefish, mako, pollack or weakfish), and each lives in a different Long Island town (Amityville, Bay Shore, Copiague or Deer Park). Can you find the kind of prize fish each of the four fishers caught and the hometown of each? 1. The Amityville fisher didn't catch the pollack or weakfish. 2. Julio didn't catch the bluefish or mako. 3. Lenny isn't from Copiague. 4. Irene either is from Bay Shore or caught the pollack or both. 5. Kate and the fisher from Bay Shore caught, in some order, the prize pollack and mako. 6. Three of the four people are the fisher from Amityville, the one who caught the bluefish and Irene. WORK: Blue Mako Pollack Weak Amityville Bay Shore Copaigue Deer Park Irene X X O X X O X X Julio X X X O X X O X Kate X O X X O X X X Lenny O X X X X X X O Amityville X O X X Bay Shore X X O X Copaigue X X Deer Park X X Irene Julio Kate Lenny Pollack Weak Mako Blue Bay shore Copaigue Amityville Deer park csc104ma Page 28 32 0 27 16 1 11 Quarters 0 0 0 0 0` 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 4 0 3 Dimes 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 2 2 2 2 2 1 1 Nickles 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 0 1 2 3 1 1 0 Pennies 42 37 32 27 22 17 12 7 2 32 27 22 17 12 7 2 22 17 12 7 0 0 0 0 0 0 1 1 1 1 1 1 2 2 3 3 3 4 0 0 0 0 1 1 3 4 0 1 2 0 0 1 2 3 0 1 7 2 12 7 2 2 17 12 7 2 7 2 1. 35 pts Translate this if statement to a flow chart and write a systematic list of all its variable values. if(important)then take notes if(topic=”news” or location=”here”)then write dispatch else write memo end if else if(topic=”sports” and location=”foreign”) then take vacation else if(not topic=”news”) then take break else Topic=sports take heart and location=foreign end if 2. end if 3. write home end if Topic=news or location=here Write dispatch Take vacation not topic=news Write memo Take break Write csc104ma Page 29 take heart Write home Important T T T T T T T T T F F F F F F F F F Topic News News News Sports Sports Sports Other Other Other News News News Sports Sports Sports Other Other Other Location Here Foreign Other Here Foreign Other Here Foreign Other Here Foreign Other Here Foreign Other Here Foreign Other Take Notes Notes Notes Notes Notes Notes Notes Notes Notes Heart Heart Heart Break Vacation Break Break Break Break Write Dispatch Dispatch Dispatch Dispatch Memo Memo Dispatch Memo Memo Home Home Home Home Home Home Home Home home csc104ma Page 30 10/13 Monday, October 13, 2014 2:10 PM 1. Ferdinand the frog devoured delicious juicy flies whilst not drinking pond water. 2. Lilypad rainwater was eagerly slurped by Davina the dragonfly, but she did not consume discarded rotten bananas. 3. Apples & puddle water made an unusual combination. 4. Ronald the River Rat enjoyed river water. 5. Bella the bat gorged on strawberries. csc104ma Page 31 csc104ma Page 32 if(smoking and not drinking=”frequent”) then get sick if(party=”hard”)then be tired else be happy end if else if(not drinking=”rare”) then be sober get car else be obvious if(smoking or party=”bad”) then get stupid else get real end if end if end if Systematic list Smoking Drinking T Frequent T Frequent T Frequent T Rare T Rare T Rare T Other T Other T Other F Frequent F Frequent F Frequent F Rare F Rare F Rare F Other F Other Party Hard Bad Other Hard Bad Other Hard Bad Other Hard Bad Other Hard Bad Other Hard Bad Be sober sober sober tired happy happy tired happy happy Sober sober sober obvious obvious obvious sober sober Get Car car car sick sick sick sick sick sick car car car real stupid real car car csc104ma Page 33 csc104ma Page 34 F F Other Other Bad sober Other sober car car Failing (course Avg < 60) false Can I work harder Get good grades true harder false On financial aid false csc104ma Page 35 true csc104ma Page 36 false Get withdrawel Form from registrar or b3028 csc104ma Page 37 true Consult with Financial aid advisor csc104ma Page 38 10/15 Wednesday, October 15, 2014 1:53 PM Every kind of visual basic control has a prefix that should start its name. Forms (a window) should start with frm Labels should start with lbl And buttons should start with btn This way you instantly know what kind of control you are working with To manipulate a control you need to know its name. The name is different than the appearance. We access or change properties of a control named susan by using susan.property HW Write a visual basic window program that does something interesting with labels and buttons csc104ma Page 39 10/20 Monday, October 20, 2014 2:22 PM Public Class frmButton Private Sub btnClick_Click(sender As Object, e As EventArgs) Handles btnClick.Click If (btnClick.Text = "Click Me") Then btnClick.Text = "Stop" ElseIf (btnClick.Text = "Stop") Then btnClick.Text = "Really Stop" ElseIf (btnClick.Text = "Really Stop") Then btnClick.Text = "Quit it" Else Me.Close() End If End Sub Private Sub btnFaces_Click(sender As Object, e As EventArgs) Handles btnFaces.Click If btnFaces.Text = "J" Then btnFaces.Text = "K" ElseIf btnFaces.Text = "K" Then btnFaces.Text = "L" Else btnFaces.Text = "J" End If End Sub Private Sub btnClick_Enter(sender As Object, e As EventArgs) Handles btnClick.MouseEnter btnClick.BackColor = Color.Gold End Sub csc104ma Page 40 End Sub Private Sub btnClick_Leave(sender As Object, e As EventArgs) Handles btnClick.MouseLeave btnClick.BackColor = Color.Gray End Sub End Class csc104ma Page 41 10/22 Wednesday, October 22, 2014 2:01 PM Form text: 10/22 quiz Button text: Touch or click When mouse enter reverse for and back colors, leave puts back. When click close window. From <https://ncc.sln.suny.edu/webapps/blackboard/execute/announcement?method=edit&editMode=true&viewChoice=2 &searchSelect=_20799_1&context=course&course_id=_20799_1&internalHandle=cp_announcements&announcementId=_ 52574_1> csc104ma Page 42 csc104ma Page 43 10/27 Monday, October 27, 2014 2:13 PM Label names start with lbl Textbox names start with txt Radio buttons start with rdb Public Class frmCalculator Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim firstNumber As Integer Dim secondNumber As Integer firstNumber = txtFirstNumber.Text secondNumber = txtSecondNumber.Text If rdbAdd.Checked Then lblResult.Text = "Adding " & firstNumber & " to " & secondNumber & " = " & firstNumber + secondNumber ElseIf rdbSubtract.Checked Then lblResult.Text = "Subtracting " & firstNumber & " and " & secondNumber & " = " & firstNumber - secondNumber Else lblResult.Text = "Don't know what to do with " & txtFirstNumber.Text & " and " & txtSecondNumber.Text End If End Sub End Class csc104ma Page 44 Public Class frmText Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click lblOutput.Text = "Seven times " & txtNumber.Text & " is " & txtNumber.Text * 7 End Sub End Class csc104ma Page 45 10/29 Wednesday, October 29, 2014 3:08 PM Public Class frmSame Private Sub btnSame_Click(sender As Object, e As EventArgs) Handles btnSame.Click If TxtFirst.Text <> txtSecond.Text Then btnSame.Text = "L" REM if the text is different, frown Else btnSame.Text = "J" REM if the text is the same, smile End If End Sub Private Sub TxtFirst_TextChanged(sender As Object, e As EventArgs) Handles TxtFirst.TextChanged If TxtFirst.Text <> txtSecond.Text Then btnSame.Text = "L" REM if the text is different, frown Else btnSame.Text = "J" REM if the text is the same, smile End If End Sub Private Sub txtSecond_TextChanged(sender As Object, e As EventArgs) Handles txtSecond.TextChanged If TxtFirst.Text <> txtSecond.Text Then btnSame.Text = "L" REM if the text is different, frown Else btnSame.Text = "J" REM if the text is the same, smile End If End Sub csc104ma Page 46 Private Sub rdbBlue_CheckedChanged(sender As Object, e As EventArgs) Handles rdbBlue.CheckedChanged Me.BackColor = Color.Blue Me.ForeColor = Color.Aqua End Sub Private Sub rdbRed_CheckedChanged(sender As Object, e As EventArgs) Handles rdbRed.CheckedChanged Me.BackColor = Color.Red Me.ForeColor = Color.Cornsilk End Sub Private Sub rdbBrown_CheckedChanged(sender As Object, e As EventArgs) Handles rdbBrown.CheckedChanged Me.BackColor = Color.Brown Me.ForeColor = Color.Fuchsia End Sub Private Sub rdbBlueText_CheckedChanged(sender As Object, e As EventArgs) Handles rdbBlueText.CheckedChanged TxtFirst.ForeColor = Color.Blue txtSecond.ForeColor = Color.Blue End Sub Private Sub rdbRedText_CheckedChanged(sender As Object, e As EventArgs) Handles rdbRedText.CheckedChanged TxtFirst.ForeColor = Color.Red txtSecond.ForeColor = Color.Red End Sub Private Sub rdbBrownText_CheckedChanged(sender As Object, e As EventArgs) Handles rdbBrownText.CheckedChanged TxtFirst.ForeColor = Color.Brown txtSecond.ForeColor = Color.Brown End Sub End Class csc104ma Page 47 11/3 Monday, November 03, 2014 3:23 PM Public Class frmNovember Private Sub rdbRed_CheckedChanged(sender As Object, e As EventArgs) Handles rdbRed.CheckedChanged Me.BackColor = Color.Red End Sub Private Sub rdbBlue_CheckedChanged(sender As Object, e As EventArgs) Handles rdbBlue.CheckedChanged Me.BackColor = Color.Blue End Sub Private Sub btnResult_Click(sender As Object, e As EventArgs) Handles btnResult.Click If rdbLess.Checked Then If CInt(txtLeft.Text) < CInt(txtRight.Text) Then btnResult.Text = "true" Else btnResult.Text = "false" End If End If If rdbGreater.Checked Then If CInt(txtLeft.Text) > CInt(txtRight.Text) Then btnResult.Text = "true" Else btnResult.Text = "false" End If End If End Sub End Class csc104ma Page 48 csc104ma Page 49 11/5 Wednesday, November 05, 2014 3:23 PM csc104ma Page 50 csc104ma Page 51 11/10 Monday, November 10, 2014 2:53 PM Project 4 Use better names Check boxes start with chk csc104ma Page 52 11/12 Exam review Sunday, November 9, 2014 8:20 PM txtFirst will contain "number is 10" txtSecond will contain "sum is 5" txtThird will contain "gamma" csc104ma Page 53 Fruit Apple Apple Apple Apple Apple Apple Apple Apple Apple Other Other Other Other Other Other Other Other Other fruitColor Red Red Red Green Green Green Other Other Other Red Red Red Green Green Green Other Other Other Output Ripe Ripe Ripe Unripe Unripe Unripe Grape Grape Grape Grape Grape Grape Unripe Unripe Unripe Grape Grape Grape Season Fall Spring Other Fall Spring Other fall spring other Fall Spring Other Fall spring Other Fall Spring Other Result Late apple Early apple Apple Never ripe Who knows Who knows Purple Purple Purple Purple Purple Purple Never ripe Who knows Who knows Purple Purple purple Public Class frmInsurance Private Sub btnInsurance_Click(sender As Object, e As EventArgs) Handles btnInsurance.Click Dim income As Double = CDbl(txtIncome.Text) Dim dependents As Integer = CInt(txtDependents.Text) csc104ma Page 54 Dim dependents As Integer = CInt(txtDependents.Text) REM if you are dying soon then each of your dependents needs 10* your income If chkDyingSoon.Checked Then btnInsurance.Text = "You need: $" & CStr(income * dependents * 10) Else REM you don't think you are dying soon REM if you have no dependents you do not need insurance If (dependents = 0) Then btnInsurance.Text = "You do not need any insurance" Else REM if you are a smoker your dependents deserve more insurance just for putting up with the smell If chkSmoker.Checked Then btnInsurance.Text = "You need: $" & CStr(income * dependents * 7) Else btnInsurance.Text = "You need: $" & CStr(income * dependents * 5) End If End If End If End Sub End Class csc104ma Page 55 11/19 Wednesday, November 19, 2014 Decade 60s 60s 60s 60s 60s 60s 60s 60s 70s 70s 70s 70s 70s 70s 70s 70s Other Other Other Instrument Drum Drum Bass Bass Cello Cello Other Other Drum Drum Bass Bass Cello Cello Other Other Bass Bass Drum 2:02 PM Music Classical Other Classical Other Classical Other Classical Other Classical Other Classical Other Classical Other Classical Other Classical Other Classical Output Kenedy Kenedy Kenedy Kenedy Kenedy Kenedy Kenedy Kenedy Instrumental Instrumental Instrumental Instrumental Instrumental Instrumental Instrumental Instrumental Obama Instrumental Obama csc104ma Page 56 Result Ringo Ringo John John Paul Paul Paul Paul Pavorotti Pavorotti Pavorotti Pavorotti Yo yo ma Yo yo ma Pavorotti Pavorotti Unknown Pavorotti Unknown Other Other Other Other Other Other Drum Drum Cello Cello Other Other Classical Other Classical Other Classical Other Obama Instrumental Obama Instrumental Obama Instrumental csc104ma Page 57 Unknown Pavorotti Unknonw yo yo ma Unknown pavorotti 12/1 Monday, December 01, 2014 2:03 PM Public Class frmList Private Sub lstColors_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstColors.SelectedIndexChanged changeColor() txtColors.Text = lstColors.SelectedItem End Sub Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles txtColors.TextChanged REM go through every color in lstColors.items For index As Integer = 1 To lstColors.Items.Count - 1 If lstColors.Items(index) = txtColors.Text Then lstColors.SelectedIndex = index changeColor() End If Next End Sub Private Sub changeColor() If lstColors.SelectedItem = "Blue" Then Me.BackColor = Color.Blue ElseIf lstColors.SelectedItem = "Red" Then Me.BackColor = Color.Red ElseIf lstColors.SelectedItem = "Green" Then Me.BackColor = Color.Green ElseIf lstColors.SelectedItem = "Brown" Then Me.BackColor = Color.Brown ElseIf lstColors.SelectedItem = "Orange" Then csc104ma Page 58 ElseIf lstColors.SelectedItem = "Orange" Then Me.BackColor = Color.Orange ElseIf lstColors.SelectedItem = "Purple" Then Me.BackColor = Color.Purple ElseIf lstColors.SelectedItem = "Charcoal" Then Me.BackColor = Color.DarkGray ElseIf lstColors.SelectedItem = "Yellow" Then Me.BackColor = Color.Yellow End If End Sub End Class csc104ma Page 59 12/3 Wednesday, December 03, 2014 1:56 PM Public Class frmChangeList Private Sub btnEnter_Click(sender As Object, e As EventArgs) Handles btnEnter.Click lstHistory.Items.Add(txtFromUser.Text) End Sub Private Sub lstHistory_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstHistory.SelectedIndexChanged txtFromUser.Text = lstHistory.SelectedItem End Sub REM see if word is in lstHistory returns the index REM if the word is not in lstHistory return -1 Private Function find(word As String, box As ListBox) As Integer REM go through all the items in lstHistory For index As Integer = 0 To box.Items.Count - 1 If word = box.Items(index) Then Return index End If Next REM did not find the word in lstHistory Return -1 End Function Private Sub txtFromUser_TextChanged(sender As Object, e As EventArgs) Handles txtFromUser.TextChanged Dim index As Integer REM holds the position of text in lstHistory index = find(txtFromUser.Text, lstHistory) REM if we found it If (index >= 0) Then lstHistory.SelectedIndex = index End If End Sub Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles txtOther.TextChanged Dim index As Integer REM holds the position of text in lstHistory index = find(txtOther.Text, lstOtherHistory) REM if we found it If (index >= 0) Then lstOtherHistory.SelectedIndex = index End If End Sub Private Sub btnOtherEnter_Click(sender As Object, e As EventArgs) Handles btnOtherEnter.Click lstOtherHistory.Items.Add(txtOther.Text) End Sub End Class csc104ma Page 60 csc104ma Page 61 12/8 Monday, December 08, 2014 2:17 PM Public Class frmGuess Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click txtFromUser.Text = "" End Sub REM adds the text of the button to txtFromUser Private Sub addButtonText(btn As Button) txtFromUser.Text = txtFromUser.Text & btn.Text End Sub Private Sub btnGuess_Click(sender As Object, e As EventArgs) Handles btnGuess.Click Dim number As Integer REM number from user Dim max As Integer REM maximum guess Dim guesses As Integer REM number of guesses til number guessed number = CInt(txtFromUser.Text) If (number < 1) Then Return If number < 10 Then max = 10 ElseIf number < 100 Then max = 100 ElseIf number < 1000 Then max = 1000 Else max = 10000 End If guesses = 0 REM no guesses yet While guesses < 2 * max guesses = guesses + 1 REM new guess Dim guess As Integer REM to hold a guess guess = Rnd() * max If guess = number Then lblGuessCount.Text = "Guessed " & number & " with " & guesses & " guesses." Return End If End While csc104ma Page 62 End While lblGuessCount.Text = "Did not guess " & number & " with " & guesses & " guesses." End Sub Private Sub btn0_Click(sender As Object, e As EventArgs) Handles btn0.Click addButtonText(btn0) End Sub Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click addButtonText(btn1) End Sub Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click addButtonText(btn2) End Sub Private Sub btn00_Click(sender As Object, e As EventArgs) Handles btn00.Click addButtonText(btn00) End Sub Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click addButtonText(btn3) End Sub Private Sub btn4_Click(sender As Object, e As EventArgs) Handles btn4.Click addButtonText(btn4) End Sub Private Sub btn5_Click(sender As Object, e As EventArgs) Handles btn5.Click addButtonText(btn5) End Sub Private Sub btn6_Click(sender As Object, e As EventArgs) Handles btn6.Click addButtonText(btn6) End Sub Private Sub btn7_Click(sender As Object, e As EventArgs) Handles btn7.Click addButtonText(btn7) End Sub csc104ma Page 63 End Sub Private Sub btn8_Click(sender As Object, e As EventArgs) Handles btn8.Click addButtonText(btn8) End Sub Private Sub btn9_Click(sender As Object, e As EventArgs) Handles btn9.Click addButtonText(btn9) End Sub End Class csc104ma Page 64 12/10 Wednesday, December 10, 2014 3:07 PM New and changed stuff is in Red Public Class frmGuess Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click txtFromUser.Text = "" End Sub REM adds the text of the button to txtFromUser Private Sub addButtonText(btn As Button) txtFromUser.Text = txtFromUser.Text & btn.Text End Sub Private Sub btnGuess_Click(sender As Object, e As EventArgs) Handles btnGuess.Click Dim number As Integer REM number from user Dim max As Integer REM maximum guess Dim guesses As Integer REM number of guesses til number guessed REM make sure something is in the textbox If txtFromUser.Text = "" Then lblGuessCount.Text = "No number to guess" Return End If number = CInt(txtFromUser.Text) REM the range of guesses corresponds to the number of digits If (number < 1) Then lblGuessCount.Text = number & " is too small to guess" Return End If If number < 10 Then REM 1 digit number max = 10 ElseIf number < 100 Then REM 2 digit number max = 100 ElseIf number < 1000 Then REM 3 digit number max = 1000 Else lblGuessCount.Text = number & " is too large to guess" Return csc104ma Page 65 Return End If guesses = 0 REM no guesses yet REM keeps guessing till you find the number Dim guess As Integer REM hold a guess of a number Do Until guess = number guess = Rnd() * max guesses = guesses + 1 Loop lblGuessCount.Text = "Guessed " & number & " in " & guesses & " guesses" End Sub Private Sub btn0_Click(sender As Object, e As EventArgs) Handles btn0.Click addButtonText(sender) End Sub Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click addButtonText(sender) End Sub Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click addButtonText(sender) End Sub Private Sub btn00_Click(sender As Object, e As EventArgs) addButtonText(sender) End Sub Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click addButtonText(sender) End Sub Private Sub btn4_Click(sender As Object, e As EventArgs) Handles btn4.Click addButtonText(sender) End Sub Private Sub btn5_Click(sender As Object, e As EventArgs) Handles btn5.Click addButtonText(sender) End Sub Private Sub btn6_Click(sender As Object, e As EventArgs) Handles btn6.Click addButtonText(sender) End Sub csc104ma Page 66 End Sub Private Sub btn7_Click(sender As Object, e As EventArgs) Handles btn7.Click addButtonText(sender) End Sub Private Sub btn8_Click(sender As Object, e As EventArgs) Handles btn8.Click addButtonText(sender) End Sub Private Sub btn9_Click(sender As Object, e As EventArgs) Handles btn9.Click addButtonText(sender) End Sub Private Sub btnNegate_Click(sender As Object, e As EventArgs) addButtonText(sender) End Sub Private Sub btnBackspace_Click(sender As Object, e As EventArgs) Handles btnBackspace.Click txtFromUser.Text = txtFromUser.Text.Substring(0, txtFromUser.Text.Length - 1) End Sub End Class csc104ma Page 67 csc104ma Page 68 12/15 Review Exam 3 Sunday, December 14, 2014 7:59 PM csc104ma Page 69 2. Sub numbers2lstOutput() For index as integer = cint(txtFirst.Text) to cint(txtLast.Text) lstOutput.Items.Add(index) rem add the number from txtFirst to txtLast csc104ma Page 70 lstOutput.Items.Add(index) rem add the number from txtFirst to txtLast Next End Sub 3. . a) Begin 14 Small b) Large start 196 4. Dim sum as integer ' sum of numbers Dim start as integer ' first number in sum Dim finish as integer ' last number in sum start = 3 finish = 7 sum = 0 for num as integer = start to finish sum = sum+num Next txtSum.Text = "Total is " & sum csc104ma Page 71
© Copyright 2026 Paperzz