A Jewellery Store Needs a Program to Calculate the Cost of Engraving Names Or Messages

Total Page:16

File Type:pdf, Size:1020Kb

A Jewellery Store Needs a Program to Calculate the Cost of Engraving Names Or Messages

Practical Test Question 1

A company needs a program to help calculate the Yearly Bonus for each employee. The Yearly Bonus is determined by considering several different factors. The first factor is the Number of Years a person has been employed by the firm. Being employed for 1 to 5 years adds R100.00 to the bonus, being employed for 6 to 10 years adds R200.00 to the bonus, and being employed for 11 or more years adds R350.00 to the bonus. (Use Radiobuttons for input)

In addition to the Number of Years, an employee's Work Grade is considered. For Work Grade 1, R75.00 is added to the bonus; for Work Grade 2, R100.00 is added to the bonus; and for Work Grade 3, R125.00 is added to the bonus. Also, if an employee has participated in community service (Parcipation = "Y"), then an additional R100.00 is added to the bonus. And finally, 5 percent of the employee's Current Salary is computed and added to the bonus. (Use Radiobuttons for input)

Use the given flowchart and code the program into Visual Basic.Net (Save as Student number frm1)

Start

Read Participation, Current Salary

Number of True Yearly Bonus = Years <= 5 100.00

False

Number of True Yearly Bonus = Years <= 10 200.00

False

Yearly Bonus = 350.00

Yearly Bonus = Work Grade = True Yearly Bonus + 1 75.00

False

Yearly Bonus = Work Grade = True Yearly Bonus + 2 100.00

False

Yearly Bonus = Yearly Bonus + 125.00

Yearly Bonus = Participation = True Yearly Bonus + “Y” 100.00 False

Yearly Bonus = Yearly Bonus + (CurrentSalary * 0.05)

Write Yearly Bonus

Stop MEMO

Private Sub btnCalculateBonus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateBonus.Click Dim Salary, Bonus As Double Dim Participation As String Salary = txtSalary.Text

If rad1to5.Checked Then Bonus = 100 If radWG1.Checked Then Bonus = Bonus + 75 ElseIf radWG2.Checked Then Bonus = Bonus + 100 Else Bonus = Bonus + 125 End If ElseIf rad6to10.Checked Then Bonus = Bonus + 200 If radWG1.Checked Then Bonus = Bonus + 75 ElseIf radWG2.Checked Then Bonus = Bonus + 100 Else Bonus = Bonus + 125 End If Else Bonus = 350 If radWG1.Checked Then Bonus = Bonus + 75 ElseIf radWG2.Checked Then Bonus = Bonus + 100 Else Bonus = Bonus + 125 End If End If Participation = InputBox("Participate in community service? Y or N", "PARTICIPATION") If Participation.ToUpper = "Y" Then Bonus = Bonus + 100 End If Bonus = Bonus + (Salary * 0.05) lblOutput.Text = "Yearly bonus: " & FormatCurrency(Bonus) End Sub Question 2

A Jewellery Store needs a program to calculate the cost of engraving names or messages on jewellery items or trophies.

The program should continually accept and calculate the cost of names or messages to be engraved. To end this process it is required that “---“ is typed as the message to signal that the repeated process is stopped.

Once the program accepts the name or message to be engraved as input, it should determine how many characters there are in this name or message. Allow the program to analyze the name or message, character by character (letter by letter). Use the following guidelines:

First Five Letters (characters): For the first five letters the cost is a total of R20. Take note that if one of the first five letters happens to be a capital letter, an additional R2 fee is charged, per capital letter, on the R20 whereas a space will be treated as a lower case character.

Remaining Letters (characters): Every letter after the fifth letter is charged at R5 per lowercase letter, R7 per uppercase letter and R1 for a space. (Save as Student number frm2)

frmHead1 frmHead2 frmBody

lstReport

btnCalc btnExit Use the following: Dim frmHead1 As String = "{0,-15}{1,-7}{2,-12}{3,-26}{4,8}" Dim frmHead2 As String = "{0,-15}{1,-7}{2,-12}{3,-8}{4,-10}{5,-8}" Dim frmBody As String = "{0,-17}{1,-7}{2,-12}{3,-8}{4,-10}{5,-8}{6,8:C2}" Enter if msg = Start yes Stop msg "- - -"

no

initialize totals

no Determine msg length

if length > 0

yes

price = 20 Display i = 1 message, totals and price

Do until yes i > length

no

Extract one character

if if if yes no charac = i <= 5 charac = space capital

yes yes

Add R2 to price no Add nothing Add 1 to totCapFive

no

if if if if yes no charac = no charac = lower i > 5 charac = space capital case

yes yes yes

Add R1 to price Add R7 to price Add R5 to price Add 1 to Add 1 to Add 1 to no totSpaces totCapRest totLowRest

no

increment i by 1 SOLUTION

Dim message, charac As String Dim NrChar, i As Integer Dim price As Double Dim totCapFive, totCapRest, totLowRest, totSpaces As Integer Dim frmHead1 As String = "{0,-15}{1,-7}{2,-12}{3,-26}{4,8}" Dim frmHead2 As String = "{0,-15}{1,-7}{2,-12}{3,-8}{4,-10}{5,-8}" Dim frmBody As String = "{0,-17}{1,-7}{2,-12}{3,-8}{4,-10}{5,-8}{6,8:C2}" lstReport.Items.Add(String.Format(frmHead1, "Message", "Total", "First Five", "Remaining", "Cost")) lstReport.Items.Add(String.Format(frmHead2, "", "", "Capital", "Capital", "Lowercase", "Spaces")) lstReport.Items.Add(" ")

message = InputBox("Enter name or message to be engraved") Do Until message = "---" totCapFive = 0 totCapRest = 0 totLowRest = 0 totSpaces = 0 NrChar = Len(message) If NrChar > 0 Then price = 20 For i = 1 To NrChar charac = message.Substring(i - 1, 1) If i <= 5 Then If charac = " " Then 'do nothing ElseIf charac = charac.ToUpper Then price = price + 2 totCapFive = totCapFive + 1 End If Else If charac = " " Then price = price + 1 totSpaces = totSpaces + 1 ElseIf charac = charac.ToUpper Then price = price + 7 totCapRest = totCapRest + 1 ElseIf charac = charac.ToLower Then price = price + 5 totLowRest = totLowRest + 1 End If End If Next End If lstReport.Items.Add(String.Format(frmBody, message, NrChar, totCapFive, totCapRest, totLowRest, totSpaces, price))

message = InputBox("Enter name or message to be engraved") Loop

Recommended publications