Hi all,
Just came across this one minor issue that I wanted to know what I can do about it.
The prompt that I was trying to make was that given two tests scores (all less than or equal to 100), I created a child class from that class where my code looked something like this for the setting up of the classes.
/*-----CLASSES-----*/
class the_tests;
rand bit [6:0] test1;
rand bit [6:0] test2;
constraint limit_score {test1 <= 100;
test2 <= 100;};
endclass : the_tests
// used for categorical constraints
typedef enum {F, D, C, B, A} grade;
// child class
class myGrade extends the_tests;
rand grade grade_type;
bit [6:0] average;
function int get_average();
average = ((test1 + test2)/2);
return average;
endfunction
constraint grade_range
{
(grade_type == F) -> average inside {[0:50]};
(grade_type == D) -> average inside {[51:60]};
(grade_type == C) -> average inside {[60:79]};
(grade_type == B) -> average inside {[80:89]};
(grade_type == A) -> average inside {[90:100]};
}
endclass : myGrade
But in my initial block, I used the following code:
initial begin
myGrade students;
students = new;
repeat(10) begin
if(students.randomize() == 1)
begin
$display("First Test = %d Second Test = %d Final Score: %0d Final Grade: %s\n", students.test1, students.test2, students.get_average(), students.grade_type.name());
end
else
$display("RANDOMIZATION FAILED \n");
end
$finish;
end
This thus gave me correct results except for printing out Final Grade. The following are my results.
First Test = 37 Second Test = 28 Final Score: 32 Final Grade: F
First Test = 90 Second Test = 73 Final Score: 81 Final Grade: F
First Test = 25 Second Test = 65 Final Score: 45 Final Grade: B
First Test = 15 Second Test = 59 Final Score: 37 Final Grade: F
First Test = 40 Second Test = 22 Final Score: 31 Final Grade: F
First Test = 68 Second Test = 2 Final Score: 35 Final Grade: F
First Test = 42 Second Test = 71 Final Score: 56 Final Grade: F
First Test = 67 Second Test = 83 Final Score: 75 Final Grade: D
First Test = 14 Second Test = 48 Final Score: 31 Final Grade: C
First Test = 89 Second Test = 29 Final Score: 59 Final Grade: F
It seems to me that the FInal Grade is displaying based on the previous Final Score, so is there any way I could perhaps match that displaying of Final Grade correctly to its respective final score?
Sorry for the long read.
Sangwoo