General information
Forum:
Borland C++ Builder
Category:
C++ Builder Language
Title:
Problem on run time
i know this isnt builder c++....but if u can help on borland c++
hello everyone please help me...the problem is that there are no compilation errors but on the run time(thats another story)it crashes
it does not go into the main menu...please help
#include
#include
const int MAX_NAME_LENGTH=100;
const int MAX_MODULE_LENGTH=7;
const int MAX_NO_OF_IDS=20;
const int MAX_NO_MODULES=12;
const int MAX_LOCATION_LENGTH=100;
const int MAX_NO_STUDENTS=15;
class Module
{
private:
char moduleName[MAX_NAME_LENGTH];
char moduleCode[MAX_MODULE_LENGTH];
int creditSize;
char moduleLeader[MAX_NAME_LENGTH];
int enrolledStudents[MAX_NO_OF_IDS];
public:
// default constructor function
Module( void );
int returnCreditSize(int creditSize );
char *returnName( void );
void SetCode( char *newcode );
char *returnCode( void );
void SetLeader( char *newleader );
char *returnLeader( void );
void SetName( char *newname );
void displayDetails( void );
void enrollStudent(int studID);
};
// default constructor function. This will get called once for each element
// in the array (in main), when that is declared. It sets the
// moduleName to be blank, which indicates "unused"
// moduleLeader to be blank, which indicates "unused"
// moduleCode to be blank, which indicates "unused"
// and initializes creditSize to be 0.
Module::Module( void )
{
strcpy( moduleName, "" );
strcpy( moduleLeader, "" );
strcpy( moduleCode, "" );
creditSize=0;
enrolledStudents[0]=0;
}
//Set a Module Name
void Module::SetName( char *newname )
{
strcpy( moduleName, newname );
}
// Retrieve a module name
char *Module::returnName( void )
{
return moduleName;
}
//Set a Module Code
void Module::SetCode( char *newcode )
{
strcpy( moduleCode, newcode );
}
// Retrieve a Module's Code
char *Module::returnCode( void )
{
return moduleCode;
}
//Set a Module Leader
void Module::SetLeader( char *newleader )
{
strcpy( moduleLeader, newleader );
}
// Retrieve a Module's Leader
char *Module::returnLeader( void )
{
return moduleLeader;
}
// Enroll some Students to the module.
void Module::enrollStudent(int studID)
{
static int i=0;
enrolledStudents[i]=studID;
i++;
}
// Retrieve a Modules credits
int Module::returnCreditSize(int credits )
{
return creditSize+=credits;
}
// Print Module details.
void Module::displayDetails( )
{
cout <<"In Module "< cout <<" and credit size equal to "< // and initializes studID and credits to be equal to 0
Student::Student( void )
{
strcpy( name, "" );
strcpy( programme, "" );
strcpy( modulesEnrolled, "" );
studID=0;
credits=0;
}
//Set a student's name
void Student::SetName( char *newname )
{
strcpy( name, newname );
}
// Retrieve a student'sname
char *Student::returnName( void )
{
return name;
}
//Set a student's programme
void Student::SetProgramme( char *newprogramme )
{
strcpy( programme, newprogramme );
}
// Retrieve a student's programme
char *Student::returnProgramme( void )
{
return programme;
}
//generate and return the student ID
int Student::returnID()
{
static int studID;
studID=0;
studID++;
return studID;
}
//adds the credits of all the modules the student
//has choose and returns them to the system
int Student::returncredits(int creditSize)
{
static int credits=0;
credits+=creditSize;
return credits;
}
//display the details of the student(excluding result)
void Student::displayDetails()
{
cout <<"Student "< cout <<" is enrolled at "<
}
//Sign a student onto a module
void Student::signOnModule(Module aModule)
{
char moduleCode[7];
cout <<"Please enter the module you want to enrolled in : "< cin >>moduleCode;
int index;
// look at each element in the module code array in turn
// If a matching code is found, give an error message
// If not found check cretid size not to be grater than 120
// If not then enroll to that module by adding the module code
for ( index=0; index < 20; ++index )
{
if ( strcmp( moduleCode, modules[index].returnCode() ) )
cout << "You are allready enrolled in this module" << endl;
}
modules[index].returnCreditSize(credits);
if ( credits > 120)
cout << " You are not allowed to get any more modules " << endl;
modules[index].SetCode(moduleCode);
modules[index].returnCode();
cout<<"The module with code "<
}
class School
{
private:
char schoolName[MAX_NAME_LENGTH];
char location[MAX_LOCATION_LENGTH];
Module modules[MAX_NO_MODULES];
Student students[MAX_NO_STUDENTS];
public:
// default constructor function
School( void );
void addNewModule(void);
void displayModuleDetails(void);
void registerStudent(void);
void enrollStudent(void);
void displayStudentDetails(void);
void displayAllStudents(void);
void enterStudentResult(void);
void displayStudentResult(void);
};
// default constructor function. This will get called once only
// in main.It sets the schoolName to be "University",
// and set location to be "England."
School::School( void )
{
strcpy( schoolName, "University" );
strcpy( location, "England" );
}
void School::addNewModule(void)
{
static int no_modules=0;
char moduleName[MAX_NAME_LENGTH];
char moduleCode[MAX_MODULE_LENGTH];
int credits;
char moduleLeader[MAX_NAME_LENGTH];
cout << "Enter the new module's name: ";
cin >> moduleName;
modules[no_modules].SetName( moduleName );
cout << "Enter the new module's code: ";
cin >> moduleCode;
modules[no_modules].SetCode( moduleCode );
cout << "Enter the new module's Leader: ";
cin >> moduleLeader;
modules[no_modules].SetLeader( moduleLeader );
cout << "Enter the new module's credit size: ";
cin >> credits;
modules[no_modules].returnCreditSize(credits );
// ...then record the fact that the number of students in the
// array has increased by one.
++no_modules;
}
// Retrieve a module name
void School::displayModuleDetails(void)
{
char moduleCode[7];
cout <<"Please enter the module Code to display : "< cin >>moduleCode;
int index;
// look at each element in the module code array in turn
// If a matching code is found, give an error message
// If not found check cretid size not to be grater than 120
// If not then enroll to that module by adding the module code
for ( index=0; index < 20; ++index )
{
if ( strcmp( moduleCode, modules[index].returnCode() ) == 0 )
cout << " Success " << endl;
}
modules[index].displayDetails();
}
void School::registerStudent(void)
{
static int no_students=0;
char name[MAX_NAME_LENGTH];
char programme[MAX_NAME_LENGTH];
// add a new student. Only do this if the array isn't
// already full.
if ( no_students == MAX_NO_STUDENTS )
{
cout << "Sorry. Cannot add more students; the system is full." << endl;
}
cout << "Enter the new student's name: ";
cin >> name;
students[no_students].SetName( name );
cout << "Enter the new student's programme: ";
cin >> programme;
students[no_students].SetProgramme( programme );
students[no_students].returnID();
++no_students;
}
void School::enrollStudent(void)
{
char moduleCode[7];
int index;
int studID;
Module aModule;
cout <<"Please insert the Student ID number"< cin >>studID;
cout <<"Please enter the module you want to enrolled in : "< cin >>moduleCode;
for ( index=0; index < 35; ++index )
{
if ( studID != students[index].returnID() )
cout << "Proceed to the next step please " << endl;
}
for ( index=0; index < 20; ++index )
{
if ( strcmp( moduleCode, modules[index].returnCode() ) == 0)
cout << "You are allready enrolled in this module" << endl;
}
students[index].signOnModule( aModule);
}
void School::displayStudentDetails(void)
{
int index,studID;
cout <<"Please insert the Student ID number"< cin >>studID;
for ( index=0; index < 15; ++index )
{
if ( studID == students[index].returnID() )
cout << "Proceed to the next step please " << endl;
}
students[index].displayDetails();
}
void School::displayAllStudents(void)
{
int index;
Student students[MAX_NO_STUDENTS];
cout <<"The details of all the students are as follows :"<
for ( index=0; index < 15; ++index ){
students[index].displayDetails();}
}
main()
{
int choice, index;
School University;
Module modules[MAX_NO_MODULES];
// Student students[MAX_NO_STUDENTS];
int no_students=0;
int no_modules=0;
// now the menu system.
while ( 1 )
{
cout << ""< cout << ""< cout << "Student Registration and Module Management System" << endl;
cout << ""< cout <<"1. Add a new module to the system" << endl;
cout <<"2. Display a module details" << endl;
cout <<"3. Display all modules details" << endl;
cout <<"4. Register a student onto a module" << endl;
cout <<"5. Enroll a student to a module" << endl;
cout <<"6. Display all students details" << endl;
cout <<"7. Display a student details" << endl;
cout <<"8. Enter a student results" << endl;
cout <<"9. Display a student result" << endl;
cout <<"10. Display a specific module result of a particular student"< cout <<"11. Display the detail and all the results of all the" << endl;
cout << " students in alphabetical order" << endl;
cout << "Please state your option: ";
cin >> choice;
switch ( choice )
{
case 1:
// add a new module. Only do this if the array isn't
// already full.
if ( no_modules == MAX_NO_MODULES )
{
cout << "Sorry. Cannot add more modules; the system is full." << endl;
break;
}
University.addNewModule();
break;
case 2:
// print details of a module.
University.displayModuleDetails();
break;
case 3:
// Print all modules details.
for ( index=0; index < no_modules; ++index )
modules[index].displayDetails();
break;
case 4:
// add a new student. Only do this if the array isn't
// already full.
University.registerStudent();
break;
case 5:
// enroll Student
University.enrollStudent();
break;
case 6:
//display a students details
University.displayStudentDetails();
break;
case 7:
//display all students details
University.displayAllStudents();
break;
case 8:
//display an ending message
cout << "GOODBYE"<
break;
default:
cout << "No such option; please enter option 1-8" << endl;
break;
}
}
}
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only