Console application to read exam scores and print some in

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 5539 Views - Last Post: 08 November 2014 - 11:31 AM Rate Topic: -----

#1 l3luehelper   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 06-November 14

Console application to read exam scores and print some in

Posted 06 November 2014 - 02:14 PM

Please see the attached for detail. any help is appreciated:

In this assignment, your task is to write a Visual Basic console application to read exam scores and print some information. Your program should contain the following steps:

Step 1: Read an integer numOfStudents, where numOfStudents > 0, to indicate the number of students.

Step 2: Read exam scores for all students, where each score is an integer between 0 and 100 inclusively.

Step 3: Output the following information:

a) The number of students in each grade (A, B, C, D, E, and F), where the score range for each grade is shown as follows:

Grade Score Range
A 90-100
B 80-89
C 70-79
D 60-69
E 50-59
F (failure) 0-49

B) The mean of the exam scores (excluding failure cases), rounded to 2 decimal places (either rounding towards even or rounding up).

c) The median of the exam scores (excluding failure cases), rounded to 2 decimal places (either rounding towards even or rounding up).

Step 4: Ask whether the user wants to repeat the program. If yes, go to Step 1 and repeat all the steps (Hint: please make sure that the variables are initialized properly). If no, terminate the program.

You can assume that all user inputs are valid.

-------------------------------------------------------------------------------------

This is what i have so far, is it so far so good? i dont know why is "numOfStudents" underlined as blue

what should i do next?

Module Module1

    Sub Main()
        Dim numOfStudents As Integer
        Console.WriteLine("Enter the number of students:")
        Console.ReadLine()


    End Sub

End Module

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Console application to read exam scores and print some in

#2 ybadragon   User is offline

  • Home Owner
  • member icon

Reputation: 571
  • View blog
  • Posts: 2,647
  • Joined: 11-May 12

Re: Console application to read exam scores and print some in

Posted 06 November 2014 - 02:23 PM

well the first step you have is to read in the number of students. Have you accomplished that yet? Hover over the blue line and read what it says. Chances are it says something about numOfStudents being declared but never used. put a breakpoint in your code and see if number of students ever changes by steping through the code with f11.
Was This Post Helpful? 0
  • +
  • -

#3 l3luehelper   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 06-November 14

Re: Console application to read exam scores and print some in

Posted 06 November 2014 - 08:18 PM

when the user enter the number of students how do i let it match so that the user can enter the number of value(the scores) same as the number of studnets? i think i was told to use array, what should i do?
Was This Post Helpful? 0
  • +
  • -

#4 ybadragon   User is offline

  • Home Owner
  • member icon

Reputation: 571
  • View blog
  • Posts: 2,647
  • Joined: 11-May 12

Re: Console application to read exam scores and print some in

Posted 07 November 2014 - 06:05 AM

Sorry I don't follow that response. What have you tried so far?
Was This Post Helpful? 0
  • +
  • -

#5 DarenR   User is online

  • D.I.C Lover

Reputation: 595
  • View blog
  • Posts: 3,849
  • Joined: 12-January 10

Re: Console application to read exam scores and print some in

Posted 07 November 2014 - 07:02 AM

ok the assignment you posted is missing some information:

where are the scores coming from? are they being supplied or do you have to ask for them?
Was This Post Helpful? 0
  • +
  • -

#6 l3luehelper   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 06-November 14

Re: Console application to read exam scores and print some in

Posted 07 November 2014 - 07:15 AM

View PostDarenR, on 07 November 2014 - 07:02 AM, said:

ok the assignment you posted is missing some information:

where are the scores coming from? are they being supplied or do you have to ask for them?



The score are enter by the user if the user has a class of 20 students, then he input 20 for the number of students and input Score1, Score2, ....Score20,

the the console will do the calculation

im stuck at how should I write to allow the user to input the score Score1,Score2,...,ScoreN.
Was This Post Helpful? 0
  • +
  • -

#7 Yips   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 64
  • Joined: 11-October 14

Re: Console application to read exam scores and print some in

Posted 07 November 2014 - 07:19 AM

There a few ways you can do this.

1.) Well, first off you have the variable to ask how many of the students there are.
Dim numOfStudents As Integer
Console.WriteLine("Enter the number of students:")
Console.ReadLine()


That's here.

