|
-
Dec 5th, 2007, 07:32 AM
#1
Thread Starter
New Member
3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
Hello All, Firstly let me introduce myself, I'm Jim, from a University in England studying Computing, with a sub module of programming.
I've always found grasping programming to be a hard subject, i understand some of the basic theorys, but it's just a little frustrating when my lecturer doesn't really take into consideration that not EVERYONE is at the same level, thus as weeks go by, its very easy to find yourself trailing off course.
I've asked for advice from the lecturer, but received no further help, thus making me purchase and borrow books to read from.. As you can tell.. I'm not too happy!
This post was NOT intended for a quick fix for my problems within the assignment i've been given, i just need a good supportive background to help me with my assignment.
The assignment
Write a program in VB.NET to process a series of exam marks. Input boxes are to be used for input and text boxes for output. The font of the text box should be set to Courier New (so that every character occupies the same width) and to size 8. Set ScrollBars to Both, and Multi-line to True.A single button should initiate the calculation.
For testing/debugging purposes you may also find it useful to create a button which uses the TextBox1.Clear() instruction to clear any text boxes.
Graduated Tasks - task 1 - Statistics - (10 marks)
The program should accept a series of exam marks, ended by -1. When the -1 is entered, it should display the following results in a text box, using AppendText, and it should display a "Done" message box when terminating.
Task Mark
The average (mean) mark 4
The smallest and largest mark. 3
"Great work" if at least 30% of the students passed (got 40% or above). If not, it should display "High failure rate" 3
Task 2 - Histogram - (5 marks)
You should write code to display a bar chart of the marks in another text box, as in:
----------------------------------------------------
|Mark |
|13 ************* |
|21 ********************* |
|7 ******* |
| ...etc |
| |
| |
| |
----------------------------------------------------
Do not take account of marks which don't fit across. Note that the asterisks should ideally start from the same character position.
.
Task 3 - Copying - (10 marks)
Assume that the marks have been entered in order of seating, and the lecturer suspects copying from nearby students. In the case that three adjacent students have identical marks, display the following before the average: their mark, and their three positions.
Example
Suspect mark: 51
Students numbered: 13 14 15
Do not use an array , string, file, or collection for this task. Assume that only one group of copiers exists
Program style - (6 marks)
Item Mark
Uses a procedure (sub) 2
Naming 2
Comments 2
Is there any positive and easy way to learn around this, I'm just trying to grasp the assigment..
Would really appreciate if anyone would be able to offer guidence / support.
Much appreciated.
J
-
Dec 5th, 2007, 07:56 AM
#2
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
Welcome to the forums Jim 
We won't write the code for you, but we will be more than happy to help you write it for yourself.
What do you have so far regarding this assignment?
-
Dec 5th, 2007, 08:15 AM
#3
Thread Starter
New Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
Hello Hack, thanks for your reply.
I've been given this assignment now around a week ago.
I just think its amazing how programs work, and how the programmers mind works. I'm sure i lack the logical confidence somewhere in my span!
So far, i'm trying to stay away from the actual coding/ visual basic application as i can, i've been reading various books, such as [KENT, Jeff 2006) "Visual Basic 2005 - DeMystified"]
Its pretty hard to read a book and say "Aaah right.. I can just use that in a project". Your creating Code from scratch, so obviously theres going to be no exact template anywhere to follow. I'm just jotting ideas and flow charts on paper, so i can get the idea physically, then convert this to logic.
I'm starting from the very basics, as this is my first year in Programming, i've got a very good feeling i need to understand THIS first, because i'll be working on a various amount of languages.
I'm just reading about numerical values, order and different operators at this time, especially looking at "Loops". It all seems rather mystical, but i'm sure somehow, somewhere i can learn it. And the most frustrating thing is, i WANT to learn it.
Many thanks. Just like to say what an imformative site, i've been following some of the tut's etc on here.
James
-
Dec 5th, 2007, 09:02 AM
#4
Lively Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
I don't know how much you actually know about programming, but the logic and syntax are the only things you really need to worry about. Doesn't matter what kind of language you write in, as long as you understand the logic.
To make the flow of a program easier on the eyes of some beginners, I've found, is to worry about only one aspect of the program and get that working. The design of the form is simple enough given Visual Studio and it's design center. My suggestion would be to focus on the first task and don't worry about the rest of the assignment. If you can't get the first one done anyways, it won't help you at all.
Let us know what you come up with on your own. Doesn't even have to be code...just an idea of what you're gonna input, how you'll calculate it, where you'll store it, and how it'll be outputed.
*mrow*
-
Dec 5th, 2007, 04:39 PM
#5
Thread Starter
New Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
Hello All, thanks for your reply's!
I've been working on it all afternoon on the laptop..
Here's what i've got SO FAR;
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim number As Double
Dim smallestSoFar As Double
Dim biggestSoFar As Double
Dim counter As Integer
Dim total As Double
Dim average As Double
smallestSoFar = 100000 ' has to be bigger than any of the input numbers
number = CDbl(InputBox("Enter Mark"))
While number <> -1 'enter -1 to terminate the program
counter = counter + 1
total = total + number
average = total / counter
'hmmmmmmmm
If number < smallestSoFar Then smallestSoFar = number 'If number is smallest of the inputted numbers, display lowest
If number > smallestSoFar Then biggestSoFar = number ' If number is Biggest of the inputted numbers, display lowest
number = CDbl(InputBox("Please enter the exam mark. To terminate the program and display results, please press -1"))
End While
MessageBox.Show("Done")
txtResult.AppendText(" Smallest Score is " & smallestSoFar & vbCrLf)
txtResult.AppendText(" Biggest Score " & biggestSoFar & vbCrLf)
txtResult.AppendText(" Average Score is " & average & vbCrLf)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
txtResult.Clear()
End Sub
End Class
Just a little stuck on the;
"Great work" if at least 30% of the students passed (got 40% or above). If not, it should display "High failure rate" 3
Hmmmmmmm
-
Dec 5th, 2007, 05:01 PM
#6
Thread Starter
New Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
I tell a lie,
This is what i have so far, i've got a feeling its not correct, but i'm trying to work around it!
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim number As Double
Dim smallestSoFar As Double
Dim biggestSoFar As Double
Dim counter As Integer
Dim total As Double
Dim average As Double
Dim passMark As Integer
smallestSoFar = 100000 ' has to be bigger than any of the input numbers
number = CDbl(InputBox("Enter Mark"))
While number <> -1 'enter -1 to terminate the program
counter = counter + 1
total = total + number
average = total / counter
passMark = average / 100 * 40
'hmmmmmmmm
If number < smallestSoFar Then smallestSoFar = number 'If number is smallest of the inputted numbers, display lowest
If number > smallestSoFar Then biggestSoFar = number ' If number is Biggest of the inputted numbers, display lowest
number = CDbl(InputBox("Please enter the exam mark. To terminate the program and display results, please press -1"))
End While
MessageBox.Show("Done")
txtResult.AppendText(" Smallest Score is " & smallestSoFar & vbCrLf)
txtResult.AppendText(" Biggest Score " & biggestSoFar & vbCrLf)
txtResult.AppendText(" Average Score is " & average & vbCrLf)
txtResult.AppendText(" Pass Mark on the average is " & passMark & vbCrLf)
If passMark >= 40 Then
MessageBox.Show("Pass! Great Work!")
Else
MessageBox.Show("High Fail Rate")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
txtResult.Clear()
End Sub
End Class
But hmmmmmm
-
Dec 5th, 2007, 05:04 PM
#7
Frenzied Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
I know a fair amount about VB, but I don't understand what you have to do (thank God im not in college LOL)...
So you just enter values into an input box, and when you type -1, it's suppost to add them all up? or what?
-
Dec 5th, 2007, 05:09 PM
#8
Thread Starter
New Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
Yes thats it, but i have a RUNNING Total of Exam Marks, at the end i want to display "Great Work if 30% of the exam marks are >= 40%"
Confusing i know...
-
Dec 5th, 2007, 05:28 PM
#9
Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
You just need to add another count to your loop that is incremented by one if and only if the score is 40% or more. At the end, count / total is the % you need to look at when deciding which message to show.
You should also validate that only numbers are entered in the input box by using Double.Parse and probably that all marks fall in the range 1-100.
-
Dec 5th, 2007, 05:48 PM
#10
Thread Starter
New Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
 Originally Posted by sdfax_work
