Разработка программных средств в C++Builder с использованием диаграммы классов
Пример 1. Диаграмма классов Диаграмма классов
Пример 1. Сгенерированный код на языке С++ CASE-средством Rational Rose Сгенерированный код на языке С++ CASE-средством Rational Rose Текс содержит описания конструктора и деструктура класса student. Текс содержит описания конструктора и деструктура класса student. //## begin module%1.2%.codegen_version preserve=yes //## begin module%1.2%.codegen_version preserve=yes // Read the documentation to learn more about C++ code generator // Read the documentation to learn more about C++ code generator // versioning. // versioning. //## end module%1.2%.codegen_version //## end module%1.2%.codegen_version //## begin module%407A8ED70148.cm preserve=no //## begin module%407A8ED70148.cm preserve=no // %X% %Q% %Z% %W% // %X% %Q% %Z% %W% //## end module%407A8ED70148.cm //## end module%407A8ED70148.cm //## begin module%407A8ED70148.cp preserve=no //## begin module%407A8ED70148.cp preserve=no //## end module%407A8ED70148.cp //## end module%407A8ED70148.cp //## Module: students%407A8ED70148; Pseudo Package body //## Module: students%407A8ED70148; Pseudo Package body //## Source file: E:\RR2000\Rose 2000\C++\source\students.cpp //## Source file: E:\RR2000\Rose 2000\C++\source\students.cpp
Текст программы для примера 1 (students.cpp) //## begin module%407A8ED70148.additionalIncludes preserve=no //## begin module%407A8ED70148.additionalIncludes preserve=no //## end module%407A8ED70148.additionalIncludes //## end module%407A8ED70148.additionalIncludes //## begin module%407A8ED70148.includes preserve=yes //## begin module%407A8ED70148.includes preserve=yes //## end module%407A8ED70148.includes //## end module%407A8ED70148.includes // students // students #include "students.h" #include "students.h" //## begin module%407A8ED70148.additionalDeclarations preserve=yes //## begin module%407A8ED70148.additionalDeclarations preserve=yes //## end module%407A8ED70148.additionalDeclarations //## end module%407A8ED70148.additionalDeclarations // Class students // Class students
Текст программы для примера 1 (students.cpp) students::students() students::students() //## begin students::students%407A8ED70148_const.hasinit preserve=no //## begin students::students%407A8ED70148_const.hasinit preserve=no //## end students::students%407A8ED70148_const.hasinit //## end students::students%407A8ED70148_const.hasinit //## begin students::students%407A8ED70148_const.initialization preserve=yes //## begin students::students%407A8ED70148_const.initialization preserve=yes //## end students::students%407A8ED70148_const.initialization //## end students::students%407A8ED70148_const.initialization { //## begin students::students%407A8ED70148_const.body preserve=yes //## begin students::students%407A8ED70148_const.body preserve=yes //## end students::students%407A8ED70148_const.body //## end students::students%407A8ED70148_const.body } students::students(const students &right) students::students(const students &right) //## begin students::students%407A8ED70148_copy.hasinit preserve=no //## begin students::students%407A8ED70148_copy.hasinit preserve=no //## end students::students%407A8ED70148_copy.hasinit //## end students::students%407A8ED70148_copy.hasinit //## begin students::students%407A8ED70148_copy.initialization preserve=yes //## begin students::students%407A8ED70148_copy.initialization preserve=yes //## end students::students%407A8ED70148_copy.initialization //## end students::students%407A8ED70148_copy.initialization { //## begin students::students%407A8ED70148_copy.body preserve=yes //## begin students::students%407A8ED70148_copy.body preserve=yes //## end students::students%407A8ED70148_copy.body //## end students::students%407A8ED70148_copy.body }
Текст программы для примера 1 (students.cpp) students::~students() students::~students() { //## begin students::~students%407A8ED70148_dest.body preserve=yes //## begin students::~students%407A8ED70148_dest.body preserve=yes //## end students::~students%407A8ED70148_dest.body //## end students::~students%407A8ED70148_dest.body } students & students::operator=(const students &right) students & students::operator=(const students &right) { //## begin students::operator=%407A8ED70148_assign.body preserve=yes //## begin students::operator=%407A8ED70148_assign.body preserve=yes //## end students::operator=%407A8ED70148_assign.body //## end students::operator=%407A8ED70148_assign.body }
Текст программы для примера 1 (students.cpp) int students::operator==(const students &right) const int students::operator==(const students &right) const { //## begin students::operator==%407A8ED70148_eq.body preserve=yes //## begin students::operator==%407A8ED70148_eq.body preserve=yes //## end students::operator==%407A8ED70148_eq.body //## end students::operator==%407A8ED70148_eq.body } int students::operator!=(const students &right) const int students::operator!=(const students &right) const { //## begin students::operator!=%407A8ED70148_neq.body preserve=yes //## begin students::operator!=%407A8ED70148_neq.body preserve=yes //## end students::operator!=%407A8ED70148_neq.body //## end students::operator!=%407A8ED70148_neq.body } // Additional Declarations // Additional Declarations //## begin students%407A8ED70148.declarations preserve=yes //## begin students%407A8ED70148.declarations preserve=yes //## end students%407A8ED70148.declarations //## end students%407A8ED70148.declarations //## begin module%407A8ED70148.epilog preserve=yes //## begin module%407A8ED70148.epilog preserve=yes //## end module%407A8ED70148.epilog //## end module%407A8ED70148.epilog
Текст программы для примера 1 (students.h) Содержит описание класса student, его атрибутов и методов Содержит описание класса student, его атрибутов и методов //## begin module%1.2%.codegen_version preserve=yes //## begin module%1.2%.codegen_version preserve=yes // Read the documentation to learn more about C++ code generator // Read the documentation to learn more about C++ code generator // versioning. // versioning. //## end module%1.2%.codegen_version //## end module%1.2%.codegen_version //## begin module%407A8ED70148.cm preserve=no //## begin module%407A8ED70148.cm preserve=no // %X% %Q% %Z% %W% // %X% %Q% %Z% %W% //## end module%407A8ED70148.cm //## end module%407A8ED70148.cm //## begin module%407A8ED70148.cp preserve=no //## begin module%407A8ED70148.cp preserve=no //## end module%407A8ED70148.cp //## end module%407A8ED70148.cp //## Module: students%407A8ED70148; Pseudo Package specification //## Module: students%407A8ED70148; Pseudo Package specification //## Source file: E:\RR2000\Rose 2000\C++\source\students.h //## Source file: E:\RR2000\Rose 2000\C++\source\students.h
Текст программы для примера 1 (students.h) #ifndef students_h #ifndef students_h #define students_h 1 #define students_h 1 #define NUMERIC int #define NUMERIC int #define CHAR char* #define CHAR char* //## begin module%407A8ED70148.additionalIncludes preserve=no //## begin module%407A8ED70148.additionalIncludes preserve=no //## end module%407A8ED70148.additionalIncludes //## end module%407A8ED70148.additionalIncludes //## begin module%407A8ED70148.includes preserve=yes //## begin module%407A8ED70148.includes preserve=yes //## end module%407A8ED70148.includes //## end module%407A8ED70148.includes //## begin module%407A8ED70148.additionalDeclarations preserve=yes //## begin module%407A8ED70148.additionalDeclarations preserve=yes //## end module%407A8ED70148.additionalDeclarations //## end module%407A8ED70148.additionalDeclarations //## begin students%407A8ED70148.preface preserve=yes //## begin students%407A8ED70148.preface preserve=yes //## end students%407A8ED70148.preface //## end students%407A8ED70148.preface
Лекция 11. Текст программы для примера 1 (students.h) //## Class: students%407A8ED70148 //## Class: students%407A8ED70148 //## Category: //## Category: //## Persistence: Transient //## Persistence: Transient //## Cardinality/Multiplicity: n //## Cardinality/Multiplicity: n class students class students { //## begin students%407A8ED70148.initialDeclarations preserve=yes //## begin students%407A8ED70148.initialDeclarations preserve=yes //## end students%407A8ED70148.initialDeclarations //## end students%407A8ED70148.initialDeclarations public: public: //## Constructors (generated) //## Constructors (generated) students(); students(); students(const students &right); students(const students &right);
Текст программы для примера 1 (students.h) //## Destructor (generated) //## Destructor (generated) ~students(); ~students(); //## Assignment Operation (generated) //## Assignment Operation (generated) students & operator=(const students &right); students & operator=(const students &right); //## Equality Operations (generated) //## Equality Operations (generated) int operator==(const students &right) const; int operator==(const students &right) const; int operator!=(const students &right) const; int operator!=(const students &right) const; //## Get and Set Operations for Class Attributes (generated) //## Get and Set Operations for Class Attributes (generated) //## Attribute: fio%407A908200DA //## Attribute: fio%407A908200DA const char* get_fio () ; const char* get_fio () ; void set_fio (char* value); void set_fio (char* value); //## Attribute: gruppa%407A909700AB //## Attribute: gruppa%407A909700AB const char* get_gruppa () const; const char* get_gruppa () const; void set_gruppa (char* value); void set_gruppa (char* value);
Текст программы для примера 1 (students.h) //## Attribute: nomer zachetki%407A90A1007D //## Attribute: nomer zachetki%407A90A1007D const int get_nomer_zachetki () const; const int get_nomer_zachetki () const; void set_nomer_zachetki (int value); void set_nomer_zachetki (int value); //## Attribute: obshejit%407A90AE00AB //## Attribute: obshejit%407A90AE00AB const char* get_obshejit () const; const char* get_obshejit () const; void set_obshejit (char* value); void set_obshejit (char* value); //## Attribute: vozrast%40B1E4E20073 //## Attribute: vozrast%40B1E4E20073 const int get_vozrast () const; const int get_vozrast () const; void set_vozrast (int value); void set_vozrast (int value); // Additional Public Declarations // Additional Public Declarations //## begin students%407A8ED70148.public preserve=yes //## begin students%407A8ED70148.public preserve=yes //## end students%407A8ED70148.public //## end students%407A8ED70148.public
Текст программы для примера 1 (students.h) protected: protected: // Additional Protected Declarations // Additional Protected Declarations //## begin students%407A8ED70148.protected preserve=yes //## begin students%407A8ED70148.protected preserve=yes //## end students%407A8ED70148.protected //## end students%407A8ED70148.protected private: private: //## Get and Set Operations for Class Attributes (generated) //## Get and Set Operations for Class Attributes (generated) //## Attribute: name%40B1D897002A //## Attribute: name%40B1D897002A const char* get_name () const; const char* get_name () const; void set_name (char* value); void set_name (char* value);
Текст программы для примера 1 (students.h) //## Attribute: pol%40B1E4C603A0 //## Attribute: pol%40B1E4C603A0 const char get_pol () const; const char get_pol () const; void set_pol (char value); void set_pol (char value); // Additional Private Declarations // Additional Private Declarations //## begin students%407A8ED70148.private preserve=yes //## begin students%407A8ED70148.private preserve=yes //## end students%407A8ED70148.private //## end students%407A8ED70148.private private: //## implementation private: //## implementation // Data Members for Class Attributes // Data Members for Class Attributes //## begin students::fio%407A908200DA.attr preserve=no public: CHAR {U} //## begin students::fio%407A908200DA.attr preserve=no public: CHAR {U} char* fio; char* fio; //## end students::fio%407A908200DA.attr //## end students::fio%407A908200DA.attr
Текст программы для примера 1 (students.h) //## begin students::gruppa%407A909700AB.attr preserve=no public: CHAR {U} //## begin students::gruppa%407A909700AB.attr preserve=no public: CHAR {U} CHAR gruppa; CHAR gruppa; //## end students::gruppa%407A909700AB.attr //## end students::gruppa%407A909700AB.attr //## begin students::nomer zachetki%407A90A1007D.attr preserve=no public: NUMERIC {U} //## begin students::nomer zachetki%407A90A1007D.attr preserve=no public: NUMERIC {U} NUMERIC nomer_zachetki; NUMERIC nomer_zachetki; //## end students::nomer zachetki%407A90A1007D.attr //## end students::nomer zachetki%407A90A1007D.attr //## begin students::obshejit%407A90AE00AB.attr preserve=no public: char {U} //## begin students::obshejit%407A90AE00AB.attr preserve=no public: char {U} char* obshejit; char* obshejit; //## end students::obshejit%407A90AE00AB.attr //## end students::obshejit%407A90AE00AB.attr //## begin students::name%40B1D897002A.attr preserve=no private: void {U} //## begin students::name%40B1D897002A.attr preserve=no private: void {U} char* name; char* name; //## end students::name%40B1D897002A.attr //## end students::name%40B1D897002A.attr //## begin students::pol%40B1E4C603A0.attr preserve=no private: char {U} //## begin students::pol%40B1E4C603A0.attr preserve=no private: char {U} char pol; char pol; //## end students::pol%40B1E4C603A0.attr //## end students::pol%40B1E4C603A0.attr
Текст программы для примера 1 (students.h) //## begin students::vozrast%40B1E4E20073.attr preserve=no public: NUMERIC {U} //## begin students::vozrast%40B1E4E20073.attr preserve=no public: NUMERIC {U} int vozrast; int vozrast; //## end students::vozrast%40B1E4E20073.attr //## end students::vozrast%40B1E4E20073.attr // Additional Implementation Declarations // Additional Implementation Declarations //## begin students%407A8ED70148.implementation preserve=yes //## begin students%407A8ED70148.implementation preserve=yes //## end students%407A8ED70148.implementation //## end students%407A8ED70148.implementation }; }; //## begin students%407A8ED70148.postscript preserve=yes //## begin students%407A8ED70148.postscript preserve=yes //## end students%407A8ED70148.postscript //## end students%407A8ED70148.postscript // Class students // Class students
Текст программы для примера 1 (students.h) //## Get and Set Operations for Class Attributes (inline) //## Get and Set Operations for Class Attributes (inline) inline const CHAR students::get_fio () inline const CHAR students::get_fio () { //## begin students::get_fio%407A908200DA.get preserve=no //## begin students::get_fio%407A908200DA.get preserve=no return fio; return fio; //## end students::get_fio%407A908200DA.get //## end students::get_fio%407A908200DA.get } inline void students::set_fio (CHAR value) inline void students::set_fio (CHAR value) { //## begin students::set_fio%407A908200DA.set preserve=no //## begin students::set_fio%407A908200DA.set preserve=no fio = value; fio = value; //## end students::set_fio%407A908200DA.set //## end students::set_fio%407A908200DA.set } inline const CHAR students::get_gruppa () const inline const CHAR students::get_gruppa () const { //## begin students::get_gruppa%407A909700AB.get preserve=no //## begin students::get_gruppa%407A909700AB.get preserve=no return gruppa; return gruppa; //## end students::get_gruppa%407A909700AB.get //## end students::get_gruppa%407A909700AB.get }
Текст программы для примера 1 (students.h) inline void students::set_gruppa (CHAR value) inline void students::set_gruppa (CHAR value) { //## begin students::set_gruppa%407A909700AB.set preserve=no //## begin students::set_gruppa%407A909700AB.set preserve=no gruppa = value; gruppa = value; //## end students::set_gruppa%407A909700AB.set //## end students::set_gruppa%407A909700AB.set } inline const NUMERIC students::get_nomer_zachetki () const inline const NUMERIC students::get_nomer_zachetki () const { //## begin students::get_nomer_zachetki%407A90A1007D.get preserve=no //## begin students::get_nomer_zachetki%407A90A1007D.get preserve=no return nomer_zachetki; return nomer_zachetki; //## end students::get_nomer_zachetki%407A90A1007D.get //## end students::get_nomer_zachetki%407A90A1007D.get } inline void students::set_nomer_zachetki (NUMERIC value) inline void students::set_nomer_zachetki (NUMERIC value) { //## begin students::set_nomer_zachetki%407A90A1007D.set preserve=no //## begin students::set_nomer_zachetki%407A90A1007D.set preserve=no nomer_zachetki = value; nomer_zachetki = value; //## end students::set_nomer_zachetki%407A90A1007D.set //## end students::set_nomer_zachetki%407A90A1007D.set }
Текст программы для примера 1 (students.h) inline const char* students::get_obshejit () const inline const char* students::get_obshejit () const { //## begin students::get_obshejit%407A90AE00AB.get preserve=no //## begin students::get_obshejit%407A90AE00AB.get preserve=no return obshejit; return obshejit; //## end students::get_obshejit%407A90AE00AB.get //## end students::get_obshejit%407A90AE00AB.get } inline void students::set_obshejit (char* value) inline void students::set_obshejit (char* value) { //## begin students::set_obshejit%407A90AE00AB.set preserve=no //## begin students::set_obshejit%407A90AE00AB.set preserve=no obshejit = value; obshejit = value; //## end students::set_obshejit%407A90AE00AB.set //## end students::set_obshejit%407A90AE00AB.set } inline const char* students::get_name () const inline const char* students::get_name () const { //## begin students::get_name%40B1D897002A.get preserve=no //## begin students::get_name%40B1D897002A.get preserve=no return name; return name; //## end students::get_name%40B1D897002A.get //## end students::get_name%40B1D897002A.get } inline void students::set_name (char* value) inline void students::set_name (char* value) { //## begin students::set_name%40B1D897002A.set preserve=no //## begin students::set_name%40B1D897002A.set preserve=no name = value; name = value; //## end students::set_name%40B1D897002A.set //## end students::set_name%40B1D897002A.set }
Текст программы для примера 1 (students.h) inline const char students::get_pol () const inline const char students::get_pol () const { //## begin students::get_pol%40B1E4C603A0.get preserve=no //## begin students::get_pol%40B1E4C603A0.get preserve=no return pol; return pol; //## end students::get_pol%40B1E4C603A0.get //## end students::get_pol%40B1E4C603A0.get } inline void students::set_pol (char value) inline void students::set_pol (char value) { //## begin students::set_pol%40B1E4C603A0.set preserve=no //## begin students::set_pol%40B1E4C603A0.set preserve=no pol = value; pol = value; //## end students::set_pol%40B1E4C603A0.set //## end students::set_pol%40B1E4C603A0.set } inline const int students::get_vozrast () const inline const int students::get_vozrast () const { //## begin students::get_vozrast%40B1E4E20073.get preserve=no //## begin students::get_vozrast%40B1E4E20073.get preserve=no return vozrast; return vozrast; //## end students::get_vozrast%40B1E4E20073.get //## end students::get_vozrast%40B1E4E20073.get }
Текст программы для примера 1 (students.h) inline void students::set_vozrast (int value) inline void students::set_vozrast (int value) { //## begin students::set_vozrast%40B1E4E20073.set preserve=no //## begin students::set_vozrast%40B1E4E20073.set preserve=no vozrast = value; vozrast = value; //## end students::set_vozrast%40B1E4E20073.set //## end students::set_vozrast%40B1E4E20073.set } //## begin module%407A8ED70148.epilog preserve=yes //## begin module%407A8ED70148.epilog preserve=yes //## end module%407A8ED70148.epilog //## end module%407A8ED70148.epilog #endif #endif
Текст программы Project1.cpp Этот файл содержит описание главной функции. Содержание этого файла генерируется программной средой C++Builder. Этот файл содержит описание главной функции. Содержание этого файла генерируется программной средой C++Builder. // // #include #include #pragma hdrstop #pragma hdrstop USERES("Project1.res"); USERES("Project1.res"); USEFORM("Unit1.cpp", Form1); USEFORM("Unit1.cpp", Form1); USEUNIT("students.cpp"); USEUNIT("students.cpp"); USE("students.h", File); USE("students.h", File); // // WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { try try { { Application->Initialize(); Application->Initialize(); Application->CreateForm(__classid(TForm1), &Form1); Application->CreateForm(__classid(TForm1), &Form1); Application->Run(); Application->Run(); } } catch (Exception &exception) catch (Exception &exception) { { Application->ShowException(&exception); Application->ShowException(&exception); } } return 0; return 0; } // //
Форма пользовательского интерфейса
Текст функций, выполняемых при нажатии на кнопку // // #include #include #pragma hdrstop #pragma hdrstop #include "Unit1.h" #include "Unit1.h" #include"students.h" #include"students.h" #include"students.cpp" #include"students.cpp" // // #pragma package(smart_init) #pragma package(smart_init) #pragma resource "*.dfm" #pragma resource "*.dfm" TForm1 *Form1; TForm1 *Form1; // // __fastcall TForm1::TForm1(TComponent* Owner) __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) : TForm(Owner) { } // // void __fastcall TForm1::Button1Click(TObject *Sender) void __fastcall TForm1::Button1Click(TObject *Sender) { students *pstudents; students *pstudents; pstudents=new students; pstudents=new students; pstudents->set_fio( Edit1->Text.c_str()); pstudents->set_fio( Edit1->Text.c_str()); Edit2->Text=pstudents->get_fio(); Edit2->Text=pstudents->get_fio(); MessageBox(NULL,pstudents->get_fio(),"Значение атрибута fio класса students",MB_OK); MessageBox(NULL,pstudents->get_fio(),"Значение атрибута fio класса students",MB_OK); } // //
Файл, содержащий описание формы Автоматически генерируется в C++Builder. Автоматически генерируется в C++Builder. // // #ifndef Unit1H #ifndef Unit1H #define Unit1H #define Unit1H // // #include #include // // class TForm1 : public TForm class TForm1 : public TForm { __published:// IDE-managed Components __published:// IDE-managed Components TEdit *Edit1; TEdit *Edit1; TEdit *Edit2; TEdit *Edit2; TButton *Button1; TButton *Button1; TLabel *Label1; TLabel *Label1; TLabel *Label2; TLabel *Label2; void __fastcall Button1Click(TObject *Sender); void __fastcall Button1Click(TObject *Sender); private:// User declarations private:// User declarations public:// User declarations public:// User declarations __fastcall TForm1(TComponent* Owner); __fastcall TForm1(TComponent* Owner); }; }; // // extern PACKAGE TForm1 *Form1; extern PACKAGE TForm1 *Form1; // // #endif #endif
Интерфейс программного средства после ввода Ф.И.О. и нажатия на кнопку