⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit6.cpp

📁 以学生本班的成绩管理为应用、开发一个小小和成绩管理系统。设计了如下类: Person 、Student、Teacher、Credit。利用builder的可视化编程.
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include"TPerson.h"
#include"TCredit.h"
#include "Unit6.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm6 *Form6;
//---------------------------------------------------------------------------
__fastcall TForm6::TForm6(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm6::Label4Click(TObject *Sender)
{
   if(this->Edit1->Text.Length()!=10)
        ShowMessage("请输入正确的帐号");
   else
   {
     Person *t=NewStudent();
     Credit *cre=new Credit();
     FILE *fp=fopen("e:\\c\\student","r");
     if(fp==NULL) ShowMessage("不明错误");
     else
     {
        int i=0;
        while(!feof(fp))
        {
           t->Read(fp);
           if(t->GetNO()==this->Edit1->Text)
           {
              i=1;
              fclose(fp);
              break;

           }
        }
        if(i==1)
        {
          this->Edit2->Text=t->GetName();
          this->Edit3->Text=t->GetClass();
          AnsiString str="e:\\C\\" +this->ComboBox1->Text ;
          fp=fopen(str.c_str(),"rb+");
          if(fp==NULL) ShowMessage("没有该学科" );
          else
          {
              while(!feof(fp))
              {
                cre->Read(fp);
                if(this->Edit1->Text==cre->GetNO())
                  {
                     i=0;
                     fclose(fp);
                     break;
                  }
              }
              if(i==0)
              {
                this->Edit5->Text=cre->GetCredit();
              }
              else
              {
               fclose(fp);

              }

          }

        }
        else
        {
           fclose(fp);
           ShowMessage("该学生不存在" );
        }



     }
     delete t;
      delete cre;
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Button1Click(TObject *Sender)
{
   if(this->Edit1->Text.Length()!=10||this->Edit5->Text.Length()==0)
   {
      if(this->Edit1->Text.Length()!=10)
        ShowMessage("请输入正确的帐号");
      else
        ShowMessage("清先输入成绩");
   }
   else
   {
     Person *t=NewStudent();
     Credit *cre=new Credit();
     FILE *fp=fopen("e:\\c\\student","r");
     if(fp==NULL) ShowMessage("不明错误");
     else
     {
        int i=0;
        while(!feof(fp))
        {
           t->Read(fp);
           if(t->GetNO()==this->Edit1->Text)
           {
              i=1;
              fclose(fp);
              break;

           }
        }
        if(i==1)
        {
          this->Edit2->Text=t->GetName();
          this->Edit3->Text=t->GetClass();
          AnsiString str="e:\\C\\" +this->ComboBox1->Text ;
          fp=fopen(str.c_str(),"rb+");
          if(fp==NULL) ShowMessage("没有该学科" );
          else
          {
              unsigned int n=0;
              while(!feof(fp))
              {
                cre->Read(fp);
                n++;
                if(this->Edit1->Text==cre->GetNO())
                  {
                     i=0;
                     break;
                  }
              }
              if(i==0)
              {
                 fseek(fp,(n-1)*(11+sizeof(float)),SEEK_SET);
                 cre->SetCredit(StrToFloat(this->Edit5->Text));
                 cre->Write(fp);
                 ShowMessage("已有该学生成绩已更新" );
                 fclose(fp);
              }
              else
              {
                cre->SetNO(t->GetNO());
                cre->SetCredit(StrToFloat(this->Edit5->Text));
                cre->Write(fp);
                ShowMessage("该学生成绩保存成功" );
                fclose(fp);

              }

          }

        }
        else
        {
           fclose(fp);
           ShowMessage("该学生不存在" );
        }



     }
     delete t;
      delete cre;
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Button3Click(TObject *Sender)
{
 this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Button2Click(TObject *Sender)
{
     this->Memo1->Clear();
     Person *t=NewStudent();
     Credit *cre=new Credit();
     int i=0;
     FILE *fp=NULL,*fc=NULL;
     AnsiString str="e:\\C\\" +this->ComboBox1->Text ;
     fc=fopen(str.c_str(),"rb+");
     fp=fopen("e:\\c\\student" ,"r");
     if(fc==NULL||fp==NULL)
     {
         if(fc==NULL)
           ShowMessage("没有该学科" );
         else
            ShowMessage("不明错误");
     }

     else
     {
        while(!feof(fc))
        {
           cre->Read(fc);
           while(!feof(fp))
           {
             t->Read(fp);
             if(t->GetNO()==cre->GetNO())
             {
               i=1;
               break;
             }

           }
           if(i==1)
            {
               this->Edit2->Text=t->GetName();
               this->Edit3->Text=t->GetClass();
               this->Memo1->Lines->Add("姓名:"+t->GetName()+"  学号:"+t->GetNO()+"  班级:"+t->GetClass()+"  学科:"+this->ComboBox1->Text+"  成绩:"+cre->GetCredit());
               
            }
            else
            {

            }

        }

        fclose(fp);
        fclose(fc);


     }
     delete t;
     delete cre;
}
//---------------------------------------------------------------------------




void __fastcall TForm6::Button4Click(TObject *Sender)
{
   AnsiString str="e:\\c\\"+this->ComboBox1->Text;
   Credit *cre=new Credit();
   FILE *fc=NULL;
   fc=fopen(str.c_str(),"r");
   if(fc==NULL)
   {
        ShowMessage("没有该学科") ;
        delete cre;
        return ;
   }
  // else
  // (
      int i=0;
      while(!feof(fc))
      {
        cre->Read(fc);
        if(this->Edit1->Text==cre->GetNO())
        {
           fclose(fc);
           i=1;
           break;
        }
      }
      if(i==1)
      {
       this->Memo1->Lines->Add("你的"+this->ComboBox1->Text+"成绩为:"+cre->GetCredit());
       this->Memo1->Lines->Add("");
      }
      else
      {
       fclose(fc);
      }
 //  )
   delete cre;
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -