Leaving aside forms and controls, from vb to c language

Leaving aside forms and controls, from vb to c language Visual Basic (VB for short) is a general object-based programm...
Sorting performance in different languages
Process oriented c
Leaving aside forms and controls, from vb to c language


Visual Basic (VB for short) is a general object-based programming language developed by Microsoft. It is a structured, modular, object-oriented visual programming language with event driven mechanism to assist the development environment. It is a language that can be used for Microsoft's own product development.
C language is a process oriented and abstract general programming language, which is widely used in Bottom development. C language can compile and process low-level memory in a simple way. C language is an efficient programming language that produces only a small amount of machine language and can run without any running environment support.

  1. As a simple and easy-to-use language, VB is now in a position. Under the collision of major high-level languages, Basic language is basically useless, but for beginners, it still plays an important role in the education of some primary and secondary school students. Technology is also included in the college entrance examination in Zhejiang Province, in which VB programming questions account for a large proportion.
  2. C language, as a relatively low-level language for development, is the basis of computer program language. Learning C language well can lay a good foundation for you to learn JAVA, C + +, VB, etc. in the future, because most of these languages are extended or derived from C language. Therefore, C language is also a compulsory course in computer related majors in universities.
  3. From VB to learning c language, understanding the commonality of the underlying algorithms and the role of facing different objects will help to increase our enthusiasm for learning computers.

The following introduces the differences and advantages and disadvantages of the two languages from two aspects.

Observe the running speed through a simple algorithm
  • Algorithms and data structures are a necessary knowledge for learning any computer language. Let's find out the advantages and disadvantages of different languages through simple sorting algorithm and dichotomy.

Sorting performance in different languages

  • Bubbling and selective sorting in VB system

Bubble sorting

Const n As Integer = 100 "be similar to c In language int Constant of type Dim i As Integer, j As Integer Dim Arr(1 To n) As Integer "arr Is a length of n An array of, VB The upper and lower bounds are used to control the length of the array " Here Arr Array random assignment,Code slightly. "Attention, in VB The values entered through the control in are all character types (which are c Not directly in the language, which can be replaced by string array). You need to pass them through val The function is converted to (numeric). Similarly, output is required str Function converts a numeric value into a character. For i = 1 To n - 1 " This is the external circulation, Controls the number of times to traverse the check, Go here N - 1 Times For j = 1 To n - i " This is internal circulation, Control the times of each inspection, Go here N - i Times, Because there were already in the last state i The number is lined up, also N - i + 1 The number needs to be checked If Arr(j) > Arr(j + 1) Then " This is responsible for inspection If sentence,The number of times it runs is the number of executions mentioned above Swap(Arr(j), Arr(j + 1)) " exchange,The number of times it runs is the number of exchanges mentioned above End If Next j Next i "Next End It is a sign of judgment and the end of the cycle Sub Swap(X1 As Integer,X2 As Integer)"Similarly, you need to pass in parameters to the function in a similar format X1 = X1 - X2 X2 = X2 + X1 X1 = X2 - X1 End Sub " The process of exchanging by addition and subtraction(Sub) , For the time being, it can be understood as an exchange function without return value(Function) " This bubbling runtime,Always throw the biggest number back "It can also be used function Custom function writing, similar to c Functions written in the language

Select sort

Const n As Integer = 100 Dim i As Integer , j As Integer, max As Integer Dim Arr(1 To n) As Integer " Here Arr Array random assignment,Code slightly. For i = 1 To n - 1 max = i " A variable is defined max,Used to mark the maximum number of this cycle. First, it is set to the current bit by default, Namely i For j = i + 1 To n If Arr(j) > Arr(max) Then max = j " If a number ratio is found, the subscript is max When the element is large, max The subscript should point to that number, That is, assign its subscript End If Next j If max <> i Then Swap(Arr(i),Arr(max)) " When max When not equal to the original subscript, Indicates that the maximum value is another number, exchange End If Next i Sub Swap(X1 As Integer,X2 As Integer) X1 = X1 - X2 X2 = X2 + X1 X1 = X2 - X1 End Sub " This selection operation will throw the large number back