You just need to add another count to your loop that is incremented by one if and only if the score is 40% or more. At the end, count / total is the % you need to look at when deciding which message to show.
You should also validate that only numbers are entered in the input box by using Double.Parse and probably that all marks fall in the range 1-100.
You've got my brain ticking away now...
-
Dec 5th, 2007, 06:24 PM
#11
Frenzied Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
Isn't the highlighted variable the wrong one for the indicated calculation?
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim number As Double
Dim smallestSoFar As Double
Dim biggestSoFar As Double
Dim counter As Integer
Dim total As Double
Dim average As Double
smallestSoFar = 100000 ' has to be bigger than any of the input numbers
number = CDbl(InputBox("Enter Mark"))
While number <> -1 'enter -1 to terminate the program
counter = counter + 1
total = total + number
average = total / counter
If number < smallestSoFar Then smallestSoFar = number 'If number is smallest of the inputted numbers, display lowest
If number > smallestSoFar Then biggestSoFar = number ' If number is Biggest of the inputted numbers, display lowest
number = CDbl(InputBox("Please enter the exam mark. To terminate the program and display results, please press -1"))
End While
MessageBox.Show("Done")
txtResult.AppendText(" Smallest Score is " & smallestSoFar & vbCrLf)
txtResult.AppendText(" Biggest Score " & biggestSoFar & vbCrLf)
txtResult.AppendText(" Average Score is " & average & vbCrLf)
End Sub
-
Dec 5th, 2007, 06:52 PM
#12
Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
Your input box is not inside the while loop. So the input box will only appear once each time you press the button. Is that what you are going for? From the description it sounded as if the input boxes should keep coming up until -1 is entered.
-
Dec 5th, 2007, 07:09 PM
#13
Frenzied Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
Code:
Yes thats it, but i have a RUNNING Total of Exam Marks, at the end i want to display "Great Work if 30% of the exam marks are >= 40%
I understand that, you enter '4' then '3', that is 2 Exam marks right? what determines if they are >= 40%? what is there to compare?
40% of what, 40% are correct values?
if 30% of the values entered are >= 40%, 40% of what?
-
Dec 6th, 2007, 02:53 AM
#14
Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
 Originally Posted by jimbo89
