By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,507 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,507 IT Pros & Developers. It's quick & easy.

How to use While Loop with Student Registration Fee Lab

P: 2
Expand|Select|Wrap|Line Numbers
  1. # include <iostream>
  2. # include <fstream>
  3. # include <iomanip>
  4. # include <cstdlib> // needed for exit ()
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     ifstream inFile;
  10.     ofstream outFile;
  11.  
  12.     inFile.open("registration.txt"); // attempt to open the file for input Student ID first
  13.     {
  14.     char registration;
  15.     if (!inFile.fail()) // if it does not fail, the file exists
  16.         cout <<"A file exits by name Registration.txt.\n"
  17.              <<" Do you want to continue and overwrite it\n"
  18.              <<" with the new information (y or n): ";
  19.         cin >> registration;
  20.         if (tolower(registration) == 'n')
  21.         {
  22.             cout << " File cannot be overwritten." << endl;
  23.             exit (1); // Terminate program execution
  24.         }
  25.     }
  26.     outFile.open("registration.txt"); // open the file for Writing
  27.     if (inFile.fail()) // Successfully Open or Not
  28.     {
  29.         cout << "\nThe file was not sucessfully opened try again"  << endl;
  30.         exit (1);
  31.  
  32.     cout << "The file was successfully opened for output."  << endl;
  33.     return 0;
  34.     }
  35. }// 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.

Expand|Select|Wrap|Line Numbers
  1. STUDENT ID #        RESIDENCE        STUDY          # of CREDITS                 FEE
  2.  
  3. ---------------      -----------------        ---------------     --------------             ------------   
  4.  
  5.     55        In-state        Undergraduate        19            $7345
  6.     100        Out-of- State        Graduate        13            $5233
  7.     974        In-state        Undergraduate         8            $5235
  8.     196        In-state        Graduate         3            $990
  9.     999        Out-of- State        Undergraduate        18            $7213
  10.     100        In-state        Graduate         5            $1034
  11.     497        In-state        Undergraduate        20            $7994
  12.     734        Out-of- State        Graduate         7            $2403
  13.     691        Out-of- State        Undergraduate        12            $4013
  14.     143        In-state        Graduate        21            $8034
  15.     555        Out-of- State        Undergraduate        10            $3985
  16.     01        Out of Country        Graduate        04            $101
  17.  
  18. THE AVERAGE REGISTRATION FEE IS : $4465
  19. THE MOST CREDIT WAS 21 TAKEN BY STUDENT 143.
  20.  
  21. LESS THAN 12 CREDITS
  22.     196 In-State Graduate    3    $990
Nov 12 '08 #1
Share this Question
Share on Google+
2 Replies


P: 2
BTW THIS IS C++ NOT C codes
Nov 12 '08 #2

Banfa
Expert Mod 5K+
P: 8,916
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
Nov 12 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.