2.) Next, you need to have the user input the score they got on their exams. So you can do this fluently using a bunch of Console.ReadLine() commands. You could also use a Do While/Until Loop or a For Next Loop. These are all available.

3.) When you have this completed, you can worry about what to do with the scores. You could use an If-Then statement, which will have the program decide for each score where it would go. Ex: If this score is this, then output this.

4.) You need to next, have the program output the information that is given. Depending on the amount of users inputted, which you need to make a control variable to control how many students the user will want to input, then you can either, if you only allow so many students to be entered... you can use, again the Console.ReadLine() command. Or you can use another type of Loop to print each score out.

Now, as this is an assignment, I will not give so much code to you. This is for you to learn how to think logically and step by step. How would you do it if you had to go through and grade each score?

Also, since you are learning VB.NET, as am I, I would highly suggest putting Option Strict On at the top of your code. This will require you to convert all types to the precise type needed. Also, it will catch more errors than you would've expected.

Hope this helps!

This post has been edited by Yips: 07 November 2014 - 07:19 AM

Was This Post Helpful? 1
  • +
  • -

#8 l3luehelper   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 06-November 14

Re: Console application to read exam scores and print some in

Posted 07 November 2014 - 09:19 AM

 Sub Main()
        Dim numOfStudents As Integer
        Dim count As Integer = 0
        Console.WriteLine("Enter the number of students:")
        numOfStudents = Console.ReadLine()
        Do Until count = numOfStudents
            Console.ReadLine()
            count += 1
        Loop



so I allowed the user to enter N-number of scores based on the number of scores he has by allow him to enter the scores until the count of the score equal numOfStudents (that is, count = numOfStudents)

I let the user enter the score, but I am not sure how to store the scores he entered so that I can used the stored score to perform the calculation

the instruction suggested to use array

can array perform what i need?

thanks
Was This Post Helpful? 0
  • +
  • -

#9 Yips   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 64
  • Joined: 11-October 14

Re: Console application to read exam scores and print some in

Posted 07 November 2014 - 09:28 AM

If the instructions said that arrays are preferred/most likely to be used, then yes, they are able to be used to do what you wish.

You can read up on arrays here. Also, you can check out the tutorials here on the forums. I'm sure there's an array tutorial.

You would use your index(es) to tell the different names apart. Names would also be referred to as elements. But remember when setting the value of the array, it starts at (0), not (1).

Remember that you set the size of the array when you declare it. Also, you can use the Redim and Preserve functions to set the size of the array.
Was This Post Helpful? 1
  • +
  • -

#10 l3luehelper   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 06-November 14

Re: Console application to read exam scores and print some in

Posted 07 November 2014 - 10:15 AM

I have allowed the user to enter the scores and count how many score inputs achieve specific letter grade

Now I have to count the mean and median of the score, excluding the failure case (F)

how should I calculate mean and median? and how should I calculate mean and median without the failure case (scores that belong to F)

Sub Main()
        Dim numOfStudents As Integer


        Dim Score As Integer() 'let score be an array score()

        Console.WriteLine("Enter the number of students:")
        numOfStudents = Console.ReadLine()
        'instruct the user to input the number of student

        
        Score = New Integer(numOfStudents - 1) {}
        Dim NumOfA, NumOfB, NumOfC, NumOfD, NumOfE, NumOfF As Integer
        For i As Integer = 0 To numOfStudents - 1
            Score(i) = Console.ReadLine()
            If Score(i) >= 90 Then
                NumOfA += 1
            ElseIf Score(i) >= 80 Then
                NumOfB += 1
            ElseIf Score(i) >= 70 Then
                NumOfC += 1
            ElseIf Score(i) >= 60 Then
                NumOfD += 1
            ElseIf Score(i) >= 50 Then
                NumOfE += 1
            ElseIf Score(i) < 50 Then
                NumOfF += 1
            End If
        Next

        'since array bounds are (0 to N) the number of elements will be N+1 instead of N, 
        'so we do numofStudents less 1 to let the num of elements equal to the number of students
        'And we let user to enter the score of student No.1 stored to Score(0), score of student No.2 stored to Score(1),
        'and so on until the user enter the score of last student No. N stored to Score(N-1).
        'Then the For Next cycle will arrange score input to specific letter grade and count the number
        ' of the score that each specific letter grade has 

        Console.WriteLine("Grade A: " & NumOfA)
        Console.WriteLine("Grade B: " & NumOfB)
        Console.WriteLine("Grade C: " & NumOfC)
        Console.WriteLine("Grade D: " & NumOfD)
        Console.WriteLine("Grade E: " & NumOfE)
        Console.WriteLine("Grade F: " & NumOfF)
        'Writes out the number of student who score specific letter grade





    End Sub