"Great work" if at least 30% of the students passed (got 40% or above). If not, it should display "High failure rate" 3
implies marks are percentages from 0% to 100%. You simply need to compare the mark input against 40 to check for a pass.
Also FourMarks is right about the smallestSoFar variable. You should be comparing with biggestSoFar to set the biggestSoFar variable. biggestSoFar should be initialised at 0 and smallestSoFar should be initialised at the maximum score of 100.
On a sidenote, you really also use a variable name like "mark" rather than "number" (which is meaningless) and construct a loop that will always execute at least once, e.g.
Code:
Do
....
Loop While (mark <> -1)
Hope this helps
-
Dec 13th, 2007, 11:02 AM
#15
Thread Starter
New Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
hello, Firsly a apologise about the wait, i've just turned an uncle, so its been a real tense time with my sister!
Back to the coding.
Yes. I have completed the first task of displaying the MEAN, highest and lowest marks entered. All im lost now is the end part of task one which asks me to " "Great work" if at least 30% of the students passed (got 40% or above). If not, it should display "High failure rate" 3"
I know one or two of you have replied with excellent answers, but believe you me i just cant get the thing to work. I know i need to include another loop. This is what i have so far, i'm starting again from the end of task 1.
Code:
Dim mark As Double
Dim smallestSoFar As Double
Dim biggestSoFar As Double
Dim counter As Integer
Dim total As Double
Dim average As Double
Dim passMark As Integer
smallestSoFar = 100 ' has to be bigger than any of the input numbers
biggestSoFar = 0
mark = CDbl(InputBox("Enter Mark"))
While (mark <> -1) 'enter -1 to terminate the program
counter = counter + 1
total = total + mark
average = total / counter
*
If mark < smallestSoFar Then smallestSoFar = mark 'If number is smallest of the inputted numbers, display lowest
If mark > biggestSoFar Then biggestSoFar = mark ' If number is Biggest of the inputted numbers, display biggest
mark = CDbl(InputBox("Enter Mark"))
End While
MessageBox.Show("Done")
txtResult.AppendText(" Smallest Score is " & smallestSoFar & vbCrLf)
txtResult.AppendText(" Biggest Score " & biggestSoFar & vbCrLf)
txtResult.AppendText(" Average Score is " & average & vbCrLf)
*
If passMark >= 40 Then
MessageBox.Show("Pass! Great Work!")
Else
MessageBox.Show("High Fail Rate")
End If
Any further tips and OR tricks would be absolutly brill.I'm getting lost with this assignment, nevermind the 10 others i've currently got to complete!
Cheers, and many thanks.
-
Dec 13th, 2007, 03:51 PM
#16
Frenzied Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
well, I'd try having a if statement under the 'Mark = CDbl(InputBox)' part, which is
Public MarksPassed As Integer = 0
Public MarksFailed As Integer = 0
(Declare those variables at the top of your Form1 class, or frmMain etc..)
vb.net Code:
If Mark > 29 Then '>= 30 passes
MarksPassed += 1
Else
MarksFailed += 1
End If
and then down where you append the rest of your values when it is complete,
vb.net Code:
Dim pct As Double = (MarksPassed/MarksFailed) * 10
txtResult.AppendText("Percentage passed " & pct)
that should do it...
I would like to mention, I noticed this piece of code will cause an error if you enter a letter or non numerical character into the input box
vb.net Code:
mark = CDbl(InputBox("Enter Mark"))
I would do this instead
vb.net Code:
While 0 < 1
If Double.TryPass(InputBox("Enter Mark"), Mark) Then
Exit While
Else
MsgBox("Please enter a correct value.")
End If
End While
That way it won't exit the loop until you've entered a correct value.
Cheers
Last edited by Icyculyr; Dec 13th, 2007 at 03:55 PM.
-
Dec 14th, 2007, 04:47 AM
#17
Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
The last post is confused. The pass mark is 40, not 30. The % calc is also incorrect. The percentage should simply be marks passed / total marks x 100. You just need two counters in your loop. One that increments every time and one that increments if and only if the mark is >=40.
There is no need to count marksFailed in order to calculate the pass rate.
E.g.
marks = {15, 55, 85, 25}
=> 2 passed, 4 marks in total
=> 2/4 x 100%
=> 50% of students passed.
=> Display Great Work
-
Dec 16th, 2007, 02:15 PM
#18
Thread Starter
New Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
Thank you, VERY much for your reply regarding this.
I havn't used the direct coding, but i have used it in conjunction with the visual basic books i'm currently borrowing from Uni.
I've searched, searched and searched for info on "Histograms", i basically have to display my results on a histogram, but i'm not too sure, i'm heading towards "nested loops", but i just want to make sure before i make some form of a commitment!
Many thanks.
J
-
Dec 16th, 2007, 04:17 PM
#19
Frenzied Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
The % calc is also incorrect. The percentage should simply be marks passed / total marks x 100.
I thought something was wrong, it has been a long time since I used anything like this... :P
vb.net Code:
While 0 < 1
If Double.TryPass(InputBox("Enter Mark"), Mark) Then
Exit While
Else
MsgBox("Please enter a correct value.")
End If
End While
If Mark > 39 Then '>= 40 passes
MarksPassed += 1
End If
MarksTotal += 1
Dim pct As Double = (MarksPassed/MarksTotal) * 100
txtResult.AppendText("Percentage passed " & pct)
Tell me if that works...
-
Dec 16th, 2007, 06:05 PM
#20
Frenzied Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
As for the histogram, that should be easy, what do you have so far..
and also, I don't quite understand what he wants you to do though?
Do not take account of marks which don't fit across. Note that the asterisks should ideally start from the same character position.
Fit across what?
and also, what decides how many asterisks there is?
would I be correct in saying that 5 students get 60% and he wants you to show that or what? should it show the pass rate? etc..?
-
Dec 16th, 2007, 06:13 PM
#21
Thread Starter
New Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
 Originally Posted by Icyculyr
