📄 student.cpp
字号:
/*
============================================================================
Name : Student.cpp
Author :
Copyright : Your copyright notice
Description : Exe source file
============================================================================
*/
// Include Files
#include "Student.h"
#include <e32base.h>
#include <e32std.h>
#include <e32cons.h> // Console
// Constants
_LIT(KTextConsoleTitle, "Console");
_LIT(KTextFailed, " failed, leave code = %d");
_LIT(KTextPressAnyKey, " [press any key]\n");
// Global Variables
LOCAL_D CConsoleBase* console; // write all messages to this
class CStudent : public CBase
{
public:
static CStudent* NewL(const TDesC& aName,TInt aNo,TReal aScore);
static CStudent* NewLC(const TDesC& aName,TInt aNo,TReal aScore);
public :
HBufC* GetName();
TInt GetNo();
TReal GetScore();
~CStudent();
private:
CStudent(TInt aNo,TReal aScore);
void ConstructL(const TDesC& aName);
private :
TInt iNo;
HBufC* iName;
TReal iScore;
};
//////////////////////////////////////////////////////////////////////////////
//
// -----> CStudent (implementation)
//
//////////////////////////////////////////////////////////////////////////////
CStudent* CStudent::NewL(const TDesC& aName,TInt aNo,TReal aScore)
{
//CStudent* stu=new (ELeave)CStudent(aNo,aScore);
//stu->ConstructL(aName);
CStudent* stu=CStudent::NewLC(aName,aNo,aScore);
CleanupStack::Pop(stu);
return stu;
}
CStudent* CStudent::NewLC(const TDesC& aName,TInt aNo,TReal aScore)
{
//CStudent* stu=CStudent::NewL(aName,aNo,aScore);
//CleanupStack::PushL(stu);
CStudent* stu=new (ELeave)CStudent(aNo,aScore);
CleanupStack::PushL(stu);
stu->ConstructL(aName);
return stu;
}
CStudent::CStudent(TInt aNo,TReal aScore)
{
iNo=aNo;
iScore=aScore;
}
void CStudent::ConstructL(const TDesC& aName)
{
iName=HBufC::NewLC(aName.Length());
TPtr16 ptr16=iName->Des();
ptr16.Copy(aName);
CleanupStack::Pop();
}
HBufC* CStudent::GetName()
{
return iName;
}
TInt CStudent::GetNo()
{
return iNo;
}
TReal CStudent::GetScore()
{
return iScore;
}
CStudent::~CStudent()
{
delete iName;
}
// Local Functions
LOCAL_C void MainL()
{
//
// add your program code here, example code below
//
console->Write(_L("Hello, world!\n"));
_LIT(KName1,"hewei");
_LIT(KNewLine,"\n");
_LIT(KFmt1,"No=%d ");
_LIT(KFmt2,"Score=%f ");
_LIT(KFmt3,"Name=");
CStudent* stu=CStudent::NewL(KName1,1,89.8);
console->Printf(KFmt3);
console->Printf(*(stu->GetName()));
console->Printf(KNewLine);
console->Printf(KFmt1,stu->GetNo());
console->Printf(KNewLine);
console->Printf(KFmt2,stu->GetScore());
console->Printf(KNewLine);
console->Getch();
CleanupStack::PopAndDestroy();
}
LOCAL_C void DoStartL()
{
// Create active scheduler (to run active objects)
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
CleanupStack::PushL(scheduler);
CActiveScheduler::Install(scheduler);
MainL();
// Delete active scheduler
CleanupStack::PopAndDestroy(scheduler);
}
// Global Functions
GLDEF_C TInt E32Main()
{
// Create cleanup stack
__UHEAP_MARK;
CTrapCleanup* cleanup = CTrapCleanup::New();
// Create output console
TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
if (createError)
return createError;
// Run application code inside TRAP harness, wait keypress when terminated
TRAPD(mainError, DoStartL());
if (mainError)
console->Printf(KTextFailed, mainError);
console->Printf(KTextPressAnyKey);
console->Getch();
delete console;
delete cleanup;
__UHEAP_MARKEND;
return KErrNone;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -