在vb.net中编写程序 [英] to write program in vb.net

查看:85
本文介绍了在vb.net中编写程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Assigment,但我无法解决,请您帮助我

超市中的每个商品均由其通用商品代码(UPC)标识,该商品代码由出现在长条矩形下方的12位数字组成.见图8.13.条形图中已对这些数字进行了编码,以便UPC可以被光学扫描仪读取.让我们将UPC称为d1-d2 d3 d4 d5 d6 -d7 d8 d9 d10 d11 -d12.左侧的一位数字标识产品的类型(例如,对于普通食品,为0;对于肉类和农产品,为2;对于药品和保健品,为3;对于优惠券,为5).第一组五位数字d2 d3 d4 d5 d6标识制造商,第二组五位数字d7 d8 d9 d10 d11标识产品.右边的第12位数字d12是校验位.被选择以便

-------------------------------------------------- ------------------------------
[Page 459]
3·d1 + d2 + 3·d3 + d4 + 3·d5 + d6 + 3·d7 + d8 + 3·d9 + d10 + 3·d11 + d12.
(*)



是10的倍数.例如,对于图8.11中的UPC,
3·0 + 7 + 3·0 + 7 + 3·3 + 4 + 3·0 + 0 + 3·9 + 0·0 + 3·3 + 4 = 40.

图8.13.通用产品代码.


由于40 = 4·10,所以40是10的倍数.如果出纳员必须手动输入UPC并输错数字,则上述总和通常不会加起来等于10的倍数.
编写一个程序,模拟超市的自动结帐柜台.一个称为UPC.TXT的主顺序文件应为每个项目包含一个记录,该记录由UPC的字段,项目名称和项目价格组成.例如,该文件可能包含以下记录:
070734000034
天时节沉睡茶
2.59

该文件应根据UPC进行订购.该程序应允许收银员一次进入一个UPC,应保持已处理物品总数的连续运行,并且应将UPC放置在一个阵列中.输入每个总和(*)时,应立即对其进行检查;如果总和不是10的倍数,则应重新输入每个总和.处理完所有项目后,程序应对UPC的数组进行排序,然后生成一个UPC.在仅通过主顺序文件传递一次之后,收据类似于图8.14中的收据.

图8.14.编程项目10的示例输出.

I have Assigment and I can''t solve it could you pleas help me

Each item in a supermarket is identified by its Universal Product Code (UPC), which consists of a sequence of 12 digits appearing below a rectangle of bars. See Figure 8.13. The bars have these digits encoded in them so that the UPC can be read by an optical scanner. Let''s refer to the UPC as d1 -d2 d3 d4 d5 d6 -d7 d8 d9 d10 d11 -d12. The single digit on the left, identifies the type of product (for instance, 0 for general groceries, 2 for meat and produce, 3 for drug and health products, and 5 for coupons). The first set of five digits, d2 d3 d4 d5 d6, identifies the manufacturer, and the second set of five digits, d7 d8 d9 d10 d11, identifies the product. The twelfth digit on the right, d12, is a check digit. It is chosen so that

--------------------------------------------------------------------------------
[Page 459]
3 · d1 + d2 + 3 · d3 + d4 + 3 · d5 + d6 + 3 · d7 + d8 + 3 · d9 + d10 + 3 · d11 + d12.
(*)



is a multiple of 10. For instance, for the UPC in Figure 8.11,
3 · 0 + 7 + 3 · 0 + 7 + 3 · 3 + 4 + 3 · 0 + 0 + 3 · 9 + 0 · 0 + 3 · 3 + 4 = 40.

Figure 8.13. A Universal Product Code.


Since 40 = 4 · 10, 40 is a multiple of 10. In the event that the cashier has to enter the UPC manually and mistypes a digit, the above sum will usually not add up to a multiple of 10.
Write a program to simulate an automated check-out counter at a supermarket. A master sequential file, called UPC.TXT, should have a record for each item consisting of fields for the UPC, name of the item, and the price of the item. For instance, the file might contain the following record:
070734000034
Celestial Seasons Sleepytime Tea
2.59

The file should be ordered with respect to the UPCs. The program should allow the cashier to enter UPCs one at a time, should keep a running total of the number of items processed, and should place the UPCs in an array. Each UPC should be checked with the sum (*) as soon as it is entered and should be reentered if the sum is not a multiple of 10. After all items have been processed, the program should sort the array of UPCs and then produce a receipt similar to the one in Figure 8.14 after making just one pass through the master sequential file.

Figure 8.14. Sample output of Programming Project 10.

推荐答案

您尝试了什么?

该论坛的整个重点不是为您提供分配作业的解决方案,而是帮助人们解决特定的问题.

如果您甚至不知道从哪里开始,就应该与您的老师交谈.
What have you tried?

This whole point of this forum is not to supply you with solutions to your assignments but to help people out with specific problems.

If you don''t even know where to start you should talk to your teacher.


您给我们看的是作业,但是没有任何关于您需要帮助的内容.

如果我正在阅读的要点是确认校验位正确,则必须创建一个模数值以对照校验位进行检查.

不知道您知道多少VB,值得值得一看 [ ^ ]为您提供模数的功能.

执行作业中描述的数学功能,并将其与运算的模数进行比较,如果它们不匹配,则运行异常代码.

另一种方法是执行蹄的计算.

我写了一个类似的功能来验证增值税号.

增值税检查的示例代码.

What you have shown us is the assignment, but there nothing specified as to what you want help with.

If the gist, as I am reading it, is confirm a check digit is correct, you will have to create a modulus value to check against the check digit.

Not knowing how much VB you know, it would be worth looking at this[^] to give you the function of a modulus.

Perform the maths funtion described in the assignment and compare it to the modulus of the operation and if they fail to match then run the exception code.

The other way is to perform the calculations of the hoof.

I wrote a similar function for verifying VAT numbers.

Example code for VAT checking.

<pre lang="vb">'' declare variable
        Dim strVatNumber As String
        Dim arrVatNumber(8) As Integer
        Dim intVatTotal As Integer
        Dim intCheckSum As Integer
        Dim strMessage
        '' set initial values
        strVatNumber = TextBox1.Text
        intVatTotal = 0
        '' loop to fill array from string and do the maths.
        For i = 0 To 6
            arrVatNumber(i) = Val(strVatNumber(i))
            arrVatNumber(i) = arrVatNumber(i) * (8 - i)
            intVatTotal = intVatTotal + arrVatNumber(i)
        Next
        '' assign check sum
        '' assure that no multiply by zero
        If arrVatNumber(7) <> 0 Then
            arrVatNumber(7) = Val(strVatNumber(7))
            arrVatNumber(8) = Val(strVatNumber(8))
            intCheckSum = (arrVatNumber(7) * 10) + arrVatNumber(8)
        Else
            intCheckSum = arrVatNumber(8)
        End If

        While intVatTotal > 97
            intVatTotal = intVatTotal - 97
        End While
        ''give result
        If intCheckSum = intVatTotal Then
            strMessage = "Vat Number Confirmed OK"
        Else
            strMessage = "Vat Number -INCORRECT-"
        End If
        Label1.Text = strMessage





我将此分配给表单的按钮单击事件.

尝试两种方法,祝您好运.





I assigned this to a button click event of a form.

Try either approach, good luck.


没有人会为您做功课.


这篇关于在vb.net中编写程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