C
C#โ€ข2y ago
The king of kings

โ” 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
Angius
Angiusโ€ข2y ago
Sounds like a nice and simple exercise, good luck ๐Ÿ‘Œ
The king of kings
The king of kingsOPโ€ข2y ago
Hello there Well! For me, it's not that simple to implement it, therefore I need your knowledge to put it into code ๐Ÿ˜‰
Angius
Angiusโ€ข2y ago
What have you tried?
The king of kings
The king of kingsOPโ€ข2y ago
Let me show u what I have built so far
using System;
namespace GradeStatisticsApp
{
public class Points_Grades
{
public static int Points { get; set; }
public static char Grades { get; set; }
public Points_Grades(int ponits, char grades)
{
Points = ponits;
Grades = grades;
}

public static void CheckAlphabetical()
{

}

public static void ReadScore()
{


}

public static void ConvertPointsIntoGrades()
{

}
}
}
using System;
namespace GradeStatisticsApp
{
public class Points_Grades
{
public static int Points { get; set; }
public static char Grades { get; set; }
public Points_Grades(int ponits, char grades)
{
Points = ponits;
Grades = grades;
}

public static void CheckAlphabetical()
{

}

public static void ReadScore()
{


}

public static void ConvertPointsIntoGrades()
{

}
}
}
using System;
using System.Text.RegularExpressions;
namespace GradeStatisticsApp
{
class Program
{
static void Main(string[] args)
{
string[] subject = { "Mathematic", "Swedish", "English", "History", "Physic" };
int[] points = new int[5];
char[] grade = new char[6];
Points_Grades.CheckAlphabetical();
Console.Write("\nEnter the student name:\t");
string userInput1 = Console.ReadLine();
Console.WriteLine("");
/*foreach (char name in userInput1)
{
Console.WriteLine();
}
Points_Grades.ReadScore();*/

for (int i = 0; i < 5; i++)
{
Console.Write(subject[i]);

Console.Write($"\nEnter the points: ");
bool condition = int.TryParse(Console.ReadLine(), out int point);
Console.Write("");
if (condition == false)
{
throw new Exception("Invalid user input");
}
if (point <= 100 && point >= 50)
{
Console.Write(Convert.ToChar('A'));
var grade1 = Console.ReadLine();
}
if (point >= 0 && point < 50)
{ Console.Write(Convert.ToChar('F'));
var grad2 = Console.ReadLine();
}
else if (point > 100)
{
throw new Exception("User input out of range");
}
Console.WriteLine("");
Console.Write(subject[0]);
Console.Write(subject[1]);
Console.Write(subject[2]);
Console.Write(subject[3]);
Console.Write(subject[4]);
}
}
}
}
using System;
using System.Text.RegularExpressions;
namespace GradeStatisticsApp
{
class Program
{
static void Main(string[] args)
{
string[] subject = { "Mathematic", "Swedish", "English", "History", "Physic" };
int[] points = new int[5];
char[] grade = new char[6];
Points_Grades.CheckAlphabetical();
Console.Write("\nEnter the student name:\t");
string userInput1 = Console.ReadLine();
Console.WriteLine("");
/*foreach (char name in userInput1)
{
Console.WriteLine();
}
Points_Grades.ReadScore();*/

for (int i = 0; i < 5; i++)
{
Console.Write(subject[i]);

Console.Write($"\nEnter the points: ");
bool condition = int.TryParse(Console.ReadLine(), out int point);
Console.Write("");
if (condition == false)
{
throw new Exception("Invalid user input");
}
if (point <= 100 && point >= 50)
{
Console.Write(Convert.ToChar('A'));
var grade1 = Console.ReadLine();
}
if (point >= 0 && point < 50)
{ Console.Write(Convert.ToChar('F'));
var grad2 = Console.ReadLine();
}
else if (point > 100)
{
throw new Exception("User input out of range");
}
Console.WriteLine("");
Console.Write(subject[0]);
Console.Write(subject[1]);
Console.Write(subject[2]);
Console.Write(subject[3]);
Console.Write(subject[4]);
}
}
}
}
Angius
Angiusโ€ข2y ago
Well, grades are stored in an array Seems like the Statistics method needs to count how many As are in there, how many Bs, and so on Usually, it's easiest to achieve with a dictionary Dictionary<char, int> for example
The king of kings
The king of kingsOPโ€ข2y ago
BlazeBin - ryrklgewvdtc
A tool for sharing your source code with the world!
Angius
Angiusโ€ข2y ago
You can fill the dictionary, then loop over the array of grades, and increment the dictionary as needed
var dict = new Dictionary<char, int>(){
['A'] = 0,
['B'] = 0,
// ...
};

