|
-
Mar 20th, 2008, 12:56 PM
#1
Thread Starter
Hyperactive Member
Classes in Classes
In my teacher gradebook program, I have several VB classes set up for the framework of the program.
I have the following classes so far.
Student (has all the student info like names, address, booknumber, grade list, attendance list, parent info etc)
Parent (info about a student's parents
Assignment (info about each assignment like page, perfect score, date assigned, kind of assignment - test or homework, etc)
Grade (has fields Value and Info, and a function PercentCorrect()
In the student class, I've set up a 2-dimensional array of grades (of type Grade Class).
But I'm not sure how to set up Get and Set statements within the Student class that refer to the Grade class.
In my main program, I want to do something like
Student(i).Grade(1,1).Value = "85" 'yes I know it's a string
Student(i).Grade(1,1).Info = "needs to redo this one" 'field for my notes on the student
Student(i).Grade(1,1).PercentCorrect = ????
Now another point. The perfect score for this assignment is held in the Assignment class. I can access it with something like
ps = Assignment(1,1).PerfectScore
Now I haven't tried it yet but will I be able to access this PerfectScore info from my Grade class to actually calculate the perfect score? Or do I need to include PerfectScore as a field in the Grade class? If so, then I have to update it for EACH student and for EACH grade. If I keep it in the Assignment class, then it only has to be changed once.
Confused yet? I am.
Any tips for me?
-
Mar 20th, 2008, 01:28 PM
#2
-
Mar 20th, 2008, 01:38 PM
#3
Re: Classes in Classes
If you include the assignment for the student as a property, you should be able to access the PerfectScore for that assignment. For each assignment, that is. But your 2-D array logic escapes me.
-
Mar 20th, 2008, 02:09 PM
#4
Re: Classes in Classes
Whenever you think you need a 2D array, consider whether or not you could make a 1D array of some type of class instead. 1D arrays are vastly easier to work with in VB, especially since the List (of Type) generic list was added in 2005.
My usual boring signature: Nothing
 
-
Mar 20th, 2008, 11:25 PM
#5
Re: Classes in Classes
I'd be inclined to use a Dictionary for this. Each Student takes Assignments and receives a Grade for each one. There needs to be a specific relationship between the Assignments and the Grades and the Dictionary provides that:
vb.net Code:
Public Class Student Private _assignments As New Dictionary(Of Assignment, Grade) Public ReadOnly Property Assignments() As Dictionary(Of Assignment, Grade) Get Return Me._assignments End Get End Property End Class
Now, when you create an Assignment you can add it to all the Students who take it:
vb.net Code:
Dim assignment1 As New Assignment For Each s As Student In students s.Assignments.Add(assignment1, Nothing) Next s
When a student completes an assignment you can set the grade for it:
vb.net Code:
someStudent.Assignments(assignment1) = someGrade
If you want to find out what grade a student got for a particular assignment you can get it easily:
vb.net Code:
Dim g As Grade = someStudent.Assignments(assignment1)
-
Mar 21st, 2008, 01:07 PM
#6
Thread Starter
Hyperactive Member
Re: Classes in Classes
But Grade is a VB Class that has several properties.
vb Code:
Public Class Grade Private pValue as string Private pInfo as string Public Property Value as string Public Property Info as string Public Function PercentCorrect as Integer End Class
So I don't see how
Dim g As Grade = someStudent.Assignments(assignment1)
will return the Value or Info or even PercentCorrect for me.
-
Mar 21st, 2008, 01:10 PM
#7
Thread Starter
Hyperactive Member
Re: Classes in Classes
kleinma, it's a 2d array because I have 4 sets of grades for each student. Our school year is divided in to 4 "9 weeks" periods. I need grades for the "1st 9 weeks", "2nd 9 weeks", "3rd 9 weeks", and "4th 9 weeks".
So a 2d array makes sense to me. Don't you agree? Am I missing something?
-
Mar 21st, 2008, 01:23 PM
#8
Thread Starter
Hyperactive Member
Re: Classes in Classes
If I could figure out a way to make the DataGridView control keep up with all the extra "assignment info" then I wouldn't need to keep up with the array at all.
I couldn't probably create a custom GridControl and add extra properties to the Grid's Columns (assignments) and Rows (students).
For example, each DataGridViewColumn (grades/assignments) could have the following extra properties
.Page
.PerfectScore
.DateAssigned
.DateTurnedIn
.PerfectScore
etc.
And each DataGridViewRow (students) could have
.FirstName
.LastName
.MinimumDGrade (some students have modified grade scales)
.MinimumCGrade
.MinimumBGrade
.MinimumAGrade
.EmailAdress
.HomePhone
.BookNumber
.BookTurnedIn
etc.
Then, when the cursor moves to a different cell in the grid, the .CellChanged event could fire code to update the displayed information. There would be no need for any trick array manipulation because all of the info would be stored in the controls.
I had wanted to do it this way last year when I started rewriting my old GradeBook which I initially wrote in VB6. It still does the job but I'd like to have some new features - like attendance.
Does anyone think I should go with the non-array idea?
-
Mar 22nd, 2008, 05:07 AM
#9
Re: Classes in Classes
 Originally Posted by DroopyPawn
But Grade is a VB Class that has several properties.
vb Code:
Public Class Grade
Private pValue as string
Private pInfo as string
Public Property Value as string
Public Property Info as string
Public Function PercentCorrect as Integer
End Class
So I don't see how
Dim g As Grade = someStudent.Assignments(assignment1)
will return the Value or Info or even PercentCorrect for me.
You don't see how? You just said it yourself. Grade is a class that has several properties. This:
VB.NET Code:
Dim g As Grade = someStudent.Assignments(assignment1)
gives you a Grade object, from which you can get any or all of those properties:
VB.NET Code:
Dim value As String = g.Value
Dim info As String = g.Info
Dim percentCorrect As Integer = g.PercentCorrect
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|