473,566 Members | 2,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use While Loop with Student Registration Fee Lab

2 New Member
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
2 2426
nirav11
2 New Member
BTW THIS IS C++ NOT C codes
Nov 12 '08 #2
Banfa
9,065 Recognized Expert Moderator Expert
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

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

Similar topics

0
2771
by: Sue Adams | last post by:
I actually have two issues/questions: I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db. The code I use to get it from the db table is: ''Retrieve the Registration Identification Number strRegisterID = Rs("Register_ID") Prior to testing my code and actually...
5
2643
by: David C | last post by:
This is very strange. Say I have code like this. I am simply looping through a collection object in a foreach loop. Course course = new Course(); foreach(Student s in course.Students) { Console.WriteLine(s.StudentID); }
25
3987
by: David C | last post by:
I posted this question, and from the replies, I get the impression that I worded my posting very poorly, so let me try this again. While debugging and stepping through this foreach loop foreach(Student s in course.Students) { Console.WriteLine(s.StudentID); }
1
1314
by: emlj001 | last post by:
I have a form that starts at page, http://www.scmeachoraldiv.org/allstate/registration/default.asp My problem is on the page http://www.scmeachoraldiv.org/allstate/registration/part2.asp I have a loop for the student lines on this page that looks back to the previous page. I have realized that I need to allow the teachers to change the...
31
16341
by: Warly girl | last post by:
Hi i have a qustion plz help me to understand and solve it Phase One Problem description You are required to implement a student registration system. The system keeps information about the students including their id, which is an automatic number issued by the system, a name, and current number of courses. It is important to keep the count...
1
2006
by: aemado | last post by:
I am trying to read in several lines, each should have exactly 5 pieces of data. I am using try/catch/throw to determine if the data is in the correct format, and trying to use iss to separate the parts. However, this is my first time using both, and I am pretty certain that I am missing something obvious. Firstly, by debugging, I found that the...
0
1514
by: andrewst | last post by:
Originally posted by Taijixp Ask your teacher for help. -- Posted via http://dbforums.com
3
6955
by: praveenaj | last post by:
I was given to write a C program using Linked list to enter student marks, but i can't figure out how this node insertion works: how nodes are linked with each other??? A Computer Training Institute wants to store marks of the Theory and Practical Papers of Data Structures & Algorithm. This system keeps the Registration Number and the Name...
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.