1
$\begingroup$

So, this is a homework question posed by my teacher:

"A student has 10 courses. Find the ceiling value of the obtained marks and corresponding grade according to the following data enter image description here

Print the result in tabular form with proper headings."

All right, so far i've done this much:

m = Table[Random[Real, {0, 100}, 4], {10}];
c = Ceiling[m];

l = {};

Do[If[c[[n]] < 40, Append[l, 0], If[39 < c[[n]] < 45, Append[l, 2], If[
44 < c[[n]] < 50, Append[l, 2.25], If[49 < c[[n]] < 55, Append[l, 
      2.5], If[54 < c[[n]] < 60, Append[l, 2.75], If[59 < c[[n]] < 
          65, Append[l, 3], If[64 < c[[n]] < 70, Append[l, 
          3.25], If[69 < c[[n]] < 75, Append[
          l, 3.5], If[74 < c[[n]] < 80, Append[l, 
            3.75], If[c[[n]] > 79, Append[l, 4]]]]]]]]]]], {n, 10}];

So, my plan was to form a list(l) consisting the ten obtained grades as elements and then use it in a TableForm expression to form the table. But unfortunately this list l isn't forming for some reason. I'm using Mathematica 5.2. So, what am i doing wrong? Is my plan incorrect? Is there any other (but easily explainable) way to solve this problem?

Thanks in advance.

p.s: i'm relatively new to mathematica.

$\endgroup$
1
  • $\begingroup$ Sir, I think v5.2 is good enough for this 'not so complicated' problem. Besides, I've tried writing the same thing in v10. Gives the same output (i.e. l={} which i basically started with). The only reason i'm using v5.2 cz upto this year, my institution will be using that. Then, it will introduce v9. But unfortunately, i need the answer before that. thanks $\endgroup$ Dec 15, 2014 at 19:40

2 Answers 2

1
$\begingroup$

Using Piecewise is a good choice.

gradePoint[grade_] := 
With[{g = Ceiling[grade]}, 
  Piecewise[{{4., g >= 80}, {3.75, g >= 75}, {3.5, g >= 70}, 
    {3.25, g >= 65}, {3., g >= 60}, {2.75, g >= 55}, 
    {2.5, g >= 50}, {2.25, g >= 45}, {2., g >= 40}}, 0]];

You may check whether the function works perfectly.

Plot[gradePoint[grade], {grade, 0, 100}]

Remaining tasks are relatively simple:

Generate random samples,

sample = RandomReal[{0, 100}, 30];

And get the result,

Join[{{"Marks", "G. P."}}, {Ceiling[#], gradePoint[#]} & /@ sample] // TableForm
$\endgroup$
3
  • $\begingroup$ so far your answer is good. but could you tell me how to get the GPA i.e the average of the GPs? i was thinking to use Mean command. could you show me how to? $\endgroup$ Dec 16, 2014 at 11:49
  • $\begingroup$ also, how to use PaddedForm to make the table look a bit more neat? $\endgroup$ Dec 16, 2014 at 12:05
  • $\begingroup$ never mind, i've figured it out $\endgroup$ Dec 16, 2014 at 21:38
1
$\begingroup$

You can use TableForm to set up the table.

row1 = {"GP", 0, 2., 2.25, 2.5, 2.75, 3.0, 3.25, 3.75, 4.};
row2 = {"Marks", "0-39", "40-44", "45-49", "50-54", "55-59", 
                 "60-64", "65-69", "70-74", "75-79", "80-100"};
{row2, row1} // TableForm

It wasn't clear to me what you want to do with this data, but you can get the mean of the GPs with

Mean[Rest[row1]]

(the Rest removes the first entry form the mean calculation.)

$\endgroup$
1
  • $\begingroup$ I meant average of the "obtained" GPs. sir i'm sorry if i wasn't able to make the problem clear. what you gave as an answer only recreates the data in the question. my task isn't to reform the table of the question. the table in the question gives some ranges of marks and their corresponding grade points. suppose a student gets his exam result of ten courses(here, the marks should be randomly generated by mathematica). my task is to write a set of commands that would make a table containing the ceiling values of the obtained marks and their corresponding GPs. and in the end, finding the GPA. $\endgroup$ Dec 16, 2014 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.