Question

In Visual Studio 2015, Write a review assignment that includes, functions, two dimension array, parallel array...

In Visual Studio 2015, Write a review assignment that includes, functions, two dimension array, parallel array with the key other than sequntial numbers, structures, multiple forms and modules

Using visual basic

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Function

in visual studio a function is declared using the Function statement as follows

[modifier(public, private etc)] Function Name_of_the_function[(parameter input)] As Return_type [statements] End Function

here modifier are access modifier like public , private , protected  

a function example

a function to calculate larger of two numbers
Module HomeworkLib_function
Function themax(ByVal a As Integer, ByVal b As Integer) As Integer
' initializing variables */
Dim max As Integer
  
If (a > b) Then
max = a
Else
max = b
End If
themax = max
End Function
Sub Main()
Dim x As Integer = 100
Dim y As Integer = 200
Dim result As Integer
  
result = themax(x , y)
Console.WriteLine("Max value is : {0}", results)
Console.ReadLine()
End Sub
End Module

so here i have defined a function and used it to find larger of the two numbers

2. two dimension array -this can be done by just using a comma while defining array as shown below two d arrays are used in the same way as one d array . its a data structure for accessing sequential data

Module twodimensionalarray
Sub Main()
' a comma sign is used to show a two d array array2(,)
Dim array2(,) As Integer = {{0, 1}, {2, 2}, {2, 3}, {4, 8}, {9, 8}}
Dim a, b As Integer
' print arrays value
  
For a = 0 To 4
For b = 0 To 1
Console.WriteLine("array2[{0},{1}] = {2}", i, j, array2(a, b))
Next b
Next a
Console.ReadKey()
End Sub
End Module

3.Structures: here we have defined a structure of a  cuboid

it contains the measurement of 3 sides of a cuboid , structures are just like classes , they contain both variables and methods (for calculating volume) in the main function we have also declared a box1 and also assigned its dimension , we could have also used the function volume   

Public Module HomeworkLib_structure
Public Structure cuboid
Dim len As Double
Dim breadth As Double
Dim height As Double

Function volume_of_the_box() As Double
Return len * breadth * tall
End Function
End Structure

Public Function Main() As Integer
Dim box1 As cuboid

box1.len = 22.84
box1.breadth = 18.05
box1.tall = 12.94

MsgBox("cuboid Characteristics" & vbCrLf & _
"len:" & vbTab & FormatNumber(box1.len) & vbCrLf & _
"breadth:" & vbTab & FormatNumber(box1.breadth) & vbCrLf & _
"tall:" & vbTab & FormatNumber(box1.tall))

Return 0
End Function
End Module

4 . Muntiple forms:forms are the containers for defining all the controls that deals with user interaction . here we are making a very basic form , i have defined my code using the comments

Public Class HomeworkLib_form
Private Sub HomeworkLib_form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'lets start with the first menu
Dim menu_bar As New MainMenu()
'now since we have th emenu we can add whatevr kind of items we want
Dim Item_file As New MenuItem("&File")
Dim Item_save As New MenuItem("&Save")
Dim item_saveas As New MenuItem("&Save_AS")
Dim item_viewAs New MenuItem("&View")

'addingthe above item to alraedy declared menu
menu_bar.MenuItems.Add(Item_file )
menu_bar.MenuItems.Add(Item_save)
menu_bar.MenuItems.Add(item_saveas)
menu_bar.MenuItems.Add(item_viewt)

' lets define some menus that are sub menus
Dim sub_menu_new As New MenuItem("&New")
Dim sub_menu_open As New MenuItem("&Open")
Dim sub_menu_save As New MenuItem("&Save")

'lets add our sub menu to our File
Item_file .MenuItems.Add(sub_menu_new)
Item_file .MenuItems.Add(sub_menu_open)
Item_file .MenuItems.Add(sub_menu_save)

'now lets add everything to the form so that we can post it
Me.Menu = menu_bar

' now we can give the topic of the form using the .text function
Me.Text = "HomeworkLib_expert"
End Sub
End Class

5 . Modules : v the code in VB is segmented and saved in modules so it saves each form in such modules with .vb extension

so we start with the module name and then define it

Module HomeworkLib

   Public Sub helloHomeworkLib()

        MessageBox.Show("HomeworkLib")


   End Sub

End Module

ALL THE PROGRAMS GIVEN ABOVE ARE IN FORM OF MODULES

EXAMPLE HERE

Module twodimensionalarray
Sub Main()
' a comma sign is used to show a two d array array2(,)
Dim array2(,) As Integer = {{0, 1}, {2, 2}, {2, 3}, {4, 8}, {9, 8}}
Dim a, b As Integer
' print arrays value
  
For a = 0 To 4
For b = 0 To 1
Console.WriteLine("array2[{0},{1}] = {2}", i, j, array2(a, b))
Next b
Next a
Console.ReadKey()
End Sub
End Module

