11 Replies - 3709 Views - Last Post: 15 October 2012 - 09:33 PM Rate Topic: -----

#1 Sid89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-October 12

Visual basic 2010 lab homework

Posted 11 October 2012 - 01:19 PM

Hi, I was wondering if I could get some help with a lab hw I have. I had some class notes (example) but I lost it, so I'm not sure if this one will be easy on my own, wondering if you guys could do these problems so I can understand it thanks.


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

Is This A Good Question/Topic? 0
  • +

Replies To: Visual basic 2010 lab homework

#2 shykxz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 11-October 12

Re: Visual basic 2010 lab homework

Posted 11 October 2012 - 01:29 PM

you will use textbox?declare the g as constant..use if else if
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Visual basic 2010 lab homework

Posted 11 October 2012 - 01:34 PM

Use a for...loop looping your iterator variable (in this case t) form 1 to 10
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.
Was This Post Helpful? 0
  • +
  • -

#4 Sid89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-October 12

Re: Visual basic 2010 lab homework

Posted 15 October 2012 - 12:32 PM

Hi guys, thanks a lot for your replies and time. I was able to figure out number five, it was easier than I thought.

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. :helpsmilie:

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Visual basic 2010 lab homework

Posted 15 October 2012 - 12:40 PM

OK, first, that's a lot of repetitive code. Perhaps a function would be better where you pass the score and it returns a grade letter. This could also be used for your average.

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

Was This Post Helpful? 0
  • +
  • -

#6 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 55
  • View blog
  • Posts: 285
  • Joined: 22-August 11

Re: Visual basic 2010 lab homework

Posted 15 October 2012 - 01:11 PM

Here's what I got with a little messing around.

Spoiler

Was This Post Helpful? 0
  • +
  • -

#7 Sid89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-October 12

Re: Visual basic 2010 lab homework

Posted 15 October 2012 - 01:38 PM

Your code there looks extremely clean and the right way to do it. It asks for scores five times, then gives an average score. The next question is how to display grades. Should the program just list all the grades all at once, or should it ask for individual scores and give letter grades. I'm not sure which to do because of the wording of the question. I wish I could combine both our codes but that doesn't seem possible lol.
Was This Post Helpful? 0
  • +
  • -

#8 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Visual basic 2010 lab homework

Posted 15 October 2012 - 01:41 PM

I would break this down into 3 methods

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.

View PostSid89, on 15 October 2012 - 04:38 PM, said:

Your code there looks extremely clean and the right way to do it. It asks for scores five times, then gives an average score. The next question is how to display grades. Should the program just list all the grades all at once, or should it ask for individual scores and give letter grades. I'm not sure which to do because of the wording of the question. I wish I could combine both our codes but that doesn't seem possible lol.

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

Was This Post Helpful? 0
  • +
  • -

#9 Sid89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-October 12

Re: Visual basic 2010 lab homework

Posted 15 October 2012 - 01:50 PM

Thanks so much for your help you guys. I actually am not sure if we learned arrays yet, that's chapter 8 I think but I'll try. It's 345 pm but I'm burned out, I have to take a nap :sleep1: . I will try to wake up early enough to be able to make these changes before 12 am when it's due. I'll try to keep you guys updated with its progress, thanks.
Was This Post Helpful? 0
  • +
  • -

#10 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 55
  • View blog
  • Posts: 285
  • Joined: 22-August 11

Re: Visual basic 2010 lab homework

Posted 15 October 2012 - 03:33 PM

I think i figured it out, I'd like to see your result first tho.

This post has been edited by torind_2000: 15 October 2012 - 03:33 PM

Was This Post Helpful? 0
  • +
  • -

#11 Sid89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-October 12

Re: Visual basic 2010 lab homework

Posted 15 October 2012 - 08:58 PM

I just got out of bed, there's one hour left I'll see what I can do now.
Was This Post Helpful? 0
  • +
  • -

#12 Sid89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-October 12

Re: Visual basic 2010 lab homework

Posted 15 October 2012 - 09:33 PM

I just turned this thing in as it is. My mind is a blank without class notes that I lost. Usually the notes are very similar to the hw, just worded different. It's almost like a template we fill in the blanks lol.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1