Having learned c language, it is obvious that the two languages have the same advantages in the For loop and If judgment statements.

  • Bubbling and selection in C language

Bubble sorting

#include<stdio.h> int main(void) { int n,i,t,tmp; scanf("%d", &n); int a[10]; for (i = 0;i < n;i++) { scanf("%d", &a[i]); } int m = n-1; for (i = 0;i < n ;i++) {//Do it n times for (t = 0;t < m;t++) {//m-1 items will be searched every time if (a[t] > a[t + 1]) { tmp = a[t]; a[t] = a[t + 1]; a[t + 1] = tmp; } //Compare the former item with the latter item and increase it } } for (i = 0;i < n;i++) { printf("%d ", a[i]); } }

Select sort

#include<stdio.h> int main(void) { int a[10]; int n,i,min,t,tmp; scanf("%d", &n); for (i = 0;i < n;i++) { scanf("%d", &a[i]); } for (i = 0;i < n-1;i++) { min = i;//Set the first disordered area of each round to the minimum value for (t = i + 1;t < n;t++) { if (a[t] < a[min]) min = t;//All numbers are compared with the minimum value. If it is smaller, put the current t into min } if (a[i] != min) { tmp = a[i]; a[i] = a[min]; a[min] = tmp;//After that, put the minimum value at the end of the ordered area } } for (i = 0;i < n;i++) { printf("%d ", a[i]); } }
  • Since it is obvious that their algorithms are the same, what is the different performance of the program in different languages?
  • VB is very slow in interpretive execution. Compared with C language, it does not wait for the compiler to compile all program statements before execution, but reads and compiles one sentence. Therefore, it is much slower than C language in speed.
  • In addition, after Microsoft announced that it would stop updating VB, it is obvious that it will have a greater gap with other languages in terms of running speed in the future.

binary search

  1. Next, let's briefly introduce the dichotomy search of the two languages

VB


1. The assignment of key has been mentioned in the previous code, and the val function is used. Text1.Text is the category and name of the control.
2. Bisection search is the fastest way to find the key in a string of data.
3. Those who are interested in this topic can also study it. It comes from Zhejiang's examination technology in January 2021.
c language

#include <stdio.h> int main() { int key ;//The number to find in the array int i,n;//n is the length of the array scanf("%d %d",&n, &key); int arr[10]; for (i = 0;i < n;i++) { scanf("%d", &arr[i]); } int length = sizeof(arr) / sizeof(arr[0]);//Length of array int low = 0; int high = length - 1; while (low <= high) { int mid = (low + high) / 2;//The split search starts from the middle mid each time if (arr[mid] > key) { high = mid - 1; } else if (arr[mid] < key) { low = mid + 1; } else { printf("eureka"); break; } } if (low > high) printf("The number was not found in the array"); return 0; }
The essence of programming language
  • According to the preliminary understanding, we know what they have in common, but it is obvious that the fields they use are different.

Process oriented c

  • Process oriented is to analyze the steps needed to solve the problem, and then use functions to realize these steps step by step. When using, you can call them one by one.
  • Obviously, c language is based on algorithms, functions, data flow diagrams, pseudo code... Through which we can solve problems with our own thinking.

Visual object oriented vb

  • VB is a visual object-oriented programming language. Visualization is that it has rich tools to use. Beginners can design all kinds of small programs through VB. For C language, it often takes hundreds of lines of code to simply use code to realize mine sweeping in the black box.

    Through the above understanding, we have roughly clarified the role, advantages and disadvantages of VB, and also transitioned to a more advanced C language. Learning from VB to C language seems to abandon some very useful controls, but it is also a way to progress to more advanced programmers. We will know more about computer language in the honing of C language and go to another level.

6 November 2021, 07:24 | Views: 7015

Add new comment

For adding a comment, please log in
or create account

0 comments