Report Card

Please help me.  I have a problem with a program that's due tomorrow.  It's suppossed to make report cards for 5 different students, each having 5 subjects, 5 credit hours, 5 grades, 5 cr_pts, and at the end, calculate a gpa for each one of them.  I've gotten it to loop for 5 students and each having 5 courses BUT **** happens and somehow, I can't store anything in the student array...I can only use structures (no classes).  Pleez, I need an answer...here's a copy of my coding, take a look at it and see if U could help me...I'm REALLY anxious to get an answer so I'm putting this question up for 200 pts.
//Name:             Marian Quan
//Date:             November 20, 1998
//Name of Program:   Grade Report
//Desc. of Program:  This program is designed to calculate the GPA of five
//                 students who takes five classes.
//Saved As:

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

//declare the structure

struct field
{
   char subj_code [7];
   char subj_title [30];
   int crhrs;
   char letter_grade[2];
   float num_grade;
   float cr_points;
   
} course = { "  ",
           "  ",
           0,
           " ",
           0,
           0
          };

struct person
{
   char fname [10];
   char lname [10];
   float total_crpts;
   float total_crhrs;
   float gpa;
   field course[5];

} student = { "   ",
            "   ",
            0,
            0,
            0
          };

//Fxn Declaration
void get_studName ();
void get_subj_info (int t);
int get_grade(int i);
float convert_grade(int i);
float compute_crpts(int i, int t);
void compute_gpa ();
void output();

//Fxn Definition

void get_studName ()
{
   clrscr ();

   person student [5];
   for (int t=0; t>5; t++) {
   cout<< "Please enter your first name: ";
   cin>> student[t].fname;
   cout<< endl;
   cout<< "Please enter your last name: ";
   cin>> student[t].lname;
   cout<< endl;
   get_subj_info (t);
   }
}

void get_subj_info (int t) {

      for (int i=0; i<5; i++) {
      clrscr ();
      cout<< "Please enter the conventional code of subject # " << i+1 << " that " << student.fname <<endl;
      cout<< "is taking." << endl;
      cout<< "An example of the conventional code format is as follows:" <<endl;
      cout<< "ENG-101." <<endl;
      cout<< "Subject Code:  ";
      cin>> student[t].course[i].subj_code;
      cout<< endl <<endl;
      //cout<< "Please enter the title of the student's " << i << " course." <<endl;
      //cout<< "Subject Title:  ";
      //cin>> student[t].course[i].subj_title;
      //cout<< endl <<endl;
      cout<< "Please enter the amount of credit hours that are allotted to the" <<endl;
      cout<< "course that the student is taking." <<endl;
      cout<< "Credit Hours for " << student.course[i].subj_code << " :  ";
      cin>> student[t].course[i].crhrs;
      cout<< endl <<endl;
      compute_crpts(t,i);

   }

}

int get_grade (int t, int i)
{
   clrscr();
   int grade ;

   cout<< "Please select the letter that corresponds to the student's grade" <<endl;
   cout<< "in the course: " <<student[t].course[i].subj_code                 <<endl;
   cout<< "   (1)   A+                                                     " <<endl;
   cout<< "   (2)   A                                                      " <<endl;
   cout<< "   (3)   B+                                                     " <<endl;
   cout<< "   (4)   B                                                      " <<endl;
   cout<< "   (5)   C+                                                     " <<endl;
   cout<< "   (6)   C                                                      " <<endl;
   cout<< "   (7)   D                                                      " <<endl;
   cout<< "   (8)   F                                                      " <<endl;
   cout<< endl;
   cout<< "Your Choice:  ";
   cout<<endl;
   cin>> grade;
   return (grade);
}