foreach (var grade in grades)
{
dict[grade] += 1;
}
var dict = new Dictionary<char, int>(){
['A'] = 0,
['B'] = 0,
// ...
};

foreach (var grade in grades)
{
dict[grade] += 1;
}
Something like this
The king of kings
The king of kingsOPโ€ข2y 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:
Write a method ReadPoints to read the student's grade points in the various subjects.
You should save the points in an array, vector or list.
When the method is called, the user must enter a number of grade points.
The grade points to be entered are controlled by the contents of the subject field.

Write a method that will convert the points into grades according to the scale A-F.
The grade A corresponds to 100 points.
The grade F corresponds to less than 50 points
You must store the grades in a field (array, vector or list).


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.
Write pseudocode for this method. Also draw flow charts.

You don't need to write pseudo code or draw flow diagrams for the entire program.
Compile and run the program.
Write a method ReadPoints to read the student's grade points in the various subjects.
You should save the points in an array, vector or list.
When the method is called, the user must enter a number of grade points.
The grade points to be entered are controlled by the contents of the subject field.

Write a method that will convert the points into grades according to the scale A-F.
The grade A corresponds to 100 points.
The grade F corresponds to less than 50 points
You must store the grades in a field (array, vector or list).


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.
Write pseudocode for this method. Also draw flow charts.

You don't need to write pseudo code or draw flow diagrams for the entire program.
Compile and run the program.
Angius
Angiusโ€ข2y ago
I don't see any mention of dictionaries being disallowed Because, without a dictionary, you're looking at much more much worse code
The king of kings
The king of kingsOPโ€ข2y ago
Really! I agree with you. This project seems a bit hard to implement.
Angius
Angiusโ€ข2y ago
var sums = new int[]{0, 0, 0, 0, 0, 0};

foreach (var grade in grades)
{
switch (grade) {
case 'A':
sums[0] += 1;
break;
case 'B':
sums[1] += 1;
break;
case 'C' //...
}
}
var sums = new int[]{0, 0, 0, 0, 0, 0};

foreach (var grade in grades)
{
switch (grade) {
case 'A':
sums[0] += 1;
break;
case 'B':
sums[1] += 1;
break;
case 'C' //...
}
}
The king of kings
The king of kingsOPโ€ข2y ago
Ok! So you recommend me to use dictionary.
Angius
Angiusโ€ข2y ago
Or maybe you could get the index by using the fact, that chars are integers under the hood
var sums = new int[]{0, 0, 0, 0, 0, 0};
// A B C D E F

foreach (var grade in grades)
{
sums[grade - 'A'] += 1;
}
var sums = new int[]{0, 0, 0, 0, 0, 0};
// A B C D E F

foreach (var grade in grades)
{
sums[grade - 'A'] += 1;
}
A dictionary would be the most straightforward
The king of kings
The king of kingsOPโ€ข2y ago
Ok
Angius
Angiusโ€ข2y ago
Should a dictionary be forbidden, the way with calculating index from char would be my choice
The king of kings
The king of kingsOPโ€ข2y 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.
Angius
Angiusโ€ข2y ago
Which ones?
The king of kings
The king of kingsOPโ€ข2y ago
What is this code doing?
Angius
Angiusโ€ข2y ago
A switch is a more concise way of writing a bunch of if/else statements
The king of kings
The king of kingsOPโ€ข2y ago
I haven't used even B grade in my project
Angius
Angiusโ€ข2y ago
You could write it as
var sums = new int[]{0, 0, 0, 0, 0, 0};

