 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
mickym2005 How do I cheat?
Reputation: 0
Joined: 13 Oct 2007 Posts: 8
|
Posted: Mon Dec 08, 2008 11:07 pm Post subject: help with java arrays |
|
|
i wanted to learn some java so i took a class. i got an assignment that has to do with arrays, but i cant figure out how to do it. if anyone could help it would be much appreciated. thanks
question:
write a class encapsulating the concept of converting integer grades to letter grades(A,B,C,D or F), assuming grades are composed of a list of integers between 0 and 100.
what needs to be done:
1)a constructor with just one parameter, the number of students; all grades can be randomly generated.
2) A method returning an array of chars corresponding to the integer grades( 90 or above should be converted to A, 80 or above to B etc...
3) A method returning a number of array of ints counting how many A's, B's, C's, D's, and F's were received.
|
|
| Back to top |
|
 |
FerrisBuellerYourMyHero Master Cheater
Reputation: 0
Joined: 14 Feb 2007 Posts: 401 Location: Inside your <kernel>
|
Posted: Tue Dec 09, 2008 12:25 pm Post subject: |
|
|
Well I'm not a java programmer. But I made this in C++ real quick and it meets all the requirements...
Its a console app, you give it the number of students, and it uses the GradingClass, to randomly generate the grades in the constructor. (ex. 0-100)
then a call to its member function "ReturnGrades()" fills the char array of the class object with the grade letters (ex. F-A)
finally a call to "CountGrades()" determines how many students got an A, B, C, etc.. As a bonus it also calculates the percentage of which students got which grade letter.
This should give you an idea of how your supposed to do it. Now re make it in java (I think its better this way anyway, since now you have to actually do some work, instead of just having it done for you. How you going to learn like that?)
Since your learning java you should know how to use arrays and loops in it.
//GradingClass.cpp
| Code: |
#include "GradingClass.h"
GradingClass::GradingClass(unsigned long NumberOfStudents) //constructor
{
int tries = 0;
NumStudents = NumberOfStudents;
//allocate memory
Grades = new char[NumStudents];
GradeNumbers = new int[NumStudents];
for(unsigned int i = 0; i < NumStudents; i++)
{
//You said it could be random ;)
GiveEmAnotherShot:
int RandomGrade = rand() % 101; //between 0(F) - 100(A)
if(RandomGrade < 60 && tries < 3)
{
tries++;
goto GiveEmAnotherShot;
}
tries = 0;
GradeNumbers[i] = RandomGrade;
}
}
GradingClass::~GradingClass() //destructor
{
//free memory
delete[] Grades;
delete[] GradeNumbers;
}
void GradingClass::ReturnGrades()
{
for(unsigned int i = 0; i < NumStudents; i++)
{
if(GradeNumbers[i] < 60)
{
Grades[i] = 'F';
}
else if(GradeNumbers[i] >= 60 && GradeNumbers[i] < 70)
{
Grades[i] = 'D';
}
else if(GradeNumbers[i] >= 70 && GradeNumbers[i] < 80)
{
Grades[i] = 'C';
}
else if(GradeNumbers[i] >= 80 && GradeNumbers[i] < 90)
{
Grades[i] = 'B';
}
else if(GradeNumbers[i] >= 90)
{
Grades[i] = 'A';
}
printf("Student # %u grade: %02i%% with a %c\r\n", (i+1), GradeNumbers[i], Grades[i]);
}
}
void GradingClass::CountGrades()
{
float a = 0.0f, b = 0.0f, c = 0.0f, d = 0.0f, f = 0.0f;
Gradez.As = 0;
Gradez.Bs = 0;
Gradez.Cs = 0;
Gradez.Ds = 0;
Gradez.Fs = 0;
for(unsigned int i = 0; i < NumStudents; i++)
{
if(Grades[i] == 'A')
{
Gradez.As++;
}
else if(Grades[i] == 'B')
{
Gradez.Bs++;
}
else if(Grades[i] == 'C')
{
Gradez.Cs++;
}
else if(Grades[i] == 'D')
{
Gradez.Ds++;
}
else if(Grades[i] == 'F')
{
Gradez.Fs++;
}
}
printf("\r\nNumber Of Students With\r\n");
printf("A: %u B: %u C: %u D: %u F: %u\r\n", Gradez.As, Gradez.Bs, Gradez.Cs, Gradez.Ds, Gradez.Fs);
a = (float)Gradez.As / NumStudents;
b = (float)Gradez.Bs / NumStudents;
c = (float)Gradez.Cs / NumStudents;
d = (float)Gradez.Ds / NumStudents;
f = (float)Gradez.Fs / NumStudents;
a *= 100.0f;
b *= 100.0f;
c *= 100.0f;
d *= 100.0f;
f *= 100.0f;
printf("%.2f%% of students are getting an A\r\n", a);
printf("%.2f%% of students are getting an B\r\n", b);
printf("%.2f%% of students are getting an C\r\n", c);
printf("%.2f%% of students are getting an D\r\n", d);
printf("%.2f%% of students are getting an F\r\n", f);
}
|
GraderApp.cpp (main file)
| Code: |
#include "GraderApp.h"
char input[8];
unsigned long students;
GradingClass* GC = 0;
int main()
{
SetConsoleTitleA("Grading Application");
system("color 0a");
GoAgain:
printf("Enter the number of students to generate grades for: ");
gets(input);
students = atoi(input); //convert string to int
GC = new GradingClass(students);
GC->ReturnGrades();
GC->CountGrades();
printf("Quit or do it agian?: ");
gets(input);
if(input[0] != 'q' && input[0] != 'Q')
{
ZeroMemory(input, 8);
delete GC;
goto GoAgain;
}
delete GC;
return 0;
}
|
project attached (includes the rest of the source files and a binary exe)
Oh and when I was testing this most of the students were failing lol!! So I gave the ones that were failing 3 tries to get above 60% and if still not then let them fail lol!!
_________________
You know, life moves pretty fast. If you don't stop and look around once in a while, You could miss it!
 |
|
| Back to top |
|
 |
mickym2005 How do I cheat?
Reputation: 0
Joined: 13 Oct 2007 Posts: 8
|
Posted: Tue Dec 09, 2008 2:36 pm Post subject: |
|
|
| this will work great . it looks familiar to what I am doing so i guess I'm on the right track, thanks.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Tue Dec 09, 2008 2:55 pm Post subject: |
|
|
Shouldn't you learn how to do this in Java so you KNOW how to use arrays...?
_________________
|
|
| Back to top |
|
 |
mickym2005 How do I cheat?
Reputation: 0
Joined: 13 Oct 2007 Posts: 8
|
Posted: Tue Dec 09, 2008 5:34 pm Post subject: |
|
|
| yeah i am doing it in java, FerrisBuellerYourMyHero just did it in C++ because that is the language that he knows and to see if it would help me since its basically the same outline with different syntax.
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Tue Dec 09, 2008 5:53 pm Post subject: |
|
|
Arrays are the same in java also...
| Code: |
char[] l = new char[];
int[] i = new int[];
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|