โ Using methods in Grade Statistics project
Write a method PrintoutGrades that prints the grades.
Write a method Statistics that will calculate the number of "A", "C" and "F" grades and the total number of grade points.
When the Statistics method is called, the grade statistics must be printed.
55 Replies
Sounds like a nice and simple exercise, good luck ๐
Hello there
Well! For me, it's not that simple to implement it, therefore I need your knowledge to put it into code ๐
What have you tried?
Let me show u what I have built so far
Well, grades are stored in an array
Seems like the
Statistics
method needs to count how many A
s are in there, how many B
s, and so on
Usually, it's easiest to achieve with a dictionary
Dictionary<char, int>
for exampleThis one is more clear https://paste.mod.gg/ryrklgewvdtc/1
BlazeBin - ryrklgewvdtc
A tool for sharing your source code with the world!
You can fill the dictionary, then loop over the array of grades, and increment the dictionary as needed
Something like this
Well! This is an assignment from my course obviously and they want me to use an array to build the project.
This is the complete assignment requirements:
I don't see any mention of dictionaries being disallowed
Because, without a dictionary, you're looking at much more much worse code
Really! I agree with you. This project seems a bit hard to implement.
Ok! So you recommend me to use dictionary.
Or maybe you could get the index by using the fact, that chars are integers under the hood
A dictionary would be the most straightforward
Ok
Should a dictionary be forbidden, the way with calculating index from char would be my choice
OK
The problem is that this project seems more advanced to me and some of the concepts you're using looks a bit confusing to me.
Which ones?
What is this code doing?
A switch is a more concise way of writing a bunch of if/else statements
I haven't used even B grade in my project
You could write it as
I know how the switch works, but why you're using it?
To count how many of each grade there is..?
Ah! Ok! This one looks more clear.
Ok
The first number is the amount of A grades, the second is the amount of B grades, and so on
The thing that most confuses me in this assignment is the
B
grade. They have mentioned that 100 or less points are A
and 50 or less is F
so I wonder why u used B
and etc..?That's usually how grades work
So I made the assumption we're talking about normal, regular, American school grades
Never heard of a system that would be only using A and F
Write a method that will convert the points into grades according to the scale A-FFrom your assignment It is a scale from A to F A is 100 points, F is less than 50 points, the other grades are spread between those
You're right. But it feels like there are some mistakes in the assignment.
Well! Actually, I'm chatting with you from Sweden, not from the USA.
Still, you probably have a grade system that consists of more than just "perfect" and "failure"
I know you guys in America use this system when it comes to setting grades for the students in your schools and it should be the same here in Sweden.
Ok! I get your point. But the question remains, why the hell they didn't specify limited points for the rest of the grades like B, C, D, and E ๐ค this is what confuses me the most ๐คจ
How the hell am I gonna do this if I don't know what those grades hold a number of points ๐คท๐ปโโ๏ธ
Distributes itself quite nicely
Ok! It makes sense, although you're talking about even numbers, according to my course teacher the points can be odd numbers too. For ex: he sent me a model that looks like this: The
task:
You need to enter points for 5 subjects and print the grade. For example:
Enter points for math? 80 p
Enter points for Swedish? 50 p
......
.....
Then you print out the grade
Subject Grade
Mathematics B
Swedish E
Oh! Sorry, I was wrong earlier, you're right. They want just like this form you mentioned.
Sorry for taking too long with the project. Just wanna ask you about the methods that are mentioned in the assignment. Do they mean void methods or different types of methods?I'm terrible at void methods, although I have watched many tutorials, but still bad at using them ๐คท๐ปโโ๏ธ
As u c see I created a method called Convert bla bla but didn't need to use it when I did the converting in Program.cs
Going by the paragraphs...
1st method doesn't mention anything either way
2nd method definitely has to be non-static and probably
void
3rd method definitely void
4ths method void
as wellOk! Well! The first one is already done. The second one needs some updating by adding these grades B, C, D, E, and F.
I got two errors while adding your last code
Pretty self-explanatory
Some variable named
grade
already exists
Use a different nameOk! I changed it to grade1 instead, how about the second error!
It's giving me a various solution
Well! The second error is gone now too after changing it grade.
The program doesn't output any result after adding your code.
Well, do you tell it to output anything?
Yes
Look
What is
grade
?You can see it inside of foreach
No, I can't
I see it being used
I don't see it being declared
I don't see what values it has
Ok
Well! In the beginning, it was grades and I changed it to grade because of the error.
May I call you to please if you're available?
Not available, I'm afraid
Ok! It's alright.
I don't really understand the code that you provided me
I don't know the purpose of this code
Assuming your array of grades is something like
[A, B, A, A, F, C, D, A, D, F]
, the purpose of this code is to count the occurence of each gradeOk! So you're talking about the third paragraph in the assignment?
I believe so..?
Ok! I see.
So how do I do that?
Write a method printPrintGrades that prints the grades.
Write a method Statistics that will calculate the number of "A", "C" and "F" grades and the total number of grade points.
When the Statistics method is called, the grade statistics must be printed.
I think the first method is complete, right? Because the project is currently printing out the grades.Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.