We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


write a program in c++

tegiam asked
Medium Priority
Last Modified: 2010-07-27
My intention is just to test how well this Website works..
The question sounds like this.......

> Write a program that will calculate a final mark and grade for an sft1101
> student ( sft is a code for a subject ).the program should prompt a user
> for the name of the student and then prompt for each separate assessment
> component for that student.The final mark and grade is then calculated and
> displayed on the screen.

> The grade are allocated according to the rules shown in figure 1.However,
> a student is to be allocated a fail if less than 40% is obtained for the
> assigment or for the exam component.In each of these case an appropriate
> message must be displayed.

>       |     mark obtained   |    grade  allocated  |
>              ------------------------------------------------------------
>                 0-49                    fail
>                 50-59                   pass
>                 60-69                   credit
>                 70-79                   distinction
>                 80-100                  high distinction

> Your program must be written so that it consists of several differnt
> functions.Your program should allow the student name to consist of one or
> several words..
Watch Question

Is this a home work assingment?


This was my younger brother homework assignment
and he obtained 9/10 for that question....
Just wanna check whether the answers from expert
exchange have any difference..And how effective is
this program.....By the way I'm new to this EE

Thanks for replying

Well,  I think you'll like EE.  However, These type of questions don't get answered unless there are a lot more points offered.   The more points, more likely to get answer,

If you just want to see how it works, why not spend your points looking at some previously answered questions instead of wasting our time on hypothetical questions.  

Of course the answer will be different than your brothers question because everyone has their own unique style and approach.

Sorry, this is too dificult a question to be answered here.
Ask your brother. Glad to help you if you have a real question.

Hmmm, Looks EXACTLY like a question currently in the comp.lang.c newsgroup that is currently receiving a barrage of replies along the same lines as those already listed above.

Don't you realise that a lot of the people here also check the relevant newsgroups?  If you can't do this one yourself, then you're not going to get very far with C++!

Brother's assignment???  I don't think so!

By the way - To satisfy your curiosity and answer your question:

This web site works well!
Up the points and I'd be happy to write a small C++ program to do it.


I'm still not getting the respond i 'm looking for..
You have to understand something about this site, you aren't going to get the response you are looking for for the given amount of points.  Granted it is an easy question to answer, but few people are willing to sit down and write an entire program for 50 points.  Most questions that you are going to ask for code for, especially an entire program is valued at 100 points.

50 points might be for help in class structure for holding the student, all their grades, etc.


Adjusted points to 100
Ok, here is your program.  As you put it that you wanted it in C++, functions are put inside of class, specifically, there are 2 classes, one that holds the student and his/her information and grades, and the second, a very simple class, converts a numerical value into a english grade equivilant.  I know, the class was not really needed, but I felt it offered something nice, this way, if more grade ranks are added, it would be easy to modify just this class and have everything else that depends on it work correctly with the new grade scale.

So, since you speficied that it was to be c++ in the title, there are multiple functions, they are just located within the classes.

Below is the code, and a sample run.

#include <iostream.h>
#include <string.h>

// Various defines required by the program to make certain
// modifications simpler in the future.

#define MAXGRADES 30
#define TRUE      1
#define FALSE      0
#define MAXVAL      100
#define MINVAL      0

// Equivilants class - designed to produce an english equivilant
// for numerical values passed to it

      int Max[4];
      char *GetEquivilant(int g);

      // Constructor creates the base table needed by the
      // GetEquivilant function

      Max[0] = 50;
      Max[1] = 60;
      Max[2] = 70;
      Max[3] = 80;

char *EQUIVILANTS::GetEquivilant(int g)

      // Compares the value in g to the base values stored
      // in the table and returns the english equivilant
      // to the value g.  ie: if g is < 50 (49 or less) the
      // function returns "Fail"

      if (g < Max[0])
            return "Fail";
      else if (g < Max[1])
            return "Pass";
      else if (g < Max[2])
            return "Credit";
      else if (g < Max[3])
            return "Distinction";
            return "High Distinction";