float convert_grade (int t, int i)
{
   int selection;
   
   selection = get_grade(t,i);
   cout<< selection;
   cout<<endl;

   switch (selection) {

   case 1:
      student[t].course[i].letter_grade[i] = 'A+';
      student[t].course[i].num_grade = 4.0;
      cout<< student[t].course[i].num_grade;
      break;

   case 2:
      student[t].course[i].letter_grade [i] = 'A';
      student[t].course[i].num_grade = 3.5;
      cout<< student[t].course[i].num_grade;
      break;

   case 3:
      student[t].course[i].letter_grade [i] = 'B','+';
      student[t].course[i].num_grade = 3.0;
      cout<< student[t].course[i].num_grade;
      break;

   case 4:
      student[t].course[i].letter_grade [i] = 'B';
      student[t].course[i].num_grade = 2.5;
      cout<< student[t].course[i].num_grade;
      break;

   case 5:
      student[t].course[i].letter_grade [i] = 'C','+';
      student[t].course[i].num_grade = 2.0;
      cout<< student[t].course[i].num_grade;
      break;

   case 6:
      student[t].course[i].letter_grade [i] = 'C';
      student[t].course[i].num_grade = 1.5;
      cout<< student[t].course[i].num_grade;
      break;

   case 7:
      student[t].course[i].letter_grade [i] = 'D';
      student[t].course[i].num_grade = 1.0;
      cout<< student[t].course[i].num_grade;
      break;

   case 8:
      student[t].course[i].letter_grade [i] = 'F';
      student[t].course[i].num_grade = 0;
      cout<< student[t].course[i].num_grade;
      break;

   default:
      cout<< "The choice that you have made is invalid.  Let's give this" <<endl;
      cout<< "another try."  <<endl;
      cout<< "   << Please strike any key to view the choices again.>>  " <<endl;
   }

   getch();
   return (student[t].course[i].num_grade);

}

float compute_crpts(int t, int i)
{
   student[t].course[i].num_grade = convert_grade (i,t);

   student[t].course[i].cr_points = (student[t].course[i].crhrs * student[t].course[i].num_grade);
   cout<<endl;
   cout<< student[t].course[i].cr_points;
   cout<<endl;
   getch();
   return (student[t].course[i].cr_points);

}

void compute_gpa () {

   student[t].total_crpts = ((student[t].course[0].cr_points) + (student[t].course[1].cr_points)
              + (student[t].course[2].cr_points) + (student[t].course[3].cr_points)
              + (student[t].course[4].cr_points ));
   student[t].total_crhrs = ((student[t].course[0].crhrs) + (student[t].course[1].crhrs)
              + (student[t].course[2].crhrs) + (student[t].course[3].crhrs)
              + (student[t].course[4].crhrs));
   student[t].gpa = student[t].total_crpts / student[t].total_crhrs;
   cout<< student[t].gpa;
}

void output ()
{
clrscr ();
cout<< endl <<endl  <<endl;
cout<< "*********************************************************************************" <<endl;
cout<< "*                       HARVARD UNIVERSITY AT STANN CREEK                       *" <<endl;
cout<< "*-------------------------------------------------------------------------------*" <<endl;
cout<< "*FIRST SEMESTER, AUGUST TO DECEMBER, 1996                  ACADEMIC FIRST YEAR  *" <<endl;
cout<< "*"                                                                             "*" <<endl;
cout<< "*  STUDENT: " <<student.fname  << " " << student.lname                      << "*" <<endl;
cout<< "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" <<endl;
cout<< "*  COURSE CODE      COURSE TITLE         GRADE     GR. PTS.  CR. HRS.  CR.PTS.  *" <<endl;
cout<< "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" <<endl;
cout<< "*    " <<student.course[0].subj_code  <<"                                 " <<student.course[0].letter_grade <<"       " << student.course[0].num_grade <<"       " <<student.course[0].crhrs <<"       " <<student.course[0].cr_points  <<endl;
cout<< "*    " <<student.course[1].subj_code  <<"                                 " <<student.course[1].letter_grade <<"       " << student.course[1].num_grade <<"       " <<student.course[1].crhrs <<"       " <<student.course[1].cr_points  <<endl;
cout<< "*    " <<student.course[2].subj_code  <<"                                 " <<student.course[2].letter_grade <<"       " << student.course[2].num_grade <<"       " <<student.course[2].crhrs <<"       " <<student.course[2].cr_points  <<endl;
cout<< "*    " <<student.course[3].subj_code  <<"                                 " <<student.course[3].letter_grade <<"       " << student.course[3].num_grade <<"       " <<student.course[3].crhrs <<"       " <<student.course[3].cr_points  <<endl;
cout<< "*    " <<student.course[4].subj_code  <<"                           " <<student.course[4].letter_grade <<"       " << student.course[4].num_grade <<"       " <<student.course[4].crhrs <<"       " <<student.course[4].cr_points  <<endl;
cout<<endl <<endl;
cout<<student.gpa;
}