As for the histogram, that should be easy, what do you have so far..
and also, I don't quite understand what he wants you to do though?
Fit across what?
and also, what decides how many asterisks there is?
would I be correct in saying that 5 students get 60% and he wants you to show that or what? should it show the pass rate? etc..?
Thats it. I dont mean to put the lecturer down, but he really needs to re-phrase the question alot more clearly so the rest of the group can understand. The entire class has NO knowledge or even understanding off the assignment, you ask for help, you get "Well thats mine to know".. And you think i'm joking. I've even enquired about the logic, with little success!
Back to the question.
I guess i have to take the results OR the Counter results and display them in a histogram of asterisks...Sounds logical or not,
-
Dec 16th, 2007, 06:45 PM
#22
Frenzied Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
Well, I have no idea what he means :P if anyone else reading this cares to shed some light, however...
with 'copying' that seems interesting...
Assume that the marks have been entered in order of seating, and the lecturer suspects copying from nearby students. In the case that three adjacent students have identical marks, display the following before the average: their mark, and their three positions.
Example
Suspect mark: 51
Students numbered: 13 14 15
Do not use an array , string, file, or collection for this task. Assume that only one group of copiers exists
So I guess he wants you to find the three cheaters, without using an array, string, file, or collection... hmm
that makes sense, but how would you do it not using an array?
I assume he will enter 3 values that are the same, but how are you to refer to them then?
Does he enter the mark that he thinks is suspicious? or select a student?
-
Dec 16th, 2007, 06:49 PM
#23
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
For the histogram, try running this code and it should give you a big clue as to how to go about creating it:
Code:
Dim sb As New System.Text.StringBuilder
For i As Integer = 1 To 10
sb.Append(i.ToString().PadRight(3))
For j As Integer = 1 To i
sb.Append("*"c)
Next j
sb.AppendLine()
Next i
MessageBox.Show(sb.ToString())
Note that if you use a TextBox with a fixed-width Font then the first asterisk in each row will be in the same column.
-
Dec 16th, 2007, 07:07 PM
#24
Thread Starter
New Member
Re: 3 Cups of Coffee & 2 hours later.. Undergrad. Requires Help!
Thank you Very much for your response.
Give me a bit of time to have a look through the coding, then i shall strive to see if i can get it to work, i already know i have to display it as a appendtext function for the textbox.
Cheers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|