#ifndef __AFXWIN_H__//绩点计算器3.h
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
#ifndef _SCALCULATOR_H_
#define _SCALCULATOR_H_
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int SubjectLen=10;
const int MaxStudent=20;
class CManager;
class CStudent
{
friend CManager;
public:
static int num;
public:
// void* operator new(size_t obj);
// void operator delete(void *p);
// CStudent operator =(CStudent &obj);
CStudent()
{
m_AllGrade=0;
m_ComplusoryGrade=0;
m_num=num;
num++;
m_numberOfGrade=0;
m_password="woshistudent";
m_numberOfComplusory=0;
m_allSum=0;
m_ComplusorySum=0;
i=0;
k=0;
fstream f;
all_compulsory[0]='0'+m_num;
all_compulsory[1]='\0';
all_all[0]='0'+m_num;
all_all[1]='\0';
char name_compulsory[]="compulsory.dat";
char name_all[]="all.dat";
strcat(all_compulsory,name_compulsory);
strcat(all_all,name_all);
f.open(all_all,ios::out|ios::binary);
if(f.fail())
{
//cout<<"创建文件时失败!"<<endl;
exit(6);
}else
{
//cout<<"创建文件名为:"<<all_all<<endl;
f.close();
}
f.open(all_compulsory,ios::out|ios::binary);
if(f.fail())
{
//cout<<"创建文件时失败!"<<endl;
exit(6);
}else
{
// cout<<"创建文件名为:"<<all_compulsory<<endl;
f.close();
}
}
void ShowComplusorySubject_Grade();
void ShowGrade();
float GetAllGPA();
void CalculateAllGPA();
float GetAllAverage();
float GetComplusoryAverage();
float GetComplusoryGPA();
int GetStudentNumber()
{
return m_num;
}
//重设密码
void RevisePassword(CString newPassword);
~CStudent(){}
/*int GetNumberOfGrade()
{
return m_numberOfGrade;
}*/
void ShowAllSubject_Grade();
// void SetStudentPrivacy(string password,string name,char sex[]);
CString GetStudentPassword();
CString GetStudentName();
// int GetStudentNum();
//protected: int GetStudentNumberOfGrade();
// void ADDStudentNumberOfGrade();
void CalculateAllAverage();
void CalculateCompulsoryGPA();
void CalculateCompulsoryAverage();
char *GetBuf_allIP();
char *GetBuf_compulsoryIP();
private:
int m_num;//学生的学号
CString m_password;
CString m_name;
CString m_sex;
int m_grade[SubjectLen];
CString m_subject[SubjectLen];
int m_complusory[SubjectLen];
int m_numberOfGrade;
float m_GPA;
//float m_allGrade;
float m_ComplusoryGPA;
float m_average;
float m_ComplusoryAverage;
float m_AllGrade;
float m_ComplusoryGrade;
float m_allSum;
float m_ComplusorySum;
int m_numberOfComplusory;
public:
char buf_all[280];
char buf_compulsory[280];
int i;
int k;
char all_compulsory[20];
char all_all[20];
};
class CManager
{
public:
CManager();//初始化CManager
// SetStudentGrade();
/*SetAccoutPassword()
{
m_accout="woshimanager";
m_accoutPassword="woshimanager";
}*/
//创建学生的各种信息
void BuildStudent(CString name,CString sex);
//void ShowStudent(int number);
void InputStudentGrade(float grade,CString subject,int number,int j);
//void ShowStudentGrade(int number);
~CManager(){}
CStudent GetStudent(int number);
CStudent *GetStudentIP(int number);
private:
int m_studentNumber;
// string m_account;
// string m_accountPassword;
CStudent *p_student[MaxStudent];
};
#endif
/
// CMy3App:
// See 绩点计算器3.cpp for the implementation of this class
//
class CMy3App : public CWinApp
{
public:
CMy3App();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMy3App)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CMy3App)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_3_H__351F22D1_85AA_47B8_B319_91E0D42C7922__INCLUDED_)
// 绩点计算器3.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "绩点计算器3.h"
#include "绩点计算器3Dlg.h"
#include <fstream>
#include <cstdlib>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <fstream>
//#include <cstdlib>
#include "sCalculator.h"
int CStudent::num=0;
void CManager::BuildStudent(CString name,CString sex)
{
p_student[m_studentNumber]=new CStudent;
p_student[m_studentNumber]->m_name=name;
p_student[m_studentNumber]->m_sex=sex;
m_studentNumber++;
}
CString CStudent::GetStudentPassword()
{
return m_password;
}
CString CStudent::GetStudentName()
{
return m_name;
}
/*int CStudent::GetStudentNum()
{
return m_num;
}*/
CManager::CManager()
{
m_studentNumber=0;
for(int i=0;i<MaxStudent+1;i++)
p_student[i]=NULL;
}
void CManager::InputStudentGrade(float grade,CString subject,int number,int j)
{
char *char_subject=(LPSTR)(LPCTSTR)subject;
p_student[number]->m_grade[p_student[number]->m_numberOfGrade]=grade;
p_student[number]->m_AllGrade+=grade;
float sum=0.0;
if(grade<60){;}
else if(grade>59&&grade<65)
{
sum=(float)1.0;
}else if(grade>64&&grade<70)
{
sum=(float)1.7;
}else if(grade>69&&grade<75)
{
sum=(float)2.2;
}else if(grade>74&&grade<80)
{
sum=(float)2.7;
}else if(grade>79&&grade<85)
{
sum=(float)3.2;
}else if(grade>84&&grade<90)
{
sum=(float)3.6;
}
else if(grade>89&&grade<95)
{
sum=(float)3.8;
}else
sum=(float)4;
fstream f1;
/*f.out("calculation of GPA.dat",ios::out|ios::binary);
if(f1.fail())
{
MessageBox("打开文件失败!");
exit(0);
}else
f1.close();*/
/*if(p_student[number]->i==0)
{
f1.open("calculation of GPA.dat",ios::out|ios::binary);
if(f1.fail())
{
//MessageBox("打开文件失败!");
exit(0);
}else
f1.close();
}
}*/
/*if(p_student[number]->i==0)
{
f1.open("calculation of all GPA.dat",ios::out|ios::binary);
if(f1.fail())
{
cout<<"打开文件失败out!"<<endl;
}else
f1.close();
}*/
f1.open(p_student[number]->all_all,ios::app|ios::out|ios::binary);//需要更换名字注意out如果文件存在打开后会清零,c++中打开文件有顺序
if(f1.fail())
{
//MessageBox("打开文件失败!");
// cout<<"打开文件失败app!"<<endl;
exit(1);
}else
{
// cout<<p_student[number]->GetBuf_allIP()<<endl;
sprintf(p_student[number]->buf_all,"%10s%14s%8s%.2f\0","subject:",char_subject,"grade:",grade);
//cout<<p_student[number]->buf_all<<endl;
//cout<<"i="<<p_student[number]->i<<endl;
int num=(p_student[number]->i)*((sizeof(int))*13);
//cout<<"num="<<num<<endl;
f1.seekp(num,ios::beg);
(p_student[number]->i)++;
f1.write((char *)&(p_student[number]->buf_all),13*sizeof(int));
/*char buf[52];
f1.seekp(0);
//num=13*(sizeof(int))*(p_student[number]->i);
//cout<<"write后的num:"<<num<<endl;
//f1.read((char *)&buf,13*sizeof(int));
for(int bian=0;bian<p_student[number]->i;bian++)
{
f1.read(buf,13*sizeof(int));//f.read()在读取char时遇到‘\0’就结束
// f1.read((char *)&buf,num);
cout<<"buf="<<buf<<endl;
}*/
//char buf[90];
//f1.read(buf,13*sizeof(int));
//cout<<buf<<endl;
f1.close();
}
//cout<<"5"<<endl;
p_student[number]->m_allSum+=sum;
//记录学生的必修分数的文件
if(j==0)
{
//cout<<"6"<<endl;
p_student[number]->m_complusory[p_student[number]->m_numberOfGrade]=1;
p_student[number]->m_ComplusoryGrade+=grade;
p_student[number]->m_ComplusorySum+=sum;
(p_student[number]->m_numberOfComplusory)++;
//cout<<"必修"<<endl;
fstream f2;
/*if((p_student[number]->k)==0)
{
// cout<<"0"<<endl;
f2.open("calculation of compulsory GPA.txt",ios::out|ios::binary);
if(f2.fail())
{
cout<<"打开文件out失败!"<<endl;
exit(3);
}else
f2.close();
}*/
//cout<<"1"<<endl;
f2.open(p_student[number]->all_compulsory,ios::app|ios::out|ios::binary);
if(f2.fail())
{
//cout<<"文件打开失败!app";
exit(4);
}else
{
sprintf(p_student[number]->buf_compulsory,"%10s%14s%8s%5.2f\0","compulsory_subject:",char_subject,"compulsory_grade:",grade);
//strcat(p_student[number]->buf_compulsory," ");
//cout<<"buf_compulsory:"<<p_student[number]->buf_compulsory<<endl;
int num=(p_student[number]->k)*(sizeof(int)*13);
//cout<<"num="<<num<<endl;
f2.seekp(num,ios::beg);
(p_student[number]->k)++;
// cout<<"p_student[number]->k="<<p_student[number]->k<<endl;
f2.write((char *)&(p_student[number]->buf_compulsory),(13*sizeof(int)));
//cout<<"buf_compulsory:"<<p_student[number]->buf_compulsory<<endl;
/* char buf[52];
f2.seekp(0);
for(int y=0;y<p_student[number]->k;y++)
{
f2.read((char *)&buf,13*(sizeof(int))+3);
cout<<"buf:"<<buf<<endl;
}
// delete []buf2;
//f2.read((char *)&buf2,13*(sizeof(int)));
// cout<<"buf2"<<buf2<<endl;
//num=13*(sizeof(int))*(p_student[number]->i);
//cout<<"write后的num:"<<num<<endl;
//f1.read((char *)&buf,13*sizeof(int));*/
/*for(int bian=0;bian<p_student[number]->k;bian++)
{
f2.read((char *)&buf,13*sizeof(int));//f.read()在读取char时遇到‘\0’就结束
// f1.read((char *)&buf,num);
cout<<"buf="<<buf<<endl;
}*/
f2.close();
}
}
else
p_student[number]->m_complusory[p_student[number]->m_numberOfGrade]=0;
p_student[number]->m_subject[p_student[number]->m_numberOfGrade]=subject;
(p_student[number]->m_numberOfGrade)++;
}
/*void CManager::ShowStudent(int number)
{
if(p_student[number]==NULL)
{
cout<<"不存在改学生,输入有误!"<<endl;
}
else
{
cout<<"show the information of student whose num is "<<number<<endl;
cout<<"the name of student:"<<p_student[number]->m_name<<endl;
cout<<"the sex of the student:"<<p_student[number]->m_sex<<endl;
}
}(/
/*int CStudent::GetStudentNumberOfGrade()
{
return m_numberOfGrade;
}*/
/*void CStudent::ADDStudentNumberOfGrade()
{
m_numberOfGrade++;
}*/
/*void CManager::ShowStudentGrade(int number)
{
cout<<"the student's number is:"<<number<<endl;
for(int i=0;i<p_student[number]->m_numberOfGrade;i++)
{
cout<<"the student's subject is:"<<p_student[number]->m_subject[i]<<endl;
cout<<"this subject's grade is"<<p_student[number]->m_grade[i]<<endl;
}
}*/
void CStudent::ShowGrade()
{
for(int i=0;i<m_numberOfGrade;i++)
{
cout<<"the student's subject is:"<<m_subject[i]<<endl;
cout<<"this subject's grade is"<<m_grade[i]<<endl;
}
}
float CStudent::GetAllGPA()
{
return m_GPA;
}
// 95-100 90-94 85-89 80-84 75-79 70-74 65-69 60-64 <60
//绩点 4.0 3.8 3.6 3.2 2.7 2.2 1.7 1.0 0
void CStudent::CalculateAllGPA()
{
//m_sumGPA=0.0;
m_GPA=m_allSum/m_numberOfGrade;
}
//重设密码
void CStudent::RevisePassword(CString newPassword)
{
m_password=newPassword;
// cout<<"succeed to revise the password!"<<endl;
}
CStudent CManager::GetStudent(int number)
{
return *p_student[number];
}
/*void* CStudent ::operator new(size_t obj)
{
// cout<<"new一个CStudent对象"<<endl;
return malloc(obj);
}
//CStudent CStudent::operator =(CStudent &obj)
void CStudent::operator delete(void *p)
{
//cout<<"消除对象p"<<endl;
free(p);
}*/
void CStudent::ShowAllSubject_Grade()
{
for(int i=0;i<m_numberOfGrade;i++)
{
cout<<"the name of the subject "<<i<<":"<<m_subject[i]<<endl;
cout<<"the grade of the subject "<<i<<":"<<m_grade[i]<<endl;
if(m_complusory[i]==1)
cout<<"the subject "<<i<<" is complusory"<<endl;
else
cout<<"the subject "<<i<<" isn't complusory"<<endl;
}
}
char *CStudent::GetBuf_allIP()
{
char *p=&buf_all[0];
return p;
//return buf_all;
}
char *CStudent::GetBuf_compulsoryIP()
{
return buf_compulsory;
}
char *GetBuf_compulsoryIP();
CStudent* CManager::GetStudentIP(int number)
{
return p_student[number];
}
void CStudent::CalculateAllAverage()
{
m_average=m_AllGrade/m_numberOfGrade;
}
void CStudent::CalculateCompulsoryGPA()
{
m_ComplusoryGPA=m_ComplusorySum/m_numberOfComplusory;
}
void CStudent::CalculateCompulsoryAverage()
{
m_ComplusoryAverage=m_ComplusoryGrade/m_numberOfComplusory;
}
float CStudent::GetAllAverage()
{
return m_average;
}
float CStudent::GetComplusoryAverage()
{
return m_ComplusoryAverage;
}
float CStudent::GetComplusoryGPA()
{
return m_ComplusoryGPA;
}
void CStudent::ShowComplusorySubject_Grade()
{
int j=0;
for(int i=0;i<m_numberOfGrade;i++)
{
if(m_complusory[i]==1)
{
cout<<"the name of complusory subject "<<j<<":"<<m_subject[i]<<endl;
cout<<"the grade of complusory subject "<<j<<":"<<m_grade[i]<<endl;
j++;
}
}
}
/
// CMy3App
BEGIN_MESSAGE_MAP(CMy3App, CWinApp)
//{{AFX_MSG_MAP(CMy3App)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/
// CMy3App construction
CMy3App::CMy3App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/
// The one and only CMy3App object
CMy3App theApp;
/
// CMy3App initialization
BOOL CMy3App::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CMy3Dlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
#if !defined(AFX_DIALOG1_H__EBEFB79B_B16C_4AAB_8551_CCF71C690D20__INCLUDED_)//Dialog1.h
#define AFX_DIALOG1_H__EBEFB79B_B16C_4AAB_8551_CCF71C690D20__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Dialog1.h : header file
//
/
// Dialog1 dialog
class Dialog1 : public CDialog
{
// Construction
public:
Dialog1(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(Dialog1)
enum { IDD = IDD_DIALOG1 };
int m_dialog1_all;
float m_dialog1_average;
float m_dialog1_GPA;
CString m_dialog1_name;
CString m_dialog1_newpassword;
long m_dialog1_number;
CString m_dialog1_password;
CString m_dialog1_show;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(Dialog1)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(Dialog1)
afx_msg void OnDialog1Exit();
afx_msg void OnDialog1RevisePassword();
afx_msg void OnDialog1ElectCourse();
afx_msg void OnDialog1All();
afx_msg void OnDialog1Compulsory();
afx_msg void OnDialog1ShowPassword();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DIALOG1_H__EBEFB79B_B16C_4AAB_8551_CCF71C690D20__INCLUDED_)
// Dialog1.cpp : implementation file
//
#include "stdafx.h"
#include "绩点计算器3.h"
#include "Dialog1.h"
#include "Dialog2.h"
#include <fstream>
#include <cstring>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CManager manager;
/
// Dialog1 dialog
Dialog1::Dialog1(CWnd* pParent /*=NULL*/)
: CDialog(Dialog1::IDD, pParent)
{
//{{AFX_DATA_INIT(Dialog1)
m_dialog1_all = -1;
m_dialog1_average = 0.0f;
m_dialog1_GPA = 0.0f;
m_dialog1_name = _T("");
m_dialog1_newpassword = _T("");
m_dialog1_number = 0;
m_dialog1_password = _T("");
m_dialog1_show = _T("");
//}}AFX_DATA_INIT
}
void Dialog1::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Dialog1)
DDX_Radio(pDX, IDC_DIALOG1_ALL, m_dialog1_all);
DDX_Text(pDX, IDC_DIALOG1_AVERAGE, m_dialog1_average);
DDX_Text(pDX, IDC_DIALOG1_GPA, m_dialog1_GPA);
DDX_Text(pDX, IDC_DIALOG1_NAME, m_dialog1_name);
DDX_Text(pDX, IDC_DIALOG1_NEWPASSWORD, m_dialog1_newpassword);
DDX_Text(pDX, IDC_DIALOG1_NUMBER, m_dialog1_number);
DDX_Text(pDX, IDC_DIALOG1_PASSWORD, m_dialog1_password);
DDX_Text(pDX, IDC_DIALOG1_SHOW, m_dialog1_show);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Dialog1, CDialog)
//{{AFX_MSG_MAP(Dialog1)
ON_BN_CLICKED(IDC_DIALOG1_EXIT, OnDialog1Exit)
ON_BN_CLICKED(IDC_DIALOG1_REVISE_PASSWORD, OnDialog1RevisePassword)
ON_BN_CLICKED(IDC_DIALOG1_ELECT_COURSE, OnDialog1ElectCourse)
ON_BN_CLICKED(IDC_DIALOG1_ALL, OnDialog1All)
ON_BN_CLICKED(IDC_DIALOG1_COMPULSORY, OnDialog1Compulsory)
ON_BN_CLICKED(IDC_DIALOG1_SHOW_PASSWORD, OnDialog1ShowPassword)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// Dialog1 message handlers
void Dialog1::OnDialog1Exit()
{
// TODO: Add your control notification handler code here
CDialog::OnOK();
}
void Dialog1::OnDialog1RevisePassword()
{
// TODO: Add your control notification handler code here
//CStudent *p=new CStudent
//CStudent* p=new CStudent(manager.GetStudent(m_dialog1_number));
UpdateData(TRUE);
manager.GetStudentIP(m_dialog1_number)->RevisePassword(m_dialog1_newpassword);
MessageBox("修改密码成功!");
UpdateData(FALSE);
//MessageBox(m_dialog1_newpassword);
}
void Dialog1::OnDialog1ElectCourse()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CStudent* p=new CStudent(manager.GetStudent(m_dialog1_number));
if(m_dialog1_all==0)
{
MessageBox("显示全部成绩,绩点,平均分!");
//显示全部成绩,绩点,平均分
// p->ShowAllSubject_Grade();
// m_dialog1_GPA=100;
//m_dialog1_average=50;
//fstream f1;
// f1.open("calculation of all GPA.dat",ios::in|ios::binary);
// char bufread[60];
// while(!f1.eof())
// {
// f1.read((char *)&bufread,13*sizeof(int));
// strcat(p->GetBuf_allIP(),bufread);
// }
// m_dialog1_show=p->GetBuf_allIP();
fstream f1;
f1.open(p->all_all,ios::in|ios::binary);
if(f1.fail())
{
MessageBox("打开文件失败!");
//cout<<"打开文件失败!"<<endl;
}else
{
char bufread[52];
f1.read((char *)&bufread,13*sizeof(int));//先要读一遍
//cout<<"bufread="<<bufread<<endl;
strcpy(p->buf_all,bufread);
while((f1.read((char *)&bufread,13*sizeof(int)))&&(!f1.eof()))
{
//f1.read((char *)&bufread,13*sizeof(int));
//cout<<"bufread"<<bufread<<endl;
strcat(p->buf_all,bufread);
}
//cout<<"显示全部成绩,学科名:"<<p->buf_all<<endl;
m_dialog1_show=p->buf_all;
// p->CalculateAllGPA();
// p->CalculateAllAverage();
f1.close();
}
p->CalculateAllGPA();
p->CalculateAllAverage();
// cout<<"All the average grade is:"<<p->GetAllAverage()<<endl;
// cout<<"All the GPA is:"<<p->GetAllGPA()<<endl;
m_dialog1_GPA=p->GetAllGPA();
m_dialog1_average=p->GetAllAverage();
//GetDlgItem(IDC_DIALOG1_GPA)->SetWindowText(m_dialog1_GPA);
//GetDlgItem(IDC_DIALOG1_AVERAGE)->SetWindowText(m_dialog1_average);
}else if(m_dialog1_all==1)
{
//显示必修科目的成绩,绩点,平均分!
MessageBox("显示必修科目的成绩,绩点,平均分!");
//p->ShowComplusorySubject_Grade();
p->CalculateCompulsoryAverage();
p->CalculateCompulsoryGPA();
// cout<<"average grade of the complusory grade is:"<<p->GetComplusoryAverage()<<endl;
//cout<<"average grade of the complusory GPA is:"<<p->GetComplusoryGPA()<<endl;
m_dialog1_GPA=p->GetComplusoryGPA();
m_dialog1_average=p->GetComplusoryAverage();
fstream f2;
f2.open(p->all_compulsory,ios::in|ios::binary);
if(f2.fail())
{
MessageBox("打开文件失败");
//cout<<"打开文件失败!"<<endl;
exit(5);
}else
{
char bufread2[52];
f2.read((char *)&bufread2,13*sizeof(int));
//cout<<"bufread2:"<<bufread2<<endl;//先要读一遍
strcpy(p->buf_compulsory,bufread2);
while(f2.read((char *)&bufread2,13*sizeof(int))&&!f2.eof())
{
//cout<<"bufread:"<<bufread<<endl;
strcat(p->buf_compulsory,bufread2);
}
//cout<<"显示选修的成绩,学科名:"<<p->buf_compulsory<<endl;
m_dialog1_show=p->buf_compulsory;
f2.close();
// p->CalculateAllGPA();
// p->CalculateAllAverage();
}
}
UpdateData(FALSE);
delete p;
//UpdateData(FALSE);
}
void Dialog1::OnDialog1All()
{
// TODO: Add your control notification handler code here
m_dialog1_all=0;
}
void Dialog1::OnDialog1Compulsory()
{
// TODO: Add your control notification handler code here
m_dialog1_all=1;
}
void Dialog1::OnDialog1ShowPassword()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_dialog1_password=m_dialog1_newpassword;
MessageBox("显示密码!");
UpdateData(FALSE);
}
#if !defined(AFX_DIALOG2_H__E13B2620_D0E3_4E25_9901_D498EB61FB25__INCLUDED_)//Dialog2.h
#define AFX_DIALOG2_H__E13B2620_D0E3_4E25_9901_D498EB61FB25__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Dialog2.h : header file
//
/
// Dialog2 dialog
class Dialog2 : public CDialog
{
// Construction
public:
Dialog2(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(Dialog2)
enum { IDD = IDD_DIALOG2 };
int m_dialog2_compulsory;
float m_dialog2_grade;
CString m_dialog2_name;
long m_dialog2_number;
CString m_dialog2_sex;
CString m_dialog2_subject;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(Dialog2)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(Dialog2)
afx_msg void OnDialog2BuildStudent();
afx_msg void OnDialog2Exit();
afx_msg void OnDialog2EnterGrade();
afx_msg void OnDialogCompulsory();
afx_msg void OnDialog2Elective();
afx_msg void OnDialog2Return();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DIALOG2_H__E13B2620_D0E3_4E25_9901_D498EB61FB25__INCLUDED_)
// Dialog2.cpp : implementation file
//
#include "stdafx.h"
#include "绩点计算器3.h"
#include "Dialog2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CManager manager;
/
// Dialog2 dialog
Dialog2::Dialog2(CWnd* pParent /*=NULL*/)
: CDialog(Dialog2::IDD, pParent)
{
//{{AFX_DATA_INIT(Dialog2)
m_dialog2_compulsory = -1;
m_dialog2_grade = 0.0f;
m_dialog2_name = _T("");
m_dialog2_number = 0;
m_dialog2_sex = _T("");
m_dialog2_subject = _T("");
//}}AFX_DATA_INIT
}
void Dialog2::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Dialog2)
DDX_Radio(pDX, IDC_DIALOG_COMPULSORY, m_dialog2_compulsory);
DDX_Text(pDX, IDC_DIALOG2_GRADE, m_dialog2_grade);
DDX_Text(pDX, IDC_DIALOG2_NAME, m_dialog2_name);
DDX_Text(pDX, IDC_DIALOG2_NUMBER, m_dialog2_number);
DDX_Text(pDX, IDC_DIALOG2_SEX, m_dialog2_sex);
DDX_Text(pDX, IDC_DIALOG2_SUBJECT, m_dialog2_subject);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Dialog2, CDialog)
//{{AFX_MSG_MAP(Dialog2)
ON_BN_CLICKED(IDC_DIALOG2_BUILD_STUDENT, OnDialog2BuildStudent)
ON_BN_CLICKED(IDC_DIALOG2_EXIT, OnDialog2Exit)
ON_BN_CLICKED(IDC_DIALOG2_ENTER_GRADE, OnDialog2EnterGrade)
ON_BN_CLICKED(IDC_DIALOG_COMPULSORY, OnDialogCompulsory)
ON_BN_CLICKED(IDC_DIALOG2_ELECTIVE, OnDialog2Elective)
ON_BN_CLICKED(IDC_DIALOG2_RETURN, OnDialog2Return)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// Dialog2 message handlers
void Dialog2::OnDialog2BuildStudent()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
manager.BuildStudent(m_dialog2_name,m_dialog2_sex);
MessageBox("创建成功!");
UpdateData(FALSE);
}
void Dialog2::OnDialog2Exit()
{
// TODO: Add your control notification handler code here
CDialog::OnOK();
}
void Dialog2::OnDialog2EnterGrade()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
/*fstream f;
f.out("calculation of GPA",ios::out|ios::binary);
if(f.fail())
{
MessageBox("打开文件失败!");
exit(0);
}else
f.close();
f.open("calculaotion of GPA",ios::in|ios::binary);
if(f.fail())
{
MessageBox("打开文件失败!");
exit(1);
}else
{
sprintf(buf,%10s%12s,"subject:",m_dialog2_subject,"grade");
}*/
manager.InputStudentGrade(m_dialog2_grade,m_dialog2_subject,m_dialog2_number,m_dialog2_compulsory);
MessageBox("录入成功!");
UpdateData(FALSE);
}
void Dialog2::OnDialogCompulsory()
{
// TODO: Add your control notification handler code here
m_dialog2_compulsory=0;
}
void Dialog2::OnDialog2Elective()
{
// TODO: Add your control notification handler code here
m_dialog2_compulsory=1;
}
void Dialog2::OnDialog2Return()
{
// TODO: Add your control notification handler code here
CDialog::OnOK();
}
// 绩点计算器3Dlg.h : header file
//
#if !defined(AFX_3DLG_H__5C2F5BAE_8B72_4058_95A4_C86AC3435261__INCLUDED_)
#define AFX_3DLG_H__5C2F5BAE_8B72_4058_95A4_C86AC3435261__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/
// CMy3Dlg dialog
class CMy3Dlg : public CDialog
{
// Construction
public:
CMy3Dlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CMy3Dlg)
enum { IDD = IDD_MY3_DIALOG };
long m_dialog3_number;
CString m_dialog3_account;
CString m_dialog3_account_password;
CString m_dialog3_number_password;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMy3Dlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CMy3Dlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnDialog3ManagerEnter();
afx_msg void OnDialog3StudentEnter();
afx_msg void OnDialog3Exit();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_3DLG_H__5C2F5BAE_8B72_4058_95A4_C86AC3435261__INCLUDED_)
// 绩点计算器3Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "绩点计算器3.h"
#include "绩点计算器3Dlg.h"
#include "Dialog1.h"
#include "Dialog2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CManager manager;
/
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CMy3Dlg dialog
CMy3Dlg::CMy3Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy3Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy3Dlg)
m_dialog3_number = 0;
m_dialog3_account = _T("");
m_dialog3_account_password = _T("");
m_dialog3_number_password = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy3Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMy3Dlg)
DDX_Text(pDX, IDC_DIALOG3_NUMBER, m_dialog3_number);
DDX_Text(pDX, IDC_DIALOG3_ACCOUNT, m_dialog3_account);
DDX_Text(pDX, IDC_DIALOG3_MANAGER_PASSWORD, m_dialog3_account_password);
DDX_Text(pDX, IDC_DIALOG3_STUDENT_PASSWORD, m_dialog3_number_password);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy3Dlg, CDialog)
//{{AFX_MSG_MAP(CMy3Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_DIALOG3_MANAGER_ENTER, OnDialog3ManagerEnter)
ON_BN_CLICKED(IDC_DIALOG3_STUDENT_ENTER, OnDialog3StudentEnter)
ON_BN_CLICKED(IDC_DIALOG3_EXIT, OnDialog3Exit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CMy3Dlg message handlers
BOOL CMy3Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMy3Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMy3Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMy3Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy3Dlg::OnDialog3ManagerEnter()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
//CManager manager;
CString managerAccount="woshimanager";//进入管理者的界面
CString managerAccountPassword="woshimanager";
// CString dialog1_account;
// CString dialog1_account_password;
// dialog1_account=strMfc.Get
if(m_dialog3_account.Compare(managerAccount)==0&&m_dialog3_account_password.Compare(managerAccountPassword)==0)
{
MessageBox("登录成功!");
this->ShowWindow(SW_HIDE);
Dialog2 dlg;
dlg.DoModal();
this->ShowWindow(SW_SHOW);
}
else if(m_dialog3_account.Compare(managerAccount)!=0)
{
MessageBox("账号不存在!");
}else
{
MessageBox("密码错误!");
}
/*MessageBox("登录成功!");
this->ShowWindow(SW_HIDE);
Dialog2 dlg;
dlg.DoModal();
this->ShowWindow(SW_SHOW);*/
//MessageBox("账号不存在!");
UpdateData(false);
}
void CMy3Dlg::OnDialog3StudentEnter()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CStudent* p=new CStudent(manager.GetStudent(m_dialog3_number));
if(p->GetStudentPassword().Compare(m_dialog3_number_password)==0)
{
MessageBox("成功登录!");
this->ShowWindow(SW_HIDE);
Dialog1 dlg;
dlg.m_dialog1_name=p->GetStudentName();
dlg.m_dialog1_number=p->GetStudentNumber();
dlg.DoModal();
this->ShowWindow(SW_SHOW);
//cout<<"succeed to enter the student's window."<<endl;
//cout<<"the name of the student is:"<<p->GetStudentName()<<endl;
}else
{
MessageBox("登录失败!");
}
delete p;
UpdateData(FALSE);
}
void CMy3Dlg::OnDialog3Exit()
{
// TODO: Add your control notification handler code here
CDialog::OnOK();
}