Computing.Net > Forums > Programming > Can someone correct my code using Nested Loop

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Can someone correct my code using Nested Loop

Reply to Message Icon

Name: kenvu90
Date: April 25, 2009 at 15:26:55 Pacific
OS: Windows Vista
Subcategory: C/C++
Comment:

this program will require a nested loop.

Processing

1) The program processes an unknown number of students using sentinel logic (user enters a value of “000” for student id in order to terminate the program – for each student, there will be multiple courses to be entered (specified by student number of classes requested) – in other words, this program requires a nested loop (an outer loop that controls the processing of students – an inner loop that controls the processing of the courses for a given student)
2) The enrollment limit for each course is four students (small U prides itself on its small classes)
3) For each course that a student is requesting, check that:
a. There is room in the course (i.e., there are fewer than four students in the course
b. The student has the appropriate semester standing for the course based on the following:

Course Identifier: CMPSC 101, BA 243, ENGL 202
Course Title: Intro to Algorithmic Processes, Business Law, Technical Writing
Minimum Semester Standing: Cmpsc is 1, BA is 2, ENGL is 4
Course # Credits: Cmpsc is 3, BA is 4, ENGL is 4


c. Assign a value to student comment based on the outcome of 3. above:
i. If the course is filled, the comment should be assigned the value --“Course enrollment reached – unable to register”
ii. If the student does not have the minimum semester standing, the comment should be assigned the value -- “Student does not have required semester standing”
iii. If the course has an opening and the student has the required semester standing, comment should be assigned the value – “Registration successful”, and the credits for this course should be added to the student’s total credits schedule

4) For purposes of output determine the semester standing description for each student:
a. If semester standing is 1 or 2 – Freshman
b. If semester standing is 3 or 4 – Sophomore
c. If semester standing is 5 or 6 - Junior
d. If semester standing is 7 or more – Senior

5) Keep track of the number of students who are successfully enrolled in each of the courses listed above – at the end of processing, display the course identifier, course description, and number of students enrolled for each course offered by the University


MY CODE:

/* Allow a user to enter an unknown number of students.
Each student registers for a pre-specificed number of courses
with some courses requiring a specific semester standing for registration.

Program need to reports the student's id, and the total number of credits for which
the student has registered.

Inputs: student id
student semester standing
student number of classes requested
course identifier

Outputs: student id
student semester description
course identifier
course title
course comment
total credits scheduled

*/

#include <iostream>
#include <string>
using namespace std;

// function prototypes
void displaySmallUHeading();
int inputStudentData(bool);
int detSemStanding(int);
int inputCourseData();
int processRegistration(string, string, int, int, int, int);
void displayStudentCourseData(string, string, string, string);
void displayStudentTotalCredits(string, int);
void displayTotalEnrollments(int, int, int);

int main()
{
string studId,
courseIndentifier,
studSemDescrip,
courseTitle,
courseComment;
int studSemStanding,
studNumCourses,
totalCreditScheduled,
totalNumStudEnrolled,
totalCmpsStuds,
totalBaStuds,
totalEnglStuds;
bool moreStudents;

displaySmallUHeading();

totalCreditScheduled = -1;

for(studSemStanding = 0; studSemStanding < studNumCourses; studSemStanding++)
{
totalNumStudEnrolled = 5;
// inputs student data (stud id, stud semester standing, number of courses, more studends)
inputStudentData(studId, studSemStanding, studNumCourses, moreStudents);

for(studSemStanding = 0; studSemStanding < studNumCourses; studSemStanding++)
{
// inputs a course identidier
inputCourseData();
totalNumStudEnrolled ++;
}
}
return 0;
}

// Inputs the students data
// Receives: more students
// Returns: stud id, stud semester standing, num courses, more students
int inputStudentData( string studId, int studSemStanding, int studNumCourses, bool moreStudents)
{
cout << "\nPlease enter student Id: ";
cin >> studId;
cout << "Please enter student semester standing: ";
cin >> studSemStanding;
cout << "Please enter student number of courses requested: ";
cin >> studNumCourses;
cout << "Please enter more students: ";
cin >> moreStudents;
}
// end inputStudentData

// Determine student semester standing
// Receives: stud semester standing
// Returns: stud semester standing description
int detSemStanding(string studSemDescrip)
{
if((studSemStanding == 1)||(studSemStanding == 2))
{
studSemDescrip = Freshman;
}
else if ((studSemStanding == 3)||(studSemStanding == 4))
{
studSemDescrip = Sophomore;
}
else if((studSemStanding == 5)||(studSemStanding == 6))
{
studSemDescrip = Junior;
}
else if(studSemStanding >= 7)
{
studSemDescrip = Senior;
}
return studSemDescrip;
}

// Input course data
// Receives: none
// Returns: course indentifier
int inputCourseData ()
{
string courseIndentifier;

cout << "\nPlease enter course indentifier: ";
cin >> courseIndentifier;

return courseIndentifier;
}
// end inputCourseData

// Process registration
// Receives: stud semester standing, course indentifier, total credits scheduled, total cmpsc studs, total ba studs, total engl studs
// Returns: course title, course comment, total credits scheduled, total cmpsc studs, total ba studs, total engl studs
int processRegistration(string courseTitle, string courseComment, int totalCreditsScheduled, int totalCmpsStuds, int totalBaStuds, int totalEnglStuds)
{
const string MINIMUM_SEM_STANDING = 1,
MINIMUM_SEM_STANDING = 2,
MINIMUM_SEM_STANDING = 4;

if(courseIndentifier > 4)
{
cout << "\nCourse enrollment reached - unable to register" << endl;
}
else if(studSemStanding != MINIMUM_SEM_STANDING)
{
cout << "Student does not have required semester standing" << endl;
}
else if(studSemStanding == MINIMUM_SEM_STANDING)
{
cout << "Registration successful" << endl;
}
}

// Display student course data
// Receives: stud id, course identifier, course title, course comment
// Returns: none
void displayStudentCourseData(string studId, string courseIdentifier, string courseTitle, string courseComment)
{
cout << "\nStudent Id: " << studId << endl;
cout << "Course identifier: " << courseIdentifier << endl;
cout << "Course title: " << courseTitle << endl;
cout << "Course comment: " << courseComment << endl;
}

// Display student total credits
// Receives: stud id, total credits scheduled
// Returns: non
void displayStudentTotalCredits(string studId, int totalCreditScheduled)
{
cout << "\nStudent Id: " << studId << endl;
cout << "Total credits scheduled: " << totalCreditScheduled << endl;
}

// Display total enrollments
// Receives: total cmpsc studs, total ba studs, total engl studs
// Returns: none
void displayTotalEnrollments(int totalCmpsStuds, int totalBaStuds, int totalEnglStuds)
{
cout << "\nTotal CMPSC students: " << totalCmpsStuds << endl;
cout << "Total BA students: " << totalBaStuds << endl;
cout << "Total ENGL students: " << totalEnglStuds << endl;
}



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Sigma Tel Replacing text with batch...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Can someone correct my code using Nested Loop

Can someone access my files? www.computing.net/answers/programming/can-someone-access-my-files/13414.html

Help with Nested Loops www.computing.net/answers/programming/help-with-nested-loops/12647.html

Can someone provide batch code? www.computing.net/answers/programming/can-someone-provide-batch-code/17939.html