|
안녕하세요?
Input 과 Output 은 재차 강조를 해도 지나치지 않죠.
우선 무엇을 하고 싶은 가를 정리해 보겠습니다.
학생이 있습니다.
수학, 영어, 국어 과목이 있습니다.
총점을 알고 싶습니다.
평균을 알고 싶습니다.
학생을 클래스와 해서 위의 데이터를 처리해 보기로 하죠.
class TStudent
{
private:
AnsiString szName; // 학생 이름
int FHan; // 국어 점수
int FEng; // 영어 점수
int FMath; // 수학 점수
public:
void __fastcall SetData( AnsiString szName, int iHan, int iEng, int iMath ); // 학생의 이름과 점수 입력
int __fastcall GetTotal( void ); // 총점 얻기
int __fastcall GetAverage( void ); // 평균 얻기
};
간단하게 위 클래스처럼 만들 수 있을 겁니다.
구현부는 -_-;;; 워낙 단순하니 하실수 있겠죠.
쥬신 님이 쓰신 글 :
: c++책에 있는것과 제가 만든 것은 값은 같은 겂니다. 빌더로 옮길떄 다른 방법이 없을 까요 꼭 CLASS를 이용하여 만들고 싶구요..다른 방법으로 프로그램을 만들고 싶습니다.
: /* //C++프로그램이고 아래가 제가 만든 프로그램입니다.
: #include <iostream>
: using namespace std;
: class Student
: {
: protected:
: private:
: public:
: int no;
: char name[10];
: int eng;
: int math;
: void TData( );
: };
:
: void Student::TData( )
: {
: cout<<no<<endl;
: cout<<name<<endl;
: cout<<eng<<endl;
: cout<<math<<endl;
: }
: int main()
: {
: Student kim;
: no = 1;
: strcpy(name, "김성주");
: eng = 90;
: math = 98;
: kim.TData( );
: Student lee;
: no = 2;
: strcpy(name, "이아랑");
: eng = 80;
: math = 100;
: lee.TData( );
: return 0;
: }
: */
: 빌더로 짠거 입니다.
: //---------------------------------------------------------------------------
:
: #ifndef Unit2H
: #define Unit2H
: //---------------------------------------------------------------------------
: class Student
: {
: protected:
: private:
: public:
: __fastcall Student(void);
: __fastcall ~Student(void);
: public:
: int no;
: char name[10];
: int eng;
: int math;
: void __fastcall TData(void);
: void __fastcall FData(void);
: };
: extern Student Data;
: #endif
: //---------------------------------------------------------------------------
:
: #include <vcl.h>
: #pragma hdrstop
:
: #include "Unit2.h"
:
: //---------------------------------------------------------------------------
:
: #pragma package(smart_init)
: Student Data;
: __fastcall Student:: Student(void)
: {
: }
: void __fastcall Student::TData(void)
: {
: Student kim;
: no = 1;
: strcpy(name, "김성주");
: eng = 90;
: math = 98;
: }
: void __fastcall Student::FData(void)
: {
: Student lee;
: no = 2;
: strcpy(name, "이아랑");
: eng = 80;
: math = 100;
: }
: __fastcall Student::~Student(void)
: {
: }
: //---------------------------------------------------------------------------
:
: #include <vcl.h>
: #pragma hdrstop
:
: #include "Unit1.h"
: #include "Unit2.h"
: //---------------------------------------------------------------------------
: #pragma package(smart_init)
: #pragma resource "*.dfm"
: TForm1 *Form1;
: //---------------------------------------------------------------------------
: __fastcall TForm1::TForm1(TComponent* Owner)
: : TForm(Owner)
: {
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TForm1::Button1Click(TObject *Sender)
: {
: Data.TData( );
: Memo1->Lines->Add(Data.no);
: Memo1->Lines->Add(Data.name);
: Memo1->Lines->Add(Data.eng);
: Memo1->Lines->Add(Data.math);
: Data.FData( );
: Memo1->Lines->Add(Data.no);
: Memo1->Lines->Add(Data.name);
: Memo1->Lines->Add(Data.eng);
: Memo1->Lines->Add(Data.math);
: }
: 답변을 부탁드립니다. 꼭 알고 싶습니다..............박카스..........선전 아닙니다.
|