❔ 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.
A
Angius•511d ago
Sounds like a nice and simple exercise, good luck 👌
TKO
The king of kings•511d ago
Hello there
Well! For me, it's not that simple to implement it, therefore I need your knowledge to put it into code 😉
A
Angius•511d ago
What have you tried?
TKO
The king of kings•511d ago
Let me show u what I have built so far
A
Angius•511d ago
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 exampleTKO
The king of kings•511d ago
This one is more clear https://paste.mod.gg/ryrklgewvdtc/1
BlazeBin - ryrklgewvdtc
A tool for sharing your source code with the world!
A
Angius•511d ago
You can fill the dictionary, then loop over the array of grades, and increment the dictionary as needed
Something like this
TKO
The king of kings•511d ago
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:
A
Angius•511d ago
I don't see any mention of dictionaries being disallowed
Because, without a dictionary, you're looking at much more much worse code
TKO
The king of kings•511d ago
Really! I agree with you. This project seems a bit hard to implement.
A
Angius•511d ago
TKO
The king of kings•511d ago
Ok! So you recommend me to use dictionary.
A
Angius•511d ago
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
TKO
The king of kings•511d ago
Ok
A
Angius•511d ago
Should a dictionary be forbidden, the way with calculating index from char would be my choice
TKO
The king of kings•511d ago
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.
A
Angius•511d ago
Which ones?
TKO
The king of kings•511d ago
What is this code doing?
A
Angius•511d ago
A switch is a more concise way of writing a bunch of if/else statements
TKO
The king of kings•511d ago
I haven't used even B grade in my project
A
Angius•511d ago
You could write it as
TKO
The king of kings•511d ago
I know how the switch works, but why you're using it?
A
Angius•511d ago
To count how many of each grade there is..?
TKO
The king of kings•511d ago
Ah! Ok! This one looks more clear.
Ok
A
Angius•511d ago
The first number is the amount of A grades, the second is the amount of B grades, and so on
TKO
The king of kings•511d ago
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..?A
Angius•511d ago
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
TKO
The king of kings•511d ago
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.
A
Angius•511d ago
Still, you probably have a grade system that consists of more than just "perfect" and "failure"
TKO
The king of kings•511d ago
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 🤷🏻♂️
A
Angius•511d ago
Distributes itself quite nicely
TKO
The king of kings•511d ago
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?TKO
The king of kings•511d ago
I'm terrible at void methods, although I have watched many tutorials, but still bad at using them 🤷🏻♂️
TKO
The king of kings•511d ago
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
A
Angius•511d ago
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 wellTKO
The king of kings•510d ago
Ok! Well! The first one is already done. The second one needs some updating by adding these grades B, C, D, E, and F.
TKO
The king of kings•510d ago
I got two errors while adding your last code
A
Angius•510d ago
Pretty self-explanatory
Some variable named
grade
already exists
Use a different nameTKO
The king of kings•510d ago
Ok! 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.
A
Angius•510d ago
Well, do you tell it to output anything?
TKO
The king of kings•510d ago
Yes
Look
TKO
The king of kings•510d ago
A
Angius•510d ago
What is
grade
?TKO
The king of kings•510d ago
You can see it inside of foreach
A
Angius•510d ago
No, I can't
A
Angius•510d ago
I see it being used
A
Angius•510d ago
I don't see it being declared
I don't see what values it has
TKO
The king of kings•510d ago
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?
A
Angius•510d ago
Not available, I'm afraid
TKO
The king of kings•510d ago
Ok! It's alright.
I don't really understand the code that you provided me
I don't know the purpose of this code
A
Angius•510d ago
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 gradeTKO
The king of kings•510d ago
Ok! So you're talking about the third paragraph in the assignment?
A
Angius•510d ago
I believe so..?
TKO
The king of kings•510d ago
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.A
Accord•509d ago
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.We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
51KMembers
View on DiscordWant results from more Discord servers?
More Posts✅ Any modern approach to getting the calling class typename aside from using the stack frame?10 years ago I used to use the stack frame to go backwards and get what class is calling my current ✅ How can I hide buttons inside a tablelayout?When i make the visible false, they still show, and if i make the visible false on both the tablelay❔ How to reverse engineer your simple console app code?Just curious. Is this possible with programs like x64dbg or... ?❔ Ef Core Constructor problemHello its my first big project with ef. I have an class with 3 attributes and one constructor that i❔ many to many database cant update the 3rd tablecant update the 3rd table who had the cust id and drink id✅ rest requests helphello i am trying to send to os command injections with RestSharp to dvwa for pentestering can someo❔ Source generator, generating type script definitions at compile timeI would like to make a automatic type script definition from code, i consider to use source generato❔ Making an async method without anything to async insidelet's say i have following scenario:
```csharp
void Foo()
{
for(int i = 0 ; i < 10000000 ;i++){} /❔ Reading file from the folder where .csproj isHow can i read files from folder where .csproj is? just like webapps allow to do, they do not copy f✅ Interoperability between incompatible typesHi!
I'm trying to pass a class back-and-forth from C# to CPP.
This class contains some members that ❔ Set item to null inside a listHey! I am trying to remove some items from a JSON object (created like `var model = new ObjectModel{Refactoring long if statement that checks for user rolesHi, I'm trying to find a cleaner way of refactoring this if code block that checks for each user rol❔ IEnumerable and dependency injectionif i want to loop enumerable from DI multiple times
```
var foos = services.GetRequiredService<IEnum❔ How did you learn . NET ?Books /youtube/udemy /other courses, what resources made you learn .NET to use as your job as web de✅ Is it possible to disable these properties on EF6? Web API 2 project, multi-layered, NF472SCENARIO
- Solution type is NET Framework 4.7.2 (it is, what it is).
- I have this project, I'm cons✅ This EntityFramework query can not be translated for SQLiteThe issue lies within `Intersect`. The point of the query is to fetch the current user, and to popul✅ Detect Network RequestI want make service that detect all connection to specific domain or ip?
And if this request contain❔ CORS errorHello, I have Cors error on my project. I add Addpolicy in my configureServices and also add app.Us❔ Ambiguities? How?Idk how i can resolve this i don't see the problem✅ How can I get rid of this annoying pointer thing in the first row, datagridview winforms^