Solved

write a program in c++

Posted on 1997-09-02
16
1,556 Views
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..
0
Comment
Question by:tegiam
  • 5
  • 4
  • 2
  • +4
16 Comments
 
LVL 2

Expert Comment

by:kellyjj
ID: 1168594
Is this a home work assingment?
0
 

Author Comment

by:tegiam
ID: 1168595
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
0
 
LVL 2

Expert Comment

by:kellyjj
ID: 1168596
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,
0
 
LVL 1

Expert Comment

by:peter_vc
ID: 1168597
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.
0
 
LVL 2

Expert Comment

by:alexxx
ID: 1168598
Sorry, this is too dificult a question to be answered here.
0
 
LVL 3

Expert Comment

by:LucHoltkamp
ID: 1168599
Ask your brother. Glad to help you if you have a real question.
.luc.
0
 
LVL 4

Expert Comment

by:Woodster
ID: 1168600
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!
0
 
LVL 4

Expert Comment

by:Woodster
ID: 1168601
By the way - To satisfy your curiosity and answer your question:

This web site works well!
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Expert Comment

by:navigator010897
ID: 1168602
Up the points and I'd be happy to write a small C++ program to do it.
0
 

Author Comment

by:tegiam
ID: 1168603
I'm still not getting the respond i 'm looking for..
0
 
LVL 1

Expert Comment

by:navigator010897
ID: 1168604
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.
0
 

Author Comment

by:tegiam
ID: 1168605
Adjusted points to 100
0
 
LVL 1

Accepted Solution

by:
navigator010897 earned 50 total points
ID: 1168606
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

class EQUIVILANTS
{
private:
      int Max[4];
public:
      EQUIVILANTS();
      char *GetEquivilant(int g);
};

EQUIVILANTS::EQUIVILANTS()
{
      // 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";
      }
      else
            return "High Distinction";
}


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


// 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.  

class STUDENTS : private EQUIVILANTS
{
 private:
  char FullName[50];
  char FirstName[50];
  char LastName[50];
  char Class[50];
  int LastNameExist;
  int NumGrades;
  GRADES Grades[MAXGRADES];

 public:
  STUDENTS();
  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();

};

STUDENTS::STUDENTS()
{
      // 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.

      strcpy(FirstName,FName);
      strcpy(LastName,LName);
      strcpy(FullName,FName);
      strcat(FullName," ");
      strcat(FullName,LName);
}
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;

      strcpy(FullName,Name);
      // 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] == ' ')
            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

      strcpy(Class,C);
}

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++;
            strcpy(Grades[x].testname,g.testname);
            Grades[x].grade = g.grade;
            return 1;

      }
      else
      {
            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)
      {
            x--;
            g.grade = Grades[x].grade;
            strcpy(g.testname,Grades[x].testname);
      }
      else
      {
            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;
      }
      else
      {
            int average=0;

            for (int x = 0; x < NumGrades; x++)
            {
                  average+=Grades[x].grade;
            }
            average/=NumGrades;
            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;
      }
      else
      {
            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;
      }
      else
      {
            int average = 0;

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

}


main()
{
      STUDENTS Student;
      char temp[50];
      GRADES g;
      EQUIVILANTS Words;



      cout << "\t\t\tGrade Calculator" << endl;
      cout << "Enter Student Name: ";
      cin.getline(temp,50);
      Student.SetName(temp);
      cout << "Enter Class Code: ";
      cin >> temp;
      Student.SetClass(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;
                  }
                  else
                        Student.AddGrade(g);
            }
      } 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;      
      else
            cout << Student.GetName() << endl;

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

      Student.OutputGrades();
      int av=Student.GetAverage();

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


 return 0;
}

Sample Run:
C:\Data\sample\Debug>sample.exe
                        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

C:\Data\sample\Debug>



0
 

Author Comment

by:tegiam
ID: 1168607
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;
                                cin>>wait;

Thank you once again
0
 

Author Comment

by:tegiam
ID: 1168608
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 !!

tata
0
 
LVL 1

Expert Comment

by:navigator010897
ID: 1168609
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"
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now