23 May, 2011

Decision




1.            Determine whether a number is Positive/Negative/Zero number.

• If TextBox1.Text < 0 Then TextBox2.Text = “Negative"
• If TextBox1.Text = 0 Then TextBox2.Text = “Zero"
• If TextBox1.Text > 0 Then TextBox2.Text = “Positive"



2.            Determine whether a number is Odd/Even number.

Dim a As Integer
        a = TextBox1.Text
        If ((a Mod 2) = 0) Then
            MsgBox("Even")
        Else
            MsgBox("Odd")
        End If


3.            Determine whether a number is Multiple of 3/5.

If TextBox1.Text Mod 3 = 0 And TextBox1.Text Mod 5 > 0 Then
TextBox2.Text = "Multiple of 3"
ElseIf TextBox1.Text Mod 5 = 0 And TextBox1.Text Mod 3 > 0 Then
TextBox2.Text = "Multiple of 5"
ElseIf TextBox1.Text Mod 3 = 0 And TextBox1.Text Mod 5 = 0 Then
TextBox2.Text = "Both"
        End If


4.            Determine whether a company has made Profit or Loss from Cost and Revenue of the company.

If TextBox1.Text > TextBox2.Text Then
            TextBox3.Text = "PROFIT"
        Else : TextBox3.Text = "LOSS"
        End If


5.            Determine the minimum/maximum of two/three numbers.

If TextBox1.Text > TextBox2.Text And TextBox3.Text < TextBox1.Text Then
            TextBox4.Text = TextBox1.Text
ElseIf TextBox2.Text > TextBox1.Text And TextBox3.Text < TextBox2.Text Then
            TextBox4.Text = TextBox2.Text
        Else
            TextBox4.Text = TextBox3.Text
        End If
-----------------------------------------------
If TextBox1.Text < TextBox2.Text And TextBox3.Text > TextBox1.Text Then
            TextBox5.Text = TextBox1.Text
        ElseIf TextBox2.Text < TextBox1.Text And TextBox3.Text > TextBox2.Text Then
            TextBox5.Text = TextBox2.Text
        Else
            TextBox5.Text = TextBox3.Text
        End If


6.           Determine whether a student has failed or passed based on the total percentage marks obtained by the student. 30% marks need to be achieved by a student to pass. Marks of 5 subjects will be input and total marks of each subject will be 100.

TextBox6.Text = TextBox1.Text + +TextBox2.Text + +TextBox3.Text + +TextBox4.Text + +TextBox5.Text
        If TextBox1.Text < 30 Or TextBox2.Text < 30 Or TextBox3.Text < 30 Or TextBox4.Text < 3 Or TextBox5.Text < 30 Then
            TextBox6.Text = "FAIL"
        Else
            TextBox6.Text = "PASS"
        End If



7.            Calculate the total salary (with bonus) for an employee of an organization. The bonus will be calculated by the following criteria:
Salary                                    Bonus
>25000                                  40%
20000-25000                                   30%
<20000                                   20%

If TextBox1.Text >= 25000 Then
TextBox2.Text = TextBox1.Text + +TextBox1.Text * 0.4
ElseIf TextBox1.Text > 20000 And TextBox1.Text < 25000 Then
TextBox2.Text = TextBox1.Text + +TextBox1.Text * 0.3
ElseIf TextBox1.Text <= 20000 Then
TextBox2.Text = TextBox1.Text + +TextBox1.Text * 0.2
End If



8.            Calculate the discount gained on total purchase amount by a customer in a Super shop. The discount rate is determined by the following criteria:
     Total Purchase Amount             Discount
 >=5000                                                         15%
            2500-4999                                                    10%
      < 2500                                                  5%

If TextBox1.Text >= 5000 Then
TextBox2.Text = TextBox1.Text - TextBox1.Text * 0.15
ElseIf TextBox1.Text > 2500 Or TextBox1.Text <= 4999 Then
TextBox2.Text = TextBox1.Text - TextBox1.Text * 0.1
ElseIf TextBox1.Text <= 2500 Then
TextBox2.Text = TextBox1.Text - TextBox1.Text * 0.05
        End If


9.            Determine the grade of a student based on the total marks obtained in a subject. The grading criteria is given below:
Total Marks                       Grade
>=90                                               A
70-89                                   B
60-69                                   C
50-59                                   D
< 50                                    F