typedef struct {
        char testname[50];
        int grade;

// Students class - designed to hold the student information,
// including first name, last name, full name, grades with
// test names, and the student class.  This class also has
// a variety of methods to allow access to the private
// data members.  

  char FullName[50];
  char FirstName[50];
  char LastName[50];
  char Class[50];
  int LastNameExist;
  int NumGrades;

  STUDENTS(char *, char *);
  void SetName(char *Name);
  void SetClass(char *C);
  char *GetName();
  char *GetFName();
  char *GetLName();
  char *GetClass();
  int LastNExist();
  int GetNumGrades();
  int AddGrade(GRADES g);
  GRADES GetGrade(int x);
  int GetAverage();
  void OutputGrades();
  void OutputAverage();


      // Initialize everything to 0 or FALSE

      FirstName[0] = '\0';
      LastName[0] = '\0';
      FullName[0] = '\0';
      NumGrades = 0;
      Class[0] = '\0';
      LastNameExist = FALSE;

STUDENTS::STUDENTS(char *FName, char *LName)
      // A students class was created with the firstname
      // and last name being passed to the constructor.

      strcat(FullName," ");
void STUDENTS::SetName(char *Name)
      // Handles setting the name and determining if the
      // name passed was a first last name combo

      unsigned int x=0, y=0;

      // Now, pull out first and last name, if applicable

      while ((x<strlen(Name)) && (Name[x] != '\0') && (Name[x]!=' '))
            FirstName[x] = Name[x++];
      FirstName[x] = '\0';
      if (Name[x] == ' ')
      while (Name[x]!='\0')
            LastName[y++] = Name[x++];
      LastName[y] = '\0';
      if (y >0)
            LastNameExist = TRUE;

void STUDENTS::SetClass(char *C)
      // Sets the students class


char *STUDENTS::GetName()
      // Gets the full name

      return FullName;
char *STUDENTS::GetFName()
      // Gets the first name

      return FirstName;
char *STUDENTS::GetLName()
      // Gets the last name

      return LastName;

int STUDENTS::LastNExist()
      // Returns whether a last name exists or not.

      return LastNameExist;

char *STUDENTS::GetClass()
      // Returns the students class

      return Class;

int STUDENTS::GetNumGrades()
      // Returns the number of grades entered.

      return NumGrades;
int STUDENTS::AddGrade(GRADES g)

      // Adds a grade to the list of grades for the student.

      int x;

      if ((NumGrades+1) < MAXGRADES)
            x = NumGrades++;
            Grades[x].grade = g.grade;
            return 1;

            cout << "ERROR: Max number of names reached"<<endl;
            return 0;
GRADES STUDENTS::GetGrade(int x)
      // returns a specific grade located at entry X

      GRADES g;

      if (NumGrades >= x)
            g.grade = Grades[x].grade;
            cout << "Error: Grade requested does not exist"<<endl;
            g.grade = -1;
            g.testname[0] = '\0';

      return g;
int STUDENTS::GetAverage()

      // Gets the average of all the students grades.  
      // This is all done in ints, so some rounding might
      // occur that could change the grade from what it might
      // be if done with floats or a calculator

      if (NumGrades == 0)
            cout << "Error: No grades to create an average" << endl;
            return 0;
            int average=0;

            for (int x = 0; x < NumGrades; x++)
            return average;
void STUDENTS::OutputGrades()

      // Generates a table of grades and outputs to the screen

      if (NumGrades == 0)
            cout << "Error: No grades to output" << endl;
            cout << "Test" << "       " << "Number Grade" << "     " << "English Equivilant" << endl << endl;

            for (int x = 0; x < NumGrades; x++)
                  cout << Grades[x].testname << "\t\t" << Grades[x].grade << "\t\t" << GetEquivilant(Grades[x].grade) << endl;

            cout << endl;

void STUDENTS::OutputAverage()
      // Finds the average, and outputs the numeric and
      // english equivilant to the students average.

      if (NumGrades == 0)
            cout << "Error: No grades to create average" << endl;
            int average = 0;

            for (int x = 0; x < NumGrades; x++)
                  average+= Grades[x].grade;
            cout << FullName << "\'s average is: " << average << " Or: " << GetEquivilant(average) << endl;


      STUDENTS Student;
      char temp[50];
      GRADES g;
      EQUIVILANTS Words;

      cout << "\t\t\tGrade Calculator" << endl;
      cout << "Enter Student Name: ";
      cout << "Enter Class Code: ";
      cin >> temp;
      cout << "Enter Grades, to complete grade list, type end" <<endl;
      do {
            cout << "Test Name: ";
            cin >> g.testname;
            if (strcmp(g.testname,"end"))
                  cout << "Test Grade: ";
                  cin >> g.grade;
                  if ((g.grade < MINVAL) || (g.grade > MAXVAL))
                        cout << "Error: Grade exeeds either the upper or lower limit." << endl;
                        cout << "       That entry has not been added to the students grade list." << endl;
      } while (strcmp(g.testname,"end"));

      // Output the grades, first is to output the list of grades
      // inputted, using the built in class function, the second
      // part is to output the average, the average value is calculated
      // by a STUDENT class function (or method) and the word value
      // of the overall grade is displayed using a class that is
      // in this case created inside of main - We could have used
      // the Student.OutputAverage() which uses the same function
      // through inheritance.
      cout << endl << endl;

      cout << "Student: ";
      if (Student.LastNExist())
            cout << Student.GetLName() << ", " << Student.GetFName() << endl;      
            cout << Student.GetName() << endl;

      cout << "For Class: " << Student.GetClass() << endl << endl;

      int av=Student.GetAverage();

            cout << "Average: " << av << " Or: " << Words.GetEquivilant(av) << endl;

 return 0;

Sample Run:
                        Grade Calculator
Enter Student Name: Jim Jones
Enter Class Code: st1101
Enter Grades, to complete grade list, type end
Test Name: T1
Test Grade: 80
Test Name: T2
Test Grade: 55
Test Name: T3
Test Grade: 44
Test Name: end

Student: Jones, Jim
For Class: st1101

Test       Number Grade     English Equivilant

T1              80              High Distinction
T2              55              Pass
T3              44              Fail

Average: 59 Or: Pass


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Thank you for your generous support !
Just to give some feed back ;
The answers are too long for a question like this.
Maybe you have been doing a lot of long and complicating program.
You have missed out something " int wait;

Thank you once again


You have not really completed the program...
When i test it with other characters beside integer for the
grades the system crash....... so you fail !!!
Try again !!

I'm sorry, but you asked for an answer to your question.  Your question did not specify that one had to be able to process ASCII characters as well as integers for the grades - I had followed your instructions.

I'm sorry to say that I probably would have done well in a teachers eyes, as in school they usually set forth standards, I followed the standards, and added some features to make the objects more usable/re-usable.  

Hell, the program could have been written all inside of main with a few loops, and a few variables - or it could have been written with a few functions.  I choose classes as you had specified C++.  I don't know what your "int wait;    cin >> wait "  unfortunately, if you are looking for weighted grades, you should have specified that in the "assignment"
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.