6 . COMING OVER TO PARALLEL ARRAYS: parallel arrays are used when we have linked data but of different data types , for example students name is a string his marks are integer so to accommodate it we make two arrays at each index the data are related or linked


'parallel arrays for students name and their marks
'the first array of names
Dim name() As String = {"john", "ken"}
'2nd array for marks
Dim marks() As Integer = {72, 98}

'we will loop it through the index using a for loop and after theat we can print indivisually
'Array.GetUpperBound(0) gives the location of last element

For counter As Integer = 0 To name.GetUpperBound(0)
Label1.Text = Label1.Text & name(counter) & ": " & marks(counter) & vbCrLf
Next
vbCrLf is for vb to recognize enter click

the code is explained using comments if you want a key value pair you will have to use a dictionary instead of array , i will show a little example

Module HomeworkLib
Sub Main()
' declaring a new dictionary object for key value pair .
Dim dict As New Dictionary(Of String, Integer)

' add some keys
dictionary.Add("ken", 75)
dictionary.Add("perl", 85)
dictionary.Add("mark", 100)
' check if key already there .
If dictionary.ContainsKey("ken") Then
' so now we can print marks .
Dim marks As Integer = dictionary.Item("ken")
Console.WriteLine(marks)
End If

'check if the key doesnt exist if not we can print it doesnt exist
If dictionary.ContainsKey("python") Then
Console.WriteLine(False)
End If
End Sub
End Module

  

 
Add a comment
Know the answer?
Add Answer to:
In Visual Studio 2015, Write a review assignment that includes, functions, two dimension array, parallel array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4...

    Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4 x 5 two-dimensional array. The program should use loops to populate the array using the rand, srand and time functions with random numbers between 10 and 60. After the values have populated the array, output the values of the array to the screen in something that looks like a 4 x 5 table.

  • Write 4 different Unit Tests for this c++ method using assert functions with visual studio. /*...

    Write 4 different Unit Tests for this c++ method using assert functions with visual studio. /* returns sum of the subarray strating from index start a is the array, n is size of the array start in the starting index of the subarray */ int subArraySum(int a[], int n, int start) {    int sum = 0;    for (int i = start; i < n; i++)        sum += a[i];    return sum; }

  • Please write below code in C++ using Visual Studio. Write program that uses a class template...

    Please write below code in C++ using Visual Studio. Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) • Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 • Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the...

  • 1. Write a C programme by using visual Studio: a) Write a function with parameters that...

    1. Write a C programme by using visual Studio: a) Write a function with parameters that returen the largest of three integer arguments. So users could call your function (name: max3) to output the maximum of three input values. b) Make a function outside of the main routine. And in the main routine, please call this function and print the harmonic mean. The harmonic mean of two numbers is obtained by taking the inverses of the two numbers, averaging them,...

  • This is my question in Microsoft Visual Studio: In many settings, it is necessary to gather...

    This is my question in Microsoft Visual Studio: In many settings, it is necessary to gather input in forms sometimes in conjunction with a database but often also a standalone process. As we can see from the reading, many different controls exist to help gather input from a form. Using assignment operators, variables store information in RAM while the program executes. Write a form using multiple text boxes to gather input that includes: 1. the name of the patient 2....

  • Exercise 2 Using javascript (visual studio code) (a) Write code that creates 5 item objects (records)...

    Exercise 2 Using javascript (visual studio code) (a) Write code that creates 5 item objects (records) (b) Place the five item objects into an array (c) Write a function that prints an array of your items it has one parameter an array of items (d) Write a function that counts items that match some attribute value. (e) Write a function that filters an array of items. It has three parameter an array of item, an attribute name and a value....

  • No. 7 7th question i want this code to be done on c++ visual studio without...

    No. 7 7th question i want this code to be done on c++ visual studio without using bool operation. and please try to make as simple as possible. Also i need flowchart for the code thanks. Q7 I need a code programmed on c++ visual studios. Also flowchart of the code. Try to make it simple college level understandable code. thanks. b. wg. Prompt the user to input the value of a double variabler, which stores the radius of a...

  • If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but...

    If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...

  • In this assignment, you are to write a C++ program (using Visual C++ 2015) that reads...

    In this assignment, you are to write a C++ program (using Visual C++ 2015) that reads training data in WEKA arff format and generates ID3 decision tree in a format similar to that of the tree generated by Weka ID3. Please note the following: Your algorithm will use the entire data set to generate the tree. You may assume that the attributes (a) are of nominal type (i.e., no numeric data), and (b) have no missing values. In general, the...

  • Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually...

    Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually kind of confusing to me. I keep getting lost in all of the words even though these are supposed to instruct me as to how to do this. Can I please get some help as to where to start? Word guessing game: Overview: Create a game in which the user has a set number of tries to correctly guess a word. I highly recommend...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT