-
1 ' Fig. 7.5: StudentPoll.vb
-
2 ' Using arrays to display poll results.
-
3
-
4 Imports System.Windows.Forms
-
5
-
6 Module modStudentPoll
-
7
-
8 Sub Main()
-
9 Dim answer, rating As Integer
-
10 Dim output As String
-
11
-
12 ' student response array (typically input at run time)
-
13 Dim responses As Integer()
-
14 responses = New Integer() {1, 2, 6, 4, 8, 5, 9, 7, _
-
15 8, 10, 1, 6, 3, 8, 6, 10, 3, 8, 2, 7, 6, 5, 7, 6, _
-
16 8, 6, 7, 5, 6, 6, 5, 6, 7, 5, 6, 4, 8, 6, 8, 10}
-
17
-
18 ' response frequency array (indices 0 through 10)
-
19 Dim frequency As Integer() = New Integer(10) {}
-
20
-
21 ' count frequencies
-
22 For answer = 0 To responses.GetUpperBound(0)
-
23 frequency(responses(answer)) += 1
-
24 Next
-
25
-
26 output &= "Rating " & vbTab & "Frequency " & vbCrLf
-
27
-
28 For rating = 1 To frequency.GetUpperBound(0)
-
29 output &= rating & vbTab & frequency(rating) & vbCrLf
-
30 Next
-
31
-
32 MessageBox.Show(output, "Student Poll Program", _
-
33 MessageBoxButtons.OK, MessageBoxIcon.Information)
-
34 End Sub ' Main
-
35
-
36 End Module ' modStudentPoll
-
Fig. 7.5
-
-
4 1493 Rabbit 12,516
Recognized Expert Moderator MVP
What line 23 does is take the answer given in response and increments the freqency array at that index. So if the response is 2, then it adds one to frequency(2). Which means that the number at frequency(2) is the number of people that responded with an answer of 2.
Thanks Rabbit but i still didn't get you well,line 23 says
frequency(respo nse(answer))+=1 now when answer is 0 response(0)=1 then it becomes frequency(1)+=1 now is the 1 in the frequency(1)ref erencing an index?
Rabbit 12,516
Recognized Expert Moderator MVP
It doesn't become frequency(1). frequency(0) would = 1 in your example. frequency(1) would still = 0 until someone answers 1. - response = (1,2,1)
-
response(0) = 1
-
response(1) = 2
-
response(2) = 1
-
-
frequency(0) = 0
-
frequency(1) = 0
-
frequency(2) = 0
-
-
frequency(response(0)) += 1
-
frequency(1) += 1
-
frequency(1) = 1
-
-
frequency(response(1)) += 1
-
frequency(2) += 1
-
frequency(2) = 1
-
-
frequency(response(2)) += 1
-
frequency(1) += 1
-
frequency(1) = 2
That code computes how many times a certain response was given. A response can be between 1 and 10. So,
frequency(1) = frequency of response 1 = how many times 1 appears in responses.
frequency(7) = frequency of response 7 = how many times 7 appears in responses.
Now, since you have an array of responses, from 0 to responses.getup perbound(0), you cycle through this array and you increment the value of the corresponding frequency of the response when found. In other words, if response(i) = 8, you have frequency(8) +=1. Which is what line 23 is doing, frequency(respo nse(i))+=1. In your code 'i' = 'answer' as the iterator in the loop.
Also, x += y means x = x+y
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Chris |
last post by:
Hello
Could anyone explain why the following:
#footer ul
{
float : left;
margin : 2px 0px 7px 28px;
padding : 0px;
width : 360px;
|
by: Chris |
last post by:
Could anyone write a small program to log the Signal-to-Noise figures
for a Netgear DG834 router?
I have been getting very variable SNR readings - and I would like to
collect some evidence to analyse.
What is needed is a program that logs into the router's html page every
minute, and then extracts the time and the SNR figure, and writes a line
of a text file.
|
by: C++fan |
last post by:
The following code is for list operation. But I can not understand.
Could anyone explain the code for me?
/*
* List definitions.
*/
#define LIST_HEAD(name, type)
struct name {
type *lh_first; /* first element */
|
by: Mike |
last post by:
I got the code below from an earlier post but I can't get it to work
(I get an error on the "for (i=0; i<a.length; i++)" line) Anyone have
code that works for cookies with keys?
> Anyone got any code out there that will set and retrieve
> cookie values that have the key/subKey structure?
Using the code provided below, examine
|
by: Wiktor Zychla [C# MVP] |
last post by:
Could anyone confirm/deny that following is a bug (or at least an
"unexpected behaviour")?
If this is not a bug, I would be glad for a short explanation or a
workaround.
Issue:
A generic class, Base, with a constraint on the generic parameter.
A generic class, RelTable, with a constraint on two generic parameters.
A reflection code that just enumerates types, methods and methods'
| |
by: Andrew |
last post by:
Hello, friends,
I am implementing web app security using asp.net 1.1, and I found the
following source code from Yahoo! Mail login page:
<form method="post" action="https://login.yahoo.com/config/login?"
autocomplete="off" name="login_form">
<input type="hidden" name=".tries" value="1">
<input type="hidden" name=".src" value="ym">
<input type="hidden" name=".md5" value="">
|
by: Sean Hammond |
last post by:
Anyone understand this?
Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
on linux2
Type "help", "copyright", "credits" or "license" for more information.
.... """Send 'input' (string) to the markdown perl script, and return
the
.... output from markdown (string).
....
.... input: a string of markdown-formatted text, including \n's at
|
by: eric_jin |
last post by:
i called function show() in a c# webservice
//show.m
function ans=show(x)
ans=x;
it works;
but when i try to call add(),it breaks;
//add.m
|
by: Steel546 |
last post by:
I want to understand why certain functions do certain things. Such as in a linked list, I'm looking for the source code behind the list.at(), or list.resize() functions.
cplusplus.com only gives references, but does anyone know where to find the behind the scenes work? Thanks.
|
by: kepbem |
last post by:
I am new to this forum, i have created this database, however the timetables will not reset themselves. They have done previously, can anyone help?
Option Compare Database
Option Explicit
'------------------------------------------------------------
' Macro1
'
'------------------------------------------------------------
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |