queue

rbjones
rbjones used Ask the Experts™
on
queue
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I guess what you want is this


////////////////////////////////////////////////////////
****** STUDENT REGISTRATION ******
(1)View Record
(2)Add Record
(3)Del Record

Please enter your choice (1, 2 ,or 3) :2
enter social security number            : 1234
enter student first name        : asdf
enter student last name : asdf
enter course with course number : asdf
enter session number                    : asdf
enter course name               : asdf
enter schedule for course               : asdf
Do you want to add another course? (y/n) :y
enter course with course number : 123
enter session number                    : asdf
enter course name               : asdf
enter schedule for course               : asdf
Do you want to add another course? (y/n) :n
do you want to add record again (y/n) :y
enter social security number            : 123445
enter student first name        : asdf
enter student last name : asdf
enter course with course number : asdf
enter session number                    : sadf
enter course name               : sadf
enter schedule for course               : asdf
Do you want to add another course? (y/n) :n
do you want to add record again (y/n) :n
Press 1 to back to main menu
Press 2 to quit from the program
2
Press any key to continue

///////////////////////////////////////////////

And you get it by changing this code like I did.

///////////////////////////////////////////////

           cout<<"enter schedule for course\t\t: ";
           cin.get(record[location].schedule,20);
           
           record[location].CourseList.push_back( CurCourse );
// end of loop            
           WriteToFile(record);
             cout << "Do you want to add another course? (y/n) :";
              cin >> Key;
               } while( Key == 'y' || Key == 'Y' );


             }
       
      cout<<"do you want to add record again (y/n) :";
       cin>>ans;
   }while(ans=='y'||ans=='Y');

////////////////////////////////////////////////////

Essentialy it's just one endl less, the other error resolved when I deleted the space after the ":" .

Author

Commented:
Nah, the problem was when you go to view record on the menu and enter your SSN.  The output would print twice like this.

****** STUDENT REGISTRATION ******
(1)View Record
(2)Add Record
(3)Del Record

Please enter your choice (1, 2 ,or 3) :1
Enter student SSN# that you want to see : 2222
Student SSN#            : 2222
Student first name      : Robert
Student last name       : Jones
Student schedule        : MWF4-5
Student course number   : CSC295
Student session number  : 01
Student course name     : JavaProgramming
Student course number   : CSC295
Student session number  : 01
Student course name     : JavaProgramming


I only entered this once, but its outputed twice
Student course number   : CSC295
Student session number  : 01
Student course name     : JavaProgramming
EOL

Commented:
you have to write

for( vector<CCourse>::iterator Iter = a[location].CourseList.begin(); Iter != a[location].CourseList.end(); Iter++ )

instead of

for( vector<CCourse>::iterator Iter = a[location].CourseList.begin(); Iter != a[location].CourseList.end(); ++Iter )
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Author

Commented:
I changed the ++Iter to Iter++ and tried to enter it again

****** STUDENT REGISTRATION ******
(1)View Record
(2)Add Record
(3)Del Record

Please enter your choice (1, 2 ,or 3) :2
enter social security number            : 1111
enter student first name        : Chris
enter student last name : Rivers
enter course with course number : CSC390
enter session number                    : 01
enter course name               : JavaProgramming
enter schedule for course               : MWF4-5
Do you want to add another course?
y
enter course with course number : CSC222
enter session number                    : C++
enter course name               : gcode
enter schedule for course               : tth3-4
Do you want to add another course?
n
do you want to add record again (y/n): n
Press 1 to back to main menu
Press 2 to quit from the program
1
****** STUDENT REGISTRATION ******
(1)View Record
(2)Add Record
(3)Del Record

Please enter your choice (1, 2 ,or 3) :1
Enter student SSN# that you want to see : 1111
Student SSN#            : 1111
Student first name      : Chris
Student last name       : Rivers
Student schedule        :
Student course number   : CSC390
Student session number  : 01
Student course name     : JavaProgramming
Student course number   : CSC222
Student session number  : C++
Student course name     : gcode
Repeated--> Student course number   : CSC390
Repeated--> Student session number  : 01
Repeated--> Student course name     : JavaProgramming
Student course number   :
Student session number  :
Student course name     :

It repeated the first entry CSC390 again.  And then it displayed:

Student course number   :
Student session number  :
Student course name     :

at the end?  That shouldn't happen either.  I only entered 2 courses.
EOL

Commented:
hm, You'v some wicked long term relationships inside your code. For today it's a bit late to give real good advice on details, thus I give you some hints how to write your code so this doesn't happen again.

-Make use of typedefs to simplify usage of templates.

typedef vector<CCourse>::iterator cListIter;

-Organize your code overviewable.

-If a function is bigger then one page on your screen something is wrong, change it.

-Build small independent parts, that you use to accomplish the whole, rather then write everything into stone.

-Break your functions down and generalize them. ( split and rule ) . Make use of the parameters to tell the function what it's supposed to do instead of writing the variants inside of the function.

-Use as less long term relations as possible.
Avoid the usage of globals totaly. Avoid even member data if it isn't realy needed and you can accomplish it within the function.

-Make good use of return types, they help you shrink your code size.

-Use the for_each algorithm of the STL

-Seperate impementation and interface ( via .h and .cpp )
Brand the names of your interfaces as clearly as possible, a good function name doesn't need a comment. Else comment the function.

-Instanciate needed local variables at the head of the function and do only otherwise to force the programm to execute initialization on the stack again.
I would write a simple menu class.  Then I would get rid of all the extra questions throughout your program.  Let main run the program through the menu class, entering one student's info at one time and then returning to the menu.

Commented:
This question didn't show any activity for more than 21 days. I will ask Community Support to close it unless you finalize it yourself within 7 days.
You can always request to keep this question open. But remember, experts can only help if you provide feedback to their comments.
Unless there is objection or further activity,  I will suggest to accept

    "EOL"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
========
Werner
Force accepted

** Mindphaser - Community Support Moderator **

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial