473,854 Members | 1,494 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 2441
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
2789
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 updating the db, I''m trying to write it to the page to make sure their isn''t a loop or massive...
5
2661
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
4015
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
1327
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 number of students here instead of on the previous pages. Can anyone help me change this loop so that...
31
16456
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 of courses a student is currently enrolled in since he is only allowed to register for 4 courses at...
1
2016
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 first piece of data is being checked in the second case, giving me errors. I believe I may need to...
0
1524
by: andrewst | last post by:
Originally posted by Taijixp Ask your teacher for help. -- Posted via http://dbforums.com
3
6978
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 other than the two marks, and all the records should be inserted in increasing order of the...
0
9901
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11025
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10682
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10758
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10371
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9513
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5743
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5942
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4562
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.