ok. i'm having trouble understanding how to manipulate my data. this is what i have so far with my program. my input data is coming from two different file. the first file looks like this that has the student ID, last name, first name...

567 white Robert
43 blackBurBn DOnna
etc...

the second file is set up so that the ID number is first with exam(E), number and grade and hw(H), number and score to follow in no particular order and can be dupes for more than once to get all grades. Q signifying end of line...

43 E 1 95 E 2 89 Q
567 E 1 67 H 1 20 H 5 20 Q
43 H 4 15 H 3 14 Q
etc...

this is my program so far...

#include <iostream>
#include <fstream>
#include <cstring>
#include <cctype>
#include <iomanip>

using namespace std;

const int MAX = 30;
const int MAX_HW = 10;
const int MAX_E = 3;


struct file1
{
  int id;
  string fname;
  string lname;
  int hw_num [MAX_HW];
  int exam_num [MAX_E];
  double exam_score;
  double hw_score;
};

void fixstring (string&);
void get_data (file1 [], int&);
void alpha (file1 [], int);
void initial (file1 [], int);
void first (file1 [], int);


int main ()
{


  string filename1;
  string studentinfo;
  string filename2;
  string gradeinfo;
  string filename3;
  string results;
  char ch;
  int x, x1, y, y1, z, z1;


  file1 names [MAX];
  //file2 grades [MAX];

  ifstream inf1;
  ifstream inf2;
  ofstream outf;
  int n = 0;

  cout << "Please enter name of student information file:" << endl;
  cin >> filename1;
 cout << "Please enter name of grade information file:" << endl;
  cin >> filename2;
  cout << "Please enter name of output file:" << endl;
  cin >> filename3;

  inf1.open (filename1.c_str());
  inf2.open (filename2.c_str());
  outf.open (filename3.c_str());

  initial (names, n);

  inf1 >> names[n].id;

  while (!inf1.eof())
    {

      inf1 >> names[n].lname >> names[n].fname;
      fixstring (names[n].lname);
      fixstring (names[n].fname);
      n++;
      inf1 >> names[n].id;
    }

  inf1.close();

  alpha(names, n);
  outf << right << setw (4) << "NAME" << setw (40) << "ID#" << endl;
  for ( int x = 0; x < n; x ++)
    {
      //outf << names[n].fname << ", " << names[n].lname << names[n].id << endl;
      outf << names[x].lname << ", " << names[x].fname << right << setw (40 - names [x].lname.length () - names [x].fname.length ()) << names\
 [x].id << endl;
    }
  outf << endl <<endl;
 outf << right << setw (44) << "HOMEWORK" << endl;
  outf << left << setw (44) << "NAME";
  for (int y = 1; y <= 10; y++)
    outf << right << setw (5) << y;
  outf << endl;


  for ( int x = 0; x < n; x ++)
    {
      //outf << names[n].fname << ", " << names[n].lname << names[n].id << endl;
      outf << names[x].lname << ", " << names[x].fname << left  <<  setw (40 - names [x].lname.length () - names [x].fname.length ()) << " ";
      for (int y = 1; y <= 10; y++)

        outf << right << setw (5) << y;
      outf << endl;



    }
  outf << endl <<endl;

  outf << right << setw (44) << "EXAM" << endl;
  outf << left << setw (44) << "NAME";
  for (int y = 1; y <= 3; y++)
    outf << right << setw (5) << y;
  outf << endl;
  for ( int x = 0; x < n; x ++)
    {
      //outf << names[n].fname << ", " << names[n].lname << names[n].id << endl;
      outf << names[x].lname << ", " << names[x].fname << right  << endl;
    }
  outf << endl <<endl;




  outf.close ();
 return 0;
}


  void fixstring (string& names)
  {
    int wlen = names.length();
    names[0] = toupper (names[0]);
    for (int i = 1; i < wlen; i++)
      names [i] = tolower (names[i]);
  }

  void alpha ( file1 names [], int n)
  // Given the string "names", alpha will read in the file and place and arrange the names accordingl \
    // y and put them in a particular order.  The alphabetized array of strings will then be passed back.
  {
    int i;// initializing integer datatype to i
    int j;// intiializing integer datatype to j
    file1 temp;// string datatype being justified for temp to be used within function

    for (i=0; i < n-1; i++)
      {
        for (j=0; j < n - (i+1); j++)
          {
            if (names[j].lname > names [j+1].lname)
              {
                temp = names[j];
                names [j] = names [j+1];
                names [j+1] = temp;
              }
          }
      }

  }
void initial (file1 names[], int n)
{
  int x, q;
  for (x = 0; x < n; x++)
    {
      cin >> names[n].id;
      for (q = 0; q = 10; q++)
        names[n].hw_num[q] = 0;
    }
}

i know i have some extra lines and functions here that i just left in but notated that they arent being used at this time. after compiling my program, this is my results...

NAME                                     ID#
Blackburn, Donna                        43
Brown, Jane                             19
Grey, James                            722
White, Robert                          567


                                    HOMEWORK
NAME                                            1    2    3    4    5    6    7    8    9   10
Blackburn, Donna                              1    2    3    4    5    6    7    8    9   10
Brown, Jane                                   1    2    3    4    5    6    7    8    9   10
Grey, James                                   1    2    3    4    5    6    7    8    9   10
White, Robert                                 1    2    3    4    5    6    7    8    9   10


                                        EXAM
NAME                                            1    2    3
Blackburn, Donna
Brown, Jane
Grey, James
White, Robert

i know that even if it compiles and gives back this data, i am doing it wrong. the first thing i'm trying to figure out is how am i supposed to initialze my homework starting grades so that they are zeroes instead of the my number increment count.

the second thing i'm not understanding is how do i set up my program, once i initialize my data, to know when reading from the second input that 43 = Blackburn, Donna, and to start plugging the appropriate grades in the appropriate slot. i know i'm not the best when it comes to syntax so any modifications/suggestions to make my program more efficient would be greatly appreciated.

names[0] = toupper (names[0]);

Is it not giving any compilation warning /error ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.