How to use While Loop with Student Registration Fee Lab

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirav11
    New Member
    • Nov 2008
    • 2

    How to use While Loop with Student Registration Fee Lab

    Code:
    # include <iostream>
    # include <fstream>
    # include <iomanip>
    # include <cstdlib> // needed for exit ()
    using namespace std;
    
    int main()
    {
    	ifstream inFile;
    	ofstream outFile;
    
    	inFile.open("registration.txt"); // attempt to open the file for input Student ID first
    	{
    	char registration;
    	if (!inFile.fail()) // if it does not fail, the file exists
    		cout <<"A file exits by name Registration.txt.\n"
    			 <<" Do you want to continue and overwrite it\n"
    			 <<" with the new information (y or n): ";
    		cin >> registration;
    		if (tolower(registration) == 'n')
    		{
    			cout << " File cannot be overwritten." << endl;
    			exit (1); // Terminate program execution
    		}
    	}
    	outFile.open("registration.txt"); // open the file for Writing
    	if (inFile.fail()) // Successfully Open or Not
    	{
    		cout << "\nThe file was not sucessfully opened try again"  << endl;
    		exit (1);
    
    	cout << "The file was successfully opened for output."  << endl;
    	return 0;
    	}
    }// I/O file
    now I need to know how to write the codes so i can read in upto 12 students records, calculate the registration fee, print the table of results, calculate and print average registration fee, prints out the students who has taken the most credits, and print out all of the students who have less than 12 credits in order, fewest credit first. Also, need error checking that input values of the studentID, status of residence, and status of study are specified in the valid range. Otherwise, you should report it in an error message, and continue to read the next set of data.
    I need a WHILE loop to read and process all the students



    MAKE SURE TO READ STUDENT ID FIRST, THE RANGE OF STUDENT ID IS BETWEEN 1 and 999. The Input file should have up to 12 student's data which I already have in put file.

    Code:
    STUDENT ID #		RESIDENCE		STUDY		  # of CREDITS		         FEE
    
    ---------------      -----------------        ---------------     --------------             ------------   
    
    	55		In-state		Undergraduate		19			$7345
    	100		Out-of- State		Graduate		13			$5233
    	974		In-state		Undergraduate		 8			$5235
    	196		In-state		Graduate		 3			$990
    	999		Out-of- State		Undergraduate		18			$7213
    	100		In-state		Graduate		 5			$1034
    	497		In-state		Undergraduate		20			$7994
    	734		Out-of- State		Graduate		 7			$2403
    	691		Out-of- State		Undergraduate		12			$4013
    	143		In-state		Graduate		21			$8034
    	555		Out-of- State		Undergraduate		10			$3985
    	01		Out of Country		Graduate		04			$101
    
    THE AVERAGE REGISTRATION FEE IS : $4465
    THE MOST CREDIT WAS 21 TAKEN BY STUDENT 143.
    
    LESS THAN 12 CREDITS
    	196 In-State Graduate	3	$990
    Last edited by Ganon11; Nov 12 '08, 04:52 AM. Reason: Please use [CODE] tags in the future.
  • nirav11
    New Member
    • Nov 2008
    • 2

    #2
    BTW THIS IS C++ NOT C codes

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Read this article How to Parse a File in C++

      And don't PM Admins/mods/experts directly with your questions

      And do read our posting guidelines

      Comment

      Working...