void main ()
{
get_subj_info (int t);
compute_gpa (int t, int i);
output();
}

Get back to me ASAP.  Thanx a million!
Marian111998Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marian111998Author Commented:
Edited text of question
0
Marian111998Author Commented:
Adjusted points to 200
0
ZoppoCommented:
That's what I think your problem is :

The global indentifier _student_ declared with the _structure person_ is only
one single object, but in the function _get_studName_ the declaration of
_person student[5]_ declares a local array, which is created on stack when calling the
function and is removed from the stack when the function ends, so all data entered inside
this function is deleted.
In the function _get_subj_info_ the array _student_ declared in _get_studName_ is not
declared (because it's local), so any of your references to _student_ in this function works
with the single global student object and not the array (I really don't know, why you don't get compiler errors or warnings with that, because in the scope of this function, _student_ is NOT a pointer).

So, I think you can easily solve it by removing the line _person student[5]_ from the
_get_studName()_ function, replace the declaration of global _student_ with a declaration of and global array, i.e:

#define NR_OF_STUDENTS 5                 // it's always better to define those constants
                                                            // for future extensions
structure person {
.
};   // no declaration here!!

person student [NR_OF_STUDENTS];

void get_studName ()
{
clrscr ();
memset( (void*)student, 0, NR_OF_STUDENTS * sizeof(struct person) ); // empty array
.
}

hope that helps,

ZOPPO
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Marian111998Author Commented:
Hey Zoppo, I got your advice and I just tried it and it doesn't work...but, I think you're right...the problem is, I don't really understand your coding (why no declarations??)...would U pleez, add it in for me cause I get all sorts of screwy messages when I did it.  Also, U asked me why I didn't get all sorts of error messages, I did when I tried to run it for the 5 people introducing the array, but I did it once W/O the array (rather pointless) but hey, I'm desperate and it worked...Newayz, get back to me Please time's a ticking and I feel like I'm going to explode any minute.  Thanx.
0
MithanderCommented:
The reason you don't want a declaration there is because then you create one student.  You don't want to do that.  You want to go to the next line and type:
person student[5];
Makeing an array of 5.  Then in get_studName() you need to remove the line:
person student[5];
and replace it with
memset((void*)student,0,5*sizeof(struct person));
this just resets all of the structs you have created.  If you make these changes then everything should work.

ZOPPO, the points are still yours.
0
cssathyaCommented:
Hi,
This is the modified code of your problem and it is compiling perfectly with possibly a few input errors. The problems in the code were as follows:

1. U had used the structure in all your functions but had neither globalized it nor passed it as a parameter to other functions. Hence in your version, the structure was a local variable for the first function and could not be accessed by other functions.
2. In many places, u had not used the array properly. U had defines the structure as an array of 5, but used it as student.something, which chould have been student[x].something.
3. In another case, u had used cin >> to get a char array(studentname). when u want to get a char array, u have to get it using cin.getline() function and not cin>> as it is not overloaded for char * .
4. When u declared grades, u had used an array of [2], but actually wanted to insert array of 3. (A+ means three characters - A, + and \0). Also u had used '' for initializing the character which can be used only for 1 character and not more. If u want to use more than 1 char, u have to use strcpy() function.

I think all these problems arose because u probably wrote the program in one sitting and then tried to compile it. In practice this is not advisable. U create a function, compile it and test it to see if it works and then go for the next function. In this way, u can solve the problem easily with less errors. This is the concept of modular programming. If u write all the modules at once and try to compile it, what is the purpose of using the modular approach??

Well, these are my views on the program. Hope u get good grades in your exam. All the best.


 //Name:        Marian Quan
 //Date:        November 20, 1998
 //Name of Program:   Grade Report
 //Desc. of Program:  This program is designed to calculate the GPA of five
 //      students who takes five classes.
 //Saved As:

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

 //declare the structure

 struct field
 {
    char subj_code [7];
    char subj_title [30];
    int crhrs;
    char letter_grade[2];
    float num_grade;
    float cr_points;
     
 };

 struct person
 {
    char fname [10];
    char lname [10];
    float total_crpts;
    float total_crhrs;
    float gpa;
    field course[5];

 };

 //Fxn Declaration
 void get_studName ();
 void get_subj_info (int );
 int get_grade(int, int);
 float convert_grade(int );
 float compute_crpts(int , int);
 void compute_gpa (int);
 void output();

 //Fxn Definition
 person student [5];

 void get_studName ()
 {
//    clrscr ();

    for (int t=0; t<5; t++) {
    cout<< "Please enter your first name: ";
    cin>> student[t].fname;
    cout<< endl;
    cout<< "Please enter your last name: ";
    cin>> student[t].lname;
    cout<< endl;
    get_subj_info (t);
    }
 }

 void get_subj_info (int t){

       for (int i=0; i<5; i++) {
//       clrscr ();
       cout<< "Please enter the conventional code of subject # " << i+1 << " that " << student[t].fname <<endl;
       cout<< "is taking." << endl;
       cout<< "An example of the conventional code format is as follows:" <<endl;
       cout<< "ENG-101." <<endl;
       cout<< "Subject Code:  ";
         cin.ignore(1);
       cin.getline(student[t].course[i].subj_code, 7);
       cout<< endl <<endl;
       //cout<< "Please enter the title of the student's " << i << " course." <<endl;
       //cout<< "Subject Title:  ";
       //cin>> student[t].course[i].subj_title;
       //cout<< endl <<endl;
       cout<< "Please enter the amount of credit hours that are allotted to the" <<endl;
       cout<< "course that the student is taking." <<endl;
       cout<< "Credit Hours for " << student[t].course[i].subj_code << " :  ";
       cin >>student[t].course[i].crhrs;
       cout<< endl <<endl;
       compute_crpts(t,i);

    }

 }

 int get_grade (int t, int i )
 {
  //  clrscr();
    int grade ;

    cout<< "Please select the letter that corresponds to the student's grade" <<endl;
    cout<< "in the course: " <<student[t].course[i].subj_code                 <<endl;
    cout<< "   (1)   A+                                                     " <<endl;
    cout<< "   (2)   A                                                      " <<endl;
    cout<< "   (3)   B+                                                     " <<endl;
    cout<< "   (4)   B                                                      " <<endl;
    cout<< "   (5)   C+                                                     " <<endl;
    cout<< "   (6)   C                                                      " <<endl;
    cout<< "   (7)   D                                                      " <<endl;
    cout<< "   (8)   F                                                      " <<endl;
    cout<< endl;
    cout<< "Your Choice:  ";
    cin>> grade;
    return (grade);
 }

 float convert_grade (int t, int i)
 {
    int selection;
     
    selection = get_grade(t,i);
    cout<< selection;
    cout<<endl;

    switch (selection) {

    case 1:
       strcpy(student[t].course[i].letter_grade ,"A+");
       student[t].course[i].num_grade = 4.0;
       cout<< student[t].course[i].num_grade;
       break;

    case 2:
       strcpy(student[t].course[i].letter_grade ,"A ");
       student[t].course[i].num_grade = 3.5;
       cout<< student[t].course[i].num_grade;
       break;

    case 3:
       strcpy(student[t].course[i].letter_grade, "B+");
       student[t].course[i].num_grade = 3.0;
       cout<< student[t].course[i].num_grade;
       break;

    case 4:
       strcpy(student[t].course[i].letter_grade , "B ");
       student[t].course[i].num_grade = 2.5;
       cout<< student[t].course[i].num_grade;
       break;

    case 5:
       strcpy(student[t].course[i].letter_grade , "C+");
       student[t].course[i].num_grade = 2.0;
       cout<< student[t].course[i].num_grade;
       break;

    case 6:
       strcpy(student[t].course[i].letter_grade , "C ");
       student[t].course[i].num_grade = 1.5;
       cout<< student[t].course[i].num_grade;
       break;

    case 7:
       strcpy(student[t].course[i].letter_grade , "D ");
       student[t].course[i].num_grade = 1.0;
       cout<< student[t].course[i].num_grade;
       break;

    case 8:
       strcpy(student[t].course[i].letter_grade , "F ");
       student[t].course[i].num_grade = 0;
       cout<< student[t].course[i].num_grade;
       break;

    default:
       cout<< "The choice that you have made is invalid.  Let's give this" <<endl;
       cout<< "another try."  <<endl;
       cout<< "   << Please strike any key to view the choices again.>>  " <<endl;
    }

    getch();
    return (student[t].course[i].num_grade);

 }

 float compute_crpts(int t, int i)
 {
    student[t].course[i].num_grade = convert_grade (i,t);

    student[t].course[i].cr_points = (student[t].course[i].crhrs * student[t].course[i].num_grade);
    cout<<endl;
    cout<< student[t].course[i].cr_points;
    cout<<endl;
    getch();
    return (student[t].course[i].cr_points);

 }

 void compute_gpa (int t) {

    student[t].total_crpts = ((student[t].course[0].cr_points) + (student[t].course[1].cr_points)
   + (student[t].course[2].cr_points) + (student[t].course[3].cr_points)
   + (student[t].course[4].cr_points ));
    student[t].total_crhrs = ((student[t].course[0].crhrs) + (student[t].course[1].crhrs)
   + (student[t].course[2].crhrs) + (student[t].course[3].crhrs)
   + (student[t].course[4].crhrs));
    student[t].gpa = student[t].total_crpts / student[t].total_crhrs;
    cout<< student[t].gpa;
 }

 void output ()
 {
// clrscr ();
 cout<< endl <<endl  <<endl;
 cout<< "*********************************************************************************"
 <<endl;
 cout<< "*                       HARVARD UNIVERSITY AT STANN CREEK                       *" <<endl;
 cout<< "*-------------------------------------------------------------------------------*" <<endl;
 cout<< "*FIRST SEMESTER, AUGUST TO DECEMBER, 1996                  ACADEMIC FIRST YEAR  *" <<endl;
 cout<< "*"                                                                             "*" <<endl;
 for(int i=0;i<5;i++)
 {
 cout<< "*  STUDENT: " <<student[i].fname  << " " << student[i].lname                      << "*" <<endl;
 cout<<
 "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
 <<endl;
 cout<< "*  COURSE CODE      COURSE TITLE         GRADE     GR. PTS.  CR. HRS.  CR.PTS.  *" <<endl;
 cout<<
 "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
 <<endl;
 cout<< "*    " <<student[i].course[0].subj_code  <<"                                 " <<student[i].course[0].letter_grade <<"       " <<
 student[i].course[0].num_grade <<"       " <<student[i].course[0].crhrs <<"       " <<student[i].course[0].cr_points  <<endl;
 cout<< "*    " <<student[i].course[1].subj_code  <<"                                 " <<student[i].course[1].letter_grade <<"       " <<
 student[i].course[1].num_grade <<"       " <<student[i].course[1].crhrs <<"       " <<student[i].course[1].cr_points  <<endl;
 cout<< "*    " <<student[i].course[2].subj_code  <<"                                 " <<student[i].course[2].letter_grade <<"       " <<
 student[i].course[2].num_grade <<"       " <<student[i].course[2].crhrs <<"       " <<student[i].course[2].cr_points  <<endl;
 cout<< "*    " <<student[i].course[3].subj_code  <<"                                 " <<student[i].course[3].letter_grade <<"       " <<
 student[i].course[3].num_grade <<"       " <<student[i].course[3].crhrs <<"       " <<student[i].course[3].cr_points  <<endl;
 cout<< "*    " <<student[i].course[4].subj_code  <<"   " <<student[i].course[4].letter_grade <<"       " <<
 student[i].course[4].num_grade <<"       " <<student[i].course[4].crhrs <<"       " <<student[i].course[4].cr_points  <<endl;
 cout<<endl <<endl;
 compute_gpa(i);
 }
 }


 void main ()
 {
 get_studName();
 output();
 }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Marian111998Author Commented:
Hey cssathya,
   Your program is great!  It works using all the ignore stuff and the stringcpy stuff that I never knew about (I'm only taking an intro course with no book...so u can imagine how "in-the-dark" I feel.  Newayz, I'm giving U all the points I have wich is only 220, but can U pls tell me how to save my float numbers like grades as 4.00, 2.00 as opposed to just 4 and 2 etc.??

Also, I don't know if this would be illegal, but since I have no more points, I'm a start a new account for help on my final project:  an ATM machine...do U think U'd be able to help me with that one??  Well, I'm a start it from today and I'll put the answer up for all the points the account accumulates.  Don't get me wrong, I'm not a leech, I'm gonna try to get something working first..but it's really hard to do stuff without a book cause I don't know how to fix stupid little problems.  Newayz, get back to me...K?  
Thank a million* infinity!

Mar.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.