Was This Post Helpful? 0
  • +
  • -

#11 Yips   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 64
  • Joined: 11-October 14

Re: Console application to read exam scores and print some in

Posted 07 November 2014 - 10:37 AM

Well, the mean is the average of all the numbers divided by the amount of numbers inputted. So you could do something like

"variable for the answer of adding all the numbers' / 'variable for the amount of scores/students'

For the median, you could do something like

Dim numbers() As Integer = {75, 98, 54, 23, 54}
Array.Sort(numbers)
If numbers.Length Mod 2 <> 0 Then 'uneven amount of numbers
    Console.WriteLine("Median = " & numbers(numbers.GetUpperBound(0) \ 2).ToString)
Else 'even amount of numbers
    Dim num1 As Integer = numbers(numbers.Length \ 2)
    Dim num2 As Integer = numbers((numbers.Length \ 2) - 1)
    Dim median As Integer = (num1 + num2) \ 2
    Console.WriteLine("Median = " & median.ToString)
End If


Obviously, this has the numbers already set. But you can replace the numbers with your set variable.

This is used for the same question asked by here.

Each has it's own way of doing it.

Depending on what you know, transfer what you know from these examples over to your project, then transform it into what you know.

If you have anymore questions, please ask.

This post has been edited by Yips: 07 November 2014 - 10:38 AM

Was This Post Helpful? 1
  • +
  • -

#12 l3luehelper   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 06-November 14

Re: Console application to read exam scores and print some in

Posted 07 November 2014 - 05:56 PM

But I was instructed to calculate the mean and median WITHOUT the failure case (aka, student who get 0~49 are excluded)

say I input scores (97, 98, 99 , 49)

since 49 is failure case we exclude it and only look at 97, 98 , 99 and find mean=(97+98+99)/3 and median = 98

I have write the code for to calculate the mean without failing case, but i am not sure how should I do for median

This post has been edited by andrewsw: 08 November 2014 - 02:55 AM
Reason for edit:: Removed large previous quote, just press REPLY

Was This Post Helpful? 0
  • +
  • -

#13 Yips   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 64
  • Joined: 11-October 14

Re: Console application to read exam scores and print some in

Posted 07 November 2014 - 06:04 PM

From the easiest standpoint on my end would be to either...

1) Create an array inputting all the variables you've made, excluding the one you don't want

or

2) Create Select...Cases, showing if these are in between this, do this. Read on cases here if you don't know the syntax for them. You can exclude the variable you don't wish to have in the cases, and make that variable it's very own case... because it's special.

This post has been edited by Yips: 07 November 2014 - 06:07 PM

Was This Post Helpful? 0
  • +
  • -

#14 l3luehelper   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 06-November 14

Re: Console application to read exam scores and print some in

Posted 08 November 2014 - 04:57 AM

I'm afraid the user have to input all the scores regardless of the failing scores or the passing scores.
I've been trying use the Select...Case to select the passing score from the array with all the scores and pass these passing scores to a new array. But I dont know how..

 Dim PassScore As Integer() = New Integer((NumOfA + NumOfB + NumOfC + NumOfD + NumOfE) - 1) {}

        For p As Integer = 0 To (NumOfA + NumOfB + NumOfC + NumOfD + NumOfE) - 1
            For i As Integer = 0 To numOfStudents - 1
                Select Case Score(i)
                    Case Is >= 50
                        PassScore(p) = Score(i)
                End Select
            Next
        Next

This post has been edited by andrewsw: 08 November 2014 - 05:01 AM
Reason for edit:: Removed previous quote and extra code tags

Was This Post Helpful? 0
  • +
  • -

#15 andrewsw   User is offline

  • awks lol ffs
  • member icon

Reputation: 6696
  • View blog
  • Posts: 27,485
  • Joined: 12-December 12

Re: Console application to read exam scores and print some in

Posted 08 November 2014 - 05:00 AM

@OP There is no need to keep quoting the previous post, there is a large Reply button further down the page.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2