foreach (var grade in grades)
{
if (grade == 'A')
{
sums[0] += 1;
}
else if (grade == 'B')
{
sums[1] += 1;
}
else if (grade == 'C')
{
// ...
}
}
var sums = new int[]{0, 0, 0, 0, 0, 0};

foreach (var grade in grades)
{
if (grade == 'A')
{
sums[0] += 1;
}
else if (grade == 'B')
{
sums[1] += 1;
}
else if (grade == 'C')
{
// ...
}
}
The king of kings
The king of kingsOPโ€ข2y ago
I know how the switch works, but why you're using it?
Angius
Angiusโ€ข2y ago
To count how many of each grade there is..?
var sums = new int[]{0, 0, 0, 0, 0, 0};
// A B C D E F
var sums = new int[]{0, 0, 0, 0, 0, 0};
// A B C D E F
The king of kings
The king of kingsOPโ€ข2y ago
Ah! Ok! This one looks more clear. Ok
Angius
Angiusโ€ข2y ago
The first number is the amount of A grades, the second is the amount of B grades, and so on
The king of kings
The king of kingsOPโ€ข2y 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..?
Angius
Angiusโ€ข2y 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-F
From 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
The king of kings
The king of kingsOPโ€ข2y 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.
Angius
Angiusโ€ข2y ago
Still, you probably have a grade system that consists of more than just "perfect" and "failure"
The king of kings
The king of kingsOPโ€ข2y 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 ๐Ÿคท๐Ÿปโ€โ™‚๏ธ
Angius
Angiusโ€ข2y ago
A - 100
B - 90
C - 80
D - 70
E - 60
F - 50
A - 100
B - 90
C - 80
D - 70
E - 60
F - 50
Distributes itself quite nicely
The king of kings
The king of kingsOPโ€ข2y 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?
The king of kings
The king of kingsOPโ€ข2y ago
I'm terrible at void methods, although I have watched many tutorials, but still bad at using them ๐Ÿคท๐Ÿปโ€โ™‚๏ธ
The king of kings
The king of kingsOPโ€ข2y 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
Angius
Angiusโ€ข2y 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 well
The king of kings
The king of kingsOPโ€ข2y 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.
The king of kings
The king of kingsOPโ€ข2y ago
I got two errors while adding your last code
Angius
Angiusโ€ข2y ago
Pretty self-explanatory Some variable named grade already exists Use a different name
The king of kings
The king of kingsOPโ€ข2y 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.
Angius
Angiusโ€ข2y ago
Well, do you tell it to output anything?
The king of kings
The king of kingsOPโ€ข2y ago
Yes Look
The king of kings
The king of kingsOPโ€ข2y ago
Angius
Angiusโ€ข2y ago
What is grade?
The king of kings
The king of kingsOPโ€ข2y ago
You can see it inside of foreach
Angius
Angiusโ€ข2y ago
No, I can't
Angius
Angiusโ€ข2y ago
I see it being used
Angius
Angiusโ€ข2y ago
I don't see it being declared I don't see what values it has
The king of kings
The king of kingsOPโ€ข2y 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?
Angius
Angiusโ€ข2y ago
Not available, I'm afraid
The king of kings
The king of kingsOPโ€ข2y 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
Angius
Angiusโ€ข2y 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 grade
The king of kings
The king of kingsOPโ€ข2y ago
Ok! So you're talking about the third paragraph in the assignment?
Angius
Angiusโ€ข2y ago
I believe so..?
The king of kings
The king of kingsOPโ€ข2y 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.
Accord
Accordโ€ข2y 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.
Want results from more Discord servers?
Add your server