쥬신 님이 쓰신 글 : : c++책에 있는것과 제가 만든 것은 값은 같은 겂니다. 빌더로 옮길떄 다른 방법이 없을 까요 꼭 CLASS를 이용하여 만들고 싶구요..다른 방법으로 프로그램을 만들고 싶습니다.
#include <string> #include <list>
class Student { private: std::string m_StrName; int m_nNo; int m_nEng; int m_nMath;
public: explicit __fastcall Student(int no, const char* name, int eng, int math); virtual __fastcall ~Student(void);
std::string __fastcall GetName(); int __fastcall GetNo(); int __fastcall GetEng(); int __fastcall GetMath(); }; //---------------------------------------------------------------------------
__fastcall Student::Student(int no, const char* name, int eng, int math) : m_nNo(no), m_nEng(eng), m_nMath(math), m_StrName(name) { } //---------------------------------------------------------------------------
__fastcall Student::~Student(void) { } //---------------------------------------------------------------------------
std::string __fastcall Student::GetName() { return m_StrName; } //---------------------------------------------------------------------------
int __fastcall Student::GetNo() { return m_nNo; } //---------------------------------------------------------------------------
int __fastcall Student::GetEng(){ return m_nEng; } //---------------------------------------------------------------------------
int __fastcall Student::GetMath() { return m_nMath; } //---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender) { try { std::list< Student* > StudentList; StudentList.push_back(new Student(1, "김성주", 90, 98)); StudentList.push_back(new Student(2, "이아랑", 80, 100)); StudentList.push_back(new Student(3, "이현진", 20, 10)); // ...... 목록 추가
Memo1->Lines->Clear(); std::list< Student* >::iterator iterator; for(iterator=StudentList.begin(); iterator!=StudentList.end(); ++iterator) { Memo1->Lines->Add("-------------------------------------"); Memo1->Lines->Add("Number : "+IntToStr((*iterator)->GetNo())); Memo1->Lines->Add("Name : "+AnsiString((*iterator)->GetName().c_str())); Memo1->Lines->Add("English: "+IntToStr((*iterator)->GetEng())); Memo1->Lines->Add("Math : "+IntToStr((*iterator)->GetMath())); delete (*iterator); (*iterator)=NULL; }
StudentList.clear(); } catch(const Exception& E) { ShowMessage("Exception: "+E.Message); } catch(const std::exception& e) { ShowMessage("Exception: "+AnsiString(e.what())); } } //---------------------------------------------------------------------------
|