Friday, January 28, 2011

Programming 2 /* Practice #1 - Acts and Facts */

'McIntyre Practice #1 - Acts and Facts 
Public Class ActsAndFacts   
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click   
    '1. Morgan loves collecting small stuffed animals. She has 6 cows and 7 sheep. How many   
        animals does she have in her collection?     
    'Variables declared   
    Dim Cows, Sheep, Animals As Integer   
    'Variables set   
    Cows = 6   
    Sheep = 7   
    'Calculation of total animals   
    Animals = Cows + Sheep   
    'Output in a message box   
    MessageBox.Show("There are " & Animals & " Animals.")   
   End Sub   
   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click   
    '2. Diane bought 7 mega burgers. Each mega burger cost $4. How many dollars did she spend on the Mega Burgers?   
    'Variables declared   
    Dim MegaBurgers As Integer   
    Dim MBCost, TotalCost As Decimal   
    'Variables set   
    MegaBurgers = 7   
    MBCost = 4   
    'Calculation of Total Cost of the Mega Burgers   
    TotalCost = MegaBurgers * MBCost   
    'Output in a message box   
    MessageBox.Show("The Total Cost of the Megaburgers is " & FormatCurrency(TotalCost, 2) & ".")   
   End Sub   
   Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click   
    '3. Ole has 15 apples and 12 oranges. How many pieces of fruit does he have?   
    'Variables declared   
    Dim Apples, Oranges, TotalFruit As Integer   
    'Variables set   
    Apples = 15   
    Oranges = 12   
    'Calculation of Total Fruit   
    TotalFruit = Apples + Oranges   
    'Output in a message box   
    MessageBox.Show("There are a total of " & TotalFruit & " fruit.")   
   End Sub   
   Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click   
    '4. There are 33 horses in a field. 15 horses go into the barn. Then 7 of them come back out. How many horses are standing in the field?   
    'Variables declared   
    Dim FieldHorses, BarnHorses, HorsesThatCameOut, HorsesStanding As Integer   
    'Variables set   
    FieldHorses = 33   
    BarnHorses = 15   
    HorsesThatCameOut = 7   
    'Calculation of Horses left in the field   
    HorsesStanding = (FieldHorses - BarnHorses) + HorsesThatCameOut   
    'Output in a message box   
    MessageBox.Show("There are " & HorsesStanding & " standing in the field.")   
   End Sub   
   Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click   
    '5. Inglebert has 15 apples and 3 times as many oranges. How many pieces of fruit does she have?   
    'Variables declared   
    Dim Apples, Oranges, TotalFruit As Integer   
    'Variables set   
    Apples = 15   
    Oranges = Apples * 3   
    'Calculation of Total Fruit   
    TotalFruit = Apples + Oranges   
    'Output in a message box   
    MessageBox.Show("There are a total of " & TotalFruit & " fruit.")   
   End Sub   
   Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click   
    '6.  English Geography Mathematics Science    
    'Andrew 12  19   18   7    
    'Brian  22  15   7   22    
    'The table shows quiz marks out of 25 in each subject.    
    '•How many marks did Brian totally obtain in Mathematics and Science?   
    '•How many more marks does Andrew need for a perfect score in Mathematics?   
    '•What is Andrew's percentage for all of the quizzes together?   
    'Variables declared   
    Dim AEng, BEng, AGeo, BGeo, AMath, BMath, ASci, BSci, PerfectScore, BTPoints, NeededForPerfectScore, APerc As Integer   
    'Variables set   
    AEng = 12   
    BEng = 22   
    AGeo = 19   
    BGeo = 15   
    AMath = 18   
    BMath = 7   
    ASci = 7   
    BSci = 22   
    PerfectScore = 25   
    'Calculation of Brian's total points in Math and Science   
    BTPoints = BMath + BSci   
    'Needed marks for a perfect score for Andrew in Math   
    NeededForPerfectScore = PerfectScore - AMath   
    'Andrew's percentage for all quizzes   
    APerc = (AEng + AGeo + AMath + ASci) / 4   
    'Outputting the answers in a message box   
    MessageBox.Show("Total marks for Brian in Math and Science is " & BTPoints & ".")   
    MessageBox.Show("Andrew needs " & NeededForPerfectScore & " points for a perfect score in Math.")   
    MessageBox.Show("Andrew's percentage for all of the quizzes together is " & APerc & ".")   
   End Sub   
  End Class   

No comments:

Post a Comment

Classes

Programming II

Advanced Relational Database

Followers