Programming Designs Forums

Programming Designs

You are not logged in.

Announcement

This forum is for archival purposes only. Registration and posting have been disabled.

#1 2007-11-14 02:03 PM

Programming-Designs
Administrator
From: Washington
Registered: 2005-09-27
Posts: 1006
Website

Create a Grade Displayer (simple)

Create a grade display functions that will tell you a grade based on an integer percentage using the following guidelines:

1. Create a function called grade() returning either (a) a char if variable type is supported or (b) if not supported return a string. An int variable should be passed into grade().

The value returned should be A - F. Use the following table to figure out which grade to return:

A : 90-100%
B : 80-89%
C : 70-79%
D : 60 - 69%
F : 59% and below

2. Create a function called gradeA() which returns a string of their grade including pluses and minuses. eg. A-, A, and A+. An int variable should be passed into gradeA().

The value should also return A - F based on the first table but with pluses and minuses.

Example
----------------
60-62% = D-
63-66% = D
67-69% = D+

and

90-92% = A-
93-96% = A
97-100% = A+

I've provided an example on the following post of my submission in C#.

Offline

 

2007-11-14 02:03 PM

Sponsors


#2 2007-11-14 02:04 PM

Programming-Designs
Administrator
From: Washington
Registered: 2005-09-27
Posts: 1006
Website

Re: Create a Grade Displayer (simple)

Submission example in C#

Code:

        static char grade(int percent)
        {
            char[] g = { 'F', 'D', 'C', 'B', 'A'};
            int v = (percent - 50) / 10; 
            v -= v > 4 ? 1 : 0; 
            v = v < 0 ? 0 : v;
            return g[v];
        }

        static string gradeA(int percent)
        {
            if (percent == 100) return "A+";
            char g = grade(percent);
            char[] gd = { '-', (char)0, '+' };
            int v = (percent % 10);
            v = v == 6 ? v / 3 - 1: v / 3;
            v = v > 2 ? 2 : v;
            string x = Convert.ToString(g); x += gd[v];
            return x;
        }

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson