Visual basic 2010 lab homework
Page 1 of 111 Replies - 1308 Views - Last Post: 15 October 2012 - 09:33 PM
#1
Visual basic 2010 lab homework
Posted 11 October 2012 - 01:19 PM
5. Falling Distance
When an object is falling because of gravity, the following formula can be used to
determine the distance the object falls in a specific time period:
d = .5 * g * t^2
The variables in the formula are as follows: d is the distance in meters, g is 9.8, and
t is the amount of time, in seconds, that the object has been falling.
Design a function named fallingDistance that accepts an object’s falling time (in
seconds) as an argument. The function should return the distance, in meters, that the
object has fallen during that time interval. Design a program that calls the function in
a loop that passes the values 1 through 10 as arguments and displays the return value.
7. Test Average and Grade
Write a program that asks the user to enter five test scores. The program should
display a letter grade for each score and the average test score. Design the follow-
ing functions in the program:
● calcAverage—This function should accept five test scores as arguments and
return the average of the scores.
● determineGrade—This function should accept a test score as an argument
and return a letter grade for the score (as a String), based on the following
grading scale:
Score Letter Grade
90–100 A
80–89 B
70–79 C
60–69 D
Below 60 F
Replies To: Visual basic 2010 lab homework
#2
Re: Visual basic 2010 lab homework
Posted 11 October 2012 - 01:29 PM
#3
Re: Visual basic 2010 lab homework
Posted 11 October 2012 - 01:34 PM
Perform the calculation using your const g which you should define before the loop
As far as where to put the results of each iteration that solves for d, well, that could be an array, a listbox multiple messageboxes. Not sure what you've already learned and where to apply that knowledge but once you have the value of d, the rest should just be displaying d.
#4
Re: Visual basic 2010 lab homework
Posted 15 October 2012 - 12:32 PM
On the other hand number 7 seems to be a bit tricky, and I bet if I didn't lose my notes for last class it wouldn't be.
I've got number seven done, but I know that he wants me to do it differently.
There is a screen shot at the end of this page attached of what my program looks like executed with sample scores inputted
So far this is what I have for number 7 in code:
Module Module1
Dim scr1, scr2, scr3, scr4, scr5, startingscore As Integer
Dim avg As Decimal
Sub Main()
calcAverage()
determineGrade()
End Sub
Sub calcaverage()
Console.WriteLine("Enter five test scores")
Console.Write("Enter score #1:")
scr1 = Console.ReadLine
' Validate
While scr1 < 0 Or scr1 > 100
Console.WriteLine("Error! Score must be 0-100")
Console.WriteLine("Please try again")
Console.WriteLine("Enter score #1:")
scr1 = Console.ReadLine
End While
Console.Write("Enter score #2:")
scr2 = Console.ReadLine
' Validate
While scr2 < 0 Or scr2 > 100
Console.WriteLine("Error! Score must be 0-100")
Console.WriteLine("Please try again")
Console.WriteLine("Enter score #2:")
scr2 = Console.ReadLine
End While
Console.Write("Enter score #3:")
scr3 = Console.ReadLine
' Validate
While scr3 < 0 Or scr3 > 100
Console.WriteLine("Error! Score must be 0-100")
Console.WriteLine("Please try again")
Console.WriteLine("Enter score #3:")
scr3 = Console.ReadLine
End While
Console.Write("Enter score #4:")
scr4 = Console.ReadLine
' Validate
While scr4 < 0 Or scr4 > 100
Console.WriteLine("Error! Score must be 0-100")
Console.WriteLine("Please try again")
Console.WriteLine("Enter score #4:")
scr4 = Console.ReadLine
End While
Console.Write("Enter score #5:")
scr5 = Console.ReadLine
' Validate
While scr5 < 0 Or scr5 > 100
Console.WriteLine("Error! Score must be 0-100")
Console.WriteLine("Please try again")
Console.WriteLine("Enter score #5:")
scr5 = Console.ReadLine
End While
avg = (scr1 + scr2 + scr3 + scr4 + scr5) / 5
End Sub
Sub determinegrade()
If scr1 < 60 Then
Console.WriteLine("Score #1 letter grade:")
Console.WriteLine("F")
End If
If scr1 >= 60 And scr1 < 70 Then
Console.WriteLine("Score #1 letter grade:")
Console.WriteLine("D")
End If
If scr1 >= 70 And scr1 < 80 Then
Console.WriteLine("Score #1 letter grade:")
Console.WriteLine("C")
End If
If scr1 >= 80 And scr1 < 90 Then
Console.WriteLine("Score #1 letter grade:")
Console.WriteLine("B")
End If
If scr1 >= 90 Then
Console.WriteLine("Score #1 letter grade:")
Console.WriteLine("A")
End If
If scr2 < 60 Then
Console.WriteLine("Score #2 letter grade:")
Console.WriteLine("F")
End If
If scr2 >= 60 And scr2 < 70 Then
Console.WriteLine("Score #2 letter grade:")
Console.WriteLine("D")
End If
If scr2 >= 70 And scr2 < 80 Then
Console.WriteLine("Score #2 letter grade:")
Console.WriteLine("C")
End If
If scr2 >= 80 And scr2 < 90 Then
Console.WriteLine("Score #2 letter grade:")
Console.WriteLine("B")
End If
If scr2 >= 90 Then
Console.WriteLine("Score #2 letter grade:")
Console.WriteLine("A")
End If
If scr3 < 60 Then
Console.WriteLine("Score #3 letter grade:")
Console.WriteLine("F")
End If
If scr3 >= 60 And scr3 < 70 Then
Console.WriteLine("Score #3 letter grade:")
Console.WriteLine("D")
End If
If scr3 >= 70 And scr3 < 80 Then
Console.WriteLine("Score #3 letter grade:")
Console.WriteLine("C")
End If
If scr3 >= 80 And scr3 < 90 Then
Console.WriteLine("Score #3 letter grade:")
Console.WriteLine("B")
End If
If scr3 >= 90 Then
Console.WriteLine("Score #3 letter grade:")
Console.WriteLine("A")
End If
If scr4 < 60 Then
Console.WriteLine("Score #4 letter grade:")
Console.WriteLine("F")
End If
If scr4 >= 60 And scr4 < 70 Then
Console.WriteLine("Score #4 letter grade:")
Console.WriteLine("D")
End If
If scr4 >= 70 And scr4 < 80 Then
Console.WriteLine("Score #4 letter grade:")
Console.WriteLine("C")
End If
If scr4 >= 80 And scr4 < 90 Then
Console.WriteLine("Score #4 letter grade:")
Console.WriteLine("B")
End If
If scr4 >= 90 Then
Console.WriteLine("Score #4 letter grade:")
Console.WriteLine("A")
End If
If scr5 < 60 Then
Console.WriteLine("Score #5 letter grade:")
Console.WriteLine("F")
End If
If scr5 >= 60 And scr5 < 70 Then
Console.WriteLine("Score #5 letter grade:")
Console.WriteLine("D")
End If
If scr5 >= 70 And scr5 < 80 Then
Console.WriteLine("Score #5 letter grade:")
Console.WriteLine("C")
End If
If scr5 >= 80 And scr5 < 90 Then
Console.WriteLine("Score #5 letter grade:")
Console.WriteLine("B")
End If
If scr5 >= 90 Then
Console.WriteLine("Score #5 letter grade:")
Console.WriteLine("A")
End If
If avg < 60 Then
Console.WriteLine("The average letter grade:")
Console.WriteLine("F")
End If
If avg >= 60 And avg < 70 Then
Console.WriteLine("The average letter grade:")
Console.WriteLine("D")
End If
If avg >= 70 And avg < 80 Then
Console.WriteLine("The average letter grade:")
Console.WriteLine("C")
End If
If avg >= 80 And avg < 90 Then
Console.WriteLine("The average letter grade:")
Console.WriteLine("B")
End If
If avg >= 90 Then
Console.WriteLine("The average letter grade:")
Console.WriteLine("A")
End If
End Sub
End Module
Now, an easy way to know there are problems with this code is how long the code is.
I know that the first part of my code (function calcAverage) may have issues (it's so long), maybe you can help, but the main problem I have with number seven is the second function which is even longer code (determineGrade). Here is the part of the question that asks this:
"determineGrade—This function should accept a test score as an argument
and return a letter grade for the score (as a String), based on the following
grading scale:"
I do not know how to make it give the letter grade efficiently, and I don't know how to incorporate .ToString into it.
I thought maybe I could try a loop of some kind, kind of like this:
Sub determinegrade()
startingscore = 1
For score = 1 To 5
Console.WriteLine("Score #" & vbTab & startingscore & vbTab & "The letter grade is" & vbTab & grade.ToString())
startingscore += 1
grade =
Next
As you can see I have nothing set for the variable grade. It just says (grade = ) because I have no idea how I'd translate that into a letter grade of the scr1-scr5. And the part where it says grade.ToString, I don't even know what the .ToString is doing for it right now.
Thanks a lot for time spent on this, I really appreciate it. This needs to be turned in by 12 am tonight, I might give it as is because it still works. He'll give half credit at most (because number 5 is right), but I know he's okay with giving a 0 also.
Attached image(s)
#5
Re: Visual basic 2010 lab homework
Posted 15 October 2012 - 12:40 PM
That's just a quick take on what I skimmed through.
Forgot to ask, have you learned about Arrays, I would think this would be a good use of an array which you can store all 5 scores into and present as needed.
This post has been edited by CharlieMay: 15 October 2012 - 12:41 PM
#6
Re: Visual basic 2010 lab homework
Posted 15 October 2012 - 01:11 PM
#7
Re: Visual basic 2010 lab homework
Posted 15 October 2012 - 01:38 PM
#8
Re: Visual basic 2010 lab homework
Posted 15 October 2012 - 01:41 PM
LetterGrade: a function that takes a score and returns a letter grade
Display: a sub that loops through you array of scores and displays them, calling lettergrade as needed.
EnterStudentGrade: a sub that you send the student number to and stores the score into the array while at the same time checking to make sure the entry is valid.
In your sub main, loop 0 to 4 calling EnterStudentGrade and passing it the student number (the iterator) When complete, call display.
You can bypass EnterStudentGrade and do it in the sub but I find it easier when checking for invalid entries to recall the sub in the current loop iteration so that I don't need a GOTO statement.
Sid89, on 15 October 2012 - 04:38 PM, said:
How about displaying them all at once only using string.format so that you can display something like:
Student 1 scored a 98 and received a A
Student 2 scored a 58 and received a F
etc...
This post has been edited by CharlieMay: 15 October 2012 - 01:39 PM
#9
Re: Visual basic 2010 lab homework
Posted 15 October 2012 - 01:50 PM
#10
Re: Visual basic 2010 lab homework
Posted 15 October 2012 - 03:33 PM
This post has been edited by torind_2000: 15 October 2012 - 03:33 PM
#11
Re: Visual basic 2010 lab homework
Posted 15 October 2012 - 08:58 PM
#12
Re: Visual basic 2010 lab homework
Posted 15 October 2012 - 09:33 PM
|
|

New Topic/Question
Reply



MultiQuote





|