Thread: need some help with organizing output for students

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    need some help with organizing output for students

    Okay, I have the basis for the rpogram I am doing, it basically is supposed to read a students info, then output it on the screen, I do not have to organize the output by the student's reference number now, but I wanted to know how I am supposed to do it. I was thinking that i could re-read the input file to recognize each reference number and skip pages in between the two. here is my code, that does the output, but I am not sure what I should do to organize the output by reference number
    Code:
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    	string SSN, LastName, FirstName, ReferenceNum;
    
    	ofstream outFile;
    	ifstream inFile;
    
    	outFile.open("a:report.txt", ios::out);
    	inFile.open("a:StudentData.txt", ios::in);
    
    	outFile << setw(6) << "Introduction to C"
    			<< setw(5) <<"\nTerm: Fall 2002"
    			<< setw(5) << "\nRef#"
    			<< "\n\n\nSSN" << right << setw(20) << right << setw(20) << "Last"
    			<< right << setw(20) << "First" << right << setw(20) << "Reference#\n";
    
    	while (inFile)
    	{
    	inFile >> SSN >> LastName >> FirstName >> ReferenceNum;
    	outFile << right << SSN << right << setw(17) << LastName << right 
    			<< setw(16) << FirstName << right << setw(17)<< ReferenceNum << "\n";
    	}
    
    
    
    	return 0;
    }
    posted the wrong code before, it's changed now
    Last edited by indigo0086; 10-30-2002 at 01:07 PM.

  2. #2
    Yep, but one way to do this is to get the reference number when reading each student's info, and store it into that elenemt of an array (or vector).

    Code:
    student class[31];
    cin >> ref_id >> name >> GPA;
    class[ref_id].name = name;
    class[ref_id].GPA = GPA;
    Then, at the end, output everything in order.
    ~Inquirer
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM