大家好,以下是我的代码。单击“运行”按钮后,它会在显示任何输出之前自动终止。谁能帮我 ?
#include <iostream>
using namespace std;
#include "StudentReviewSystem.h"
#include <string>
#include "Course.h"
StudentReviewSystem ::StudentReviewSystem()
{
}
StudentReviewSystem :: ~StudentReviewSystem()
{
}
void StudentReviewSystem :: addCourse( const int courseId, const string courseName )
{
int numOfCourse = 0;
Course* C ;
if(numOfCourse==0)
{
C = new Course[numOfCourse+1];
C[0].courseId= courseId ;
C[0].courseName = courseName ;
cout<< " Course " <<courseId<< " has been added"<<endl;
numOfCourse++;
}
else
{
int x = 0 ;
for(int i = 0; i< numOfCourse; i++)
{
if(C[i].courseId == courseId)
{
cout<< " Course " <<courseId<< " already exists"<<endl;
x++;
}
if(x == 0)
{
Course* tmp = C ;
C = new Course[numOfCourse+1];
for(int i = 0; i< numOfCourse ; i++)
{
C[i] = tmp[i];
}
C[numOfCourse].courseId = courseId;
C[numOfCourse].courseName = courseName;
delete[] tmp ;
numOfCourse++;
}
}
}
}
int main()
{
StudentReviewSystem S;
S.addCourse( 101, "Algorithms and Programming" );
S.addCourse( 201, "Fundamental Structures of Computer Science I" );
S.addCourse( 101, "Algorithms and Programming" );
}
答案 0 :(得分:1)
如果通过终止表示关闭终端窗口,请尝试在主页末尾运行system("pause");
。