Dim a As Integer
        a = TextBox1.Text
        If a > 89 Then
            MsgBox("You have passed at Grade A")
        ElseIf a > 69 Then
            MsgBox("You have passed at Grade B")
        ElseIf a > 59 Then
            MsgBox("You have passed at Grade C")
        ElseIf a > 49 Then
            MsgBox("You have passed at Grade D")
        Else
            MsgBox("You have failed F")
        End If


10.        Calculate the total cost of CDs sold by a computer store. The computer store sells DVDs at 70 taka each for small orders or at 60 taka each for orders of 100 DVDs or more. 
Dim n, Tc As Integer
        n = TextBox1.Text
        If n >= 100 Then
            Tc = n * 60
            TextBox2.Text = Tc
        Else
            Tc = n * 70
            TextBox2.Text = Tc
        End If
11. Once User has entered Salary, Calculate and display:
Bonus (20% of Salary),Total Salary (Salary + Bonus)

Dim Salary As Integer
Salary = TextBox1.Text
Dim Bonus As Integer
Bonus = Salary * .2
TextBox2.Text = Bonus
Dim TSalary As Integer
TSalary = Salary + Bonus
TextBox3.Text = TSalary

12. Once User has entered Unit Price & Discount (%), Calculate and display: Discount Amount, Payable Amount (Unit Price – Discount Amount)

Dim Price As Integer
Price = TextBox1.Text
Dim D As Integer
D = TextBox2.Text
Dim Discount As Integer
Discount = (Price * D) / 100
TextBox3.Text = Discount
Dim Pay As Integer
Pay = Price – Discount
TextBox4.Text = Pay





Conversion




1.  Convert the length in km (kilometer) to meter/feet/centimeter and vice versa.

• TextBox2.Text = TextBox1.Text * 1000
• TextBox3.Text = (19.68503937 * TextBox1.Text * 1000) / 6
• TextBox4.Text = TextBox1.Text * 100000



2.   Convert Fahrenheit temperature to Celsius and vice versa.

• TextBox2.Text = (5 * TextBox1.Text - 160) / 9
• TextBox4.Text = (9 * TextBox3.Text + +160) / 5



Numbers and Basic Arithmetic Operations




1.            Calculate the Addition/Subtraction/Multiplication/Division of two numbers.

• TextBox3.Text = TextBox1.Text + +TextBox2.Text
• TextBox3.Text = TextBox1.Text - TextBox2.Text
• TextBox3.Text = TextBox1.Text * TextBox2.Text
• TextBox3.Text = TextBox1.Text / TextBox2.Text


2.            Calculate the Average of three numbers.

 TextBox4.Text = (TextBox1.Text + +TextBox2.Text + +TextBox3.Text) / 3


3.            Calculate the Percentage of one number to another number (for example, 35 is 70% of 50)


TextBox3.Text = TextBox1.Text * TextBox2.Text / 100


4.            Calculate the Area of a rectangle/square/triangle/circle.

• TextBox3.Text = TextBox1.Text * TextBox2.Text
• TextBox2.Text = TextBox1.Text * TextBox1.Text
• TextBox3.Text = 0.5 * TextBox1.Text * TextBox2.Text
• TextBox2.Text = 3.1416 * (TextBox1.Text * TextBox1.Text)


5.            Calculate the Price of an item after 30% discount.

TextBox2.Text = TextBox1.Text - (TextBox1.Text * 0.3)


6.            Calculate the Amount of Simple Interest from principal amount, annual rate and time.


TextBox4.Text = TextBox1.Text * TextBox2.Text * TextBox3.Text * (1 / 1200)

02 May, 2011

Output Tracing



Output Tracing:

Dim i As Integer = 15
Dim j As Integer = 10
Dim k As Integer

Do While j < i
   i = i + 1
   j += 2
   k += i + j
Loop

TextBox1.Text = i
TextBox2.Text = j
TextBox3.Text = k


i
j
k
(before loop)
15
10
0
10<15: T
16
12
0+16+12=28
12<16: T
17
14
28+17+14=59
14<17: T
18
16
59+18+16=93
16<18: T
19
18
93+19+18=130
18<19: T
20
20
130+20+20=170
20<20: F






Output:

20
20
170

Q1:

Dim i As Integer = 6
Dim j As Integer = 8
Dim k As Integer

Output:

15
10
7
 
 

Do
   i = i + 1
   k += i + j
   j += 2  
Loop While j < i

TextBox1.Text = k
TextBox2.Text = j
TextBox3.Text = i


i
k
j
(before loop)
6
0
8

7
0+7+8=15
10
10<7: F