Can someone help me figure out why nothing comes up on the output screen. The program compiles but the the output is blank.


1. Maintain information on all students. Each student has the following:

1st line - lastname, city of residence, student id, ssn

2nd line - course, course id, course department, credit hours, grade (number representation... ex. A = 4, B+ = 3.3, C- =1.7 etc)

Note - Each student will initially be enrolled in 5 courses... However, the user should be able to add or drop a course (along with its corresponding information) at will!

**Please review the text file, registration.txt, attached before you submit your program, as the text file is very specific!!!

2. The program should be menu driven and possess the following features in seperate functions:

a. Menu

As a selection within the menu, the user should be able to:

b. Print Students in Alphabetical Order

c. Retrieve a Student & Prints Their Corresponding Information

d. Add a Student Record

e. Delete a Student Record

f. Add Student in a Course

g. Delete Student from a Course

h. Print a Student Report - Total Credit Hours

#include<iostream>
#include<list>
#include<fstream>
#include<algorithm>

using namespace std;
typedef list<int> studentList;

typedef studentList::iterator list_it; 
void loadList(studentList & students);
void menu(int &selection);
void addStudent(studentList & l);
void enrollStudent(studentList l);
void sortStudent(studentList & students);
void deleteStudentRec(studentList & l);
void deleteStudentCour(studentList & l);
void retrieveStudent(studentList l);
void printRetrieve(studentList & students);



int main ()
{
    studentList students;
    loadList(students);
    addStudent(students);
    enrollStudent(students);
    sortStudent(students);
    deleteStudentRec(students);
    deleteStudentCour(students);
    retrieveStudent(students);
    printRetrieve(students);    

    
    int selection;
   
    do
    {
         menu(selection);
         if(selection == 1)
            addStudent(students);
         else if (selection ==2)
            enrollStudent(students);
         else if (selection == 3)
            sortStudent(students);
         else if (selection == 4)
            deleteStudentRec(students);
         else if (selection == 5)
            deleteStudentCour(students);
         else if (selection == 6)
            retrieveStudent(students);
         else if (selection ==7)
              printRetrieve(students);
         else
            cout<<"Invalid selection "<<endl; 
    }while(selection !=0);
    system("pause");
    return 0;
}
void menu(int &selection)
{
     cout <<"Students at Norfolk State University "<<endl<<endl;
     cout << "1: Add a student "<<endl;
     cout << "2: Enroll a student in a course "<<endl;
     cout << "3: Sort a student "<<endl;
     cout << "4: Delete a student record "<<endl;
	 cout << "5: delete student course "<<endl;
	 cout << "6: Retrieve student "<<endl;
	 cout << "7: Print retrieving student records"<<endl;
     cin>>selection;
}


void addStudent(studentList & l)
{
int student;
list_it pos;
cout <<"Please enter the student to add:";
cin >> student;
l.insert(pos,student);
}

void enrollStudent(studentList l)
{    
     int course, student;
     list_it pos;
     cout << "please enter course name"<<endl;
     cin >> course;
     cout <<"please enter the student name:";
     cin >>student;
     pos = find (l.begin(), l.end(), course);
     if (pos != l.end())
     l.insert(pos,student);
     else
     cout<<course<<"not found"<<endl;
     
}
void sortStudent(studentList & students)
{
     cout<<"sorting the students"<<endl;
     students.sort();
     cout << "printing list"<<endl;
     while(!students.empty())
     {
      cout<<students.front()<<endl;
      students.pop_front();
      }
}

void deleteStudentRec(studentList & l)
{
     cout<<"Erasing a student record"<<endl;
     int student;
     list_it pos;
     cout <<"please enter a student:";
     cin >> student;
     for(list_it it= l.begin(); it != l.end(); it++)
     {
                 if (*it ==student)
                 pos = it;
};
l.erase(pos);
}
void deleteStudentCour(studentList & l)
{
     {
     cout<<"Erasing a student course"<<endl;
     int course;
     list_it pos;
     cout <<"please enter a student course:";
     cin >> course;
     for(list_it it= l.begin(); it != l.end(); it++)
     {
                 if (*it ==course)
                 pos = it;
};
l.erase(pos);
}
}
void retrieveStudent(studentList l)
{
     cout<<"Retreiving student information";
     int students;
     list_it pos;
     cout <<"Please enter student name:";
     cin >> students;
     pos = find (l.begin(), l.end(), students);
     if (pos != l.end())
     cout <<"Found it:"<<*pos<<endl;
     else
     cout <<students<<"not found"<<endl;
         
     
}
void printRetrieve(studentList & students)
{
     cout << "printing list"<<endl;
     while(!students.empty())
     {
      cout<<students.front()<<endl;
      students.pop_front();
      }
}
     

void loadList(studentList & students)
{
     
	ifstream infile;
	infile.open("registration.dat");
    int student;
	while (!infile.eof() )
	{

		infile >> student; 
		students.push_back(student);
	}
	infile.close();
}

this should help:

void printRetrieve(studentList & students)
{
    cout << "printing list"<<endl;
    
    for( studentList::iterator it = students.begin(); it != students.end(); it++ )
        cout<< *it<<endl;
}

this is a copy, the list wont be altered

enrollStudent(studentList l);

this should help:

void printRetrieve(studentList & students)
{
    cout << "printing list"<<endl;
    
    for( studentList::iterator it = students.begin(); it != students.end(); it++ )
        cout<< *it<<endl;
}

this is a copy, the list wont be altered

enrollStudent(studentList l);

I tried the code given and thier is still a blank output screen

I tried the code given and thier is still a blank output screen

"nothing comes up on the output screen" - what does it mean? Doesn't menu show up on th screen? If it doesn't maybe problem lies here

void loadList(studentList & students)
{
     
	ifstream infile;
	infile.open("registration.dat");
    int student;
	while (!infile.eof() )
	{

		infile >> student; 
		students.push_back(student);
	}
	infile.close();
}

When i run your program without registration.dat file I got infinity while loop. Maybe your file is not properly open, or it's structure is not correct (f.e. You have numbers of students separated with coma).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.