6 Star 3 Fork 0

甘才军 / CTestAutoJudge

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
myprogClass.h 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
//以类对象TMyProgram的方式实现了对C/C++程序的编译、链接、运行、自动评分--------------
#ifndef myprogClassH
#include<vcl.h>
#define myprogClassH
//说明:一个TMyProgram对象表示一个C/C++源程序文件
//类使用示例
// TMyProgram* prog=new TMyprogram("c:\\test\\1.c");
// ...
// ...
// delete prog;
class __declspec(dllexport) TMyProgram
{
public:
//功能:构造函数,初始化源程序
//sourceFileName:源程序文件名,如c:\test\1.c
TMyProgram(AnsiString sourceFileName);
//功能;用BCB编译器对源程序文件进行编译
//返回:若没有语法错误,将在源程序文件所在目录下生成和源程序文件基本名同名的obj
// 文件,且返回值为"",否则,返回第一个语法错误的原始消息
AnsiString Compile();
//功能:链接源程序文件
//返回:错误消息,若没有错误,则返回"",并且在源程序所在目录生成一个可执行文件
AnsiString Link();
//功能:运行程序
//inputFile:输入数据文件
//注意:
// 1.在调用前必须先调用compile,link,否则会抛出异常
// 2.调用此函数后,可以立即通过ResultStrings属性访问对应的输出结果
void Run(AnsiString inputFile);
//析构函数,释放动态分配的内存
~TMyProgram();
//获取程序运行结果,在执行Run后有效
__property TStringList* ResultStrings = { read=FResultStrings };
//获取源程序文件去掉空行后内容
__property TStringList* SourceFileContent = { read=GetSourceFileContent };
//获取源程序文件的有效行数
__property int LineNumber = { read=GetLineNumber };
//设置子进程的执行超时时间(ms),若超过该时间,自动结束子进程,默认时间为3秒
//设为0,表示等待子进程自行结束
__property int TimeOut = { write=SetTimeOut,read=FTimeOut };
protected:
//源程序文件名
AnsiString sFile;
//源程序文件名编译后对应的obj文件名,如:c:\test\1.obj
AnsiString objFileName;
//源程序文件编译链接后对应的可执行文件名,如:c:\test\1.exe
AnsiString exeFileName;
private:
//存储程序运行原始结果
TStringList* FResultStrings;
//源程序文件内容,去掉了里面的空行
TStringList* FSourceFileContent;
int FTimeOut;
//获取源程序文件内容
TStringList* __fastcall GetSourceFileContent();
int __fastcall GetLineNumber();
void __fastcall SetTimeOut(int value);
};
#endif
C++
1
https://gitee.com/gancaijun/CTestAutoJudge.git
git@gitee.com:gancaijun/CTestAutoJudge.git
gancaijun
CTestAutoJudge
CTestAutoJudge
develop

搜索帮助