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

📄 myplan.cpp

📁 用VC++实现的关于会议室使用计划 例程解析!
💻 CPP
字号:
// Myplan.cpp: implementation of the Myplan class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Mplan.h"
#include "Myplan.h"
#include "OutFile.h"
#include "InFile.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Myplan::Myplan()
{

}

//Myplan::~Myplan()
//{

//}
Myplan::Myplan(char n[]){
	strcpy(name,n);
	for(int i=0;i<7;i++)
		plans[i] = new Mlist();
}
Myplan::~Myplan(){
	while(rooms.GetCount()>0)
		delete rooms.RemoveHead();
	while(allplans.GetCount()>0)
		delete allplans.RemoveHead();
	for (int i=0;i<7;i++)
		delete plans[i];
}
void Myplan::AddRoom(Room *p){
//	p->setRoomInfo(char *rno,int *per);
	rooms.AddTail(p);	
}
void Myplan::AddPlan(int date,Plan *p){
	//
	plans[date]->AddTail(p);
	if(allplans.Find(p) == NULL)
		allplans.AddTail(p);
}
Mlist *Myplan::Roomlist(int date,CString per){
	Mlist *rom=rooms.Roomlist(per);
	POSITION pos = plans[date]->GetHeadPosition();
	POSITION pos2 = rom->GetHeadPosition();
	while(pos){
		Plan *p = (Plan *)plans[date]->GetNext(pos);
		CString rno;	
		p->getRoomno(rno);
		while(pos2){
			POSITION pos3 = pos2;
			Room *p = (Room *)rom->GetNext(pos2);
			CString rno1;
			CString person;
			p->getRoomInfo(rno1,person);
			if(rno==rno1)
				rom->RemoveAt(pos3);
			}
	}
	return rom;
}
Mlist *Myplan::Planlist(int date,CString rno){
	return plans[date]->Planlist(rno);
}
Mlist *Myplan::AllRoomlist(){
	return rooms.Roomlist("0");
}
Mlist *Myplan::AllPlanlist(){
	Mlist *list = new Mlist();
	POSITION pos = allplans.GetHeadPosition();
	while(pos){
		Plan *p = (Plan *)allplans.GetNext(pos);
		list->AddTail(p);
	}
	return list;
}
//////////////////////////////////////////////////////////////////////
// Plan Class
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Plan::Plan()
{

}

Plan::~Plan()
{

}
Plan::Plan(CString cd){
	code=cd;
}
CString Plan::getCode(){
	return code;
}
void Plan::setDate(int dat){
	date=dat;
}
void Plan::setName(CString nam){
	name=nam;
}
void Plan::setPersnum(CString pern){
	persnum=pern;
}
void Plan::setRoomno(CString rno){
	roomno=rno;
}
void Plan::setTime(int st,int ed){
	start=st;end=ed;
}
void Plan::modifyPlan(Plan *p,int dat,CString nam,CString pern,CString rno,int st,int ed){
	p->setDate(dat);
	p->setName(nam);
	p->setPersnum(pern);
	p->setRoomno(rno);
	p->setTime(st,ed);	
}
void Plan::getDate(int &dat){
	dat=date;
}
void Plan::getName(CString &nam){
	nam=name;
}
void Plan::getPersnum(CString &pern){
	pern=persnum;
}
void Plan::getRoomno(CString &rno){
	rno=roomno;
}
void Plan::getTime(int &st,int &ed){
	st=start;ed=end;
}
//////////////////////////////////////////////////////////////////////
// Mlist Class
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Mlist::Mlist()
{

}

Mlist::~Mlist()
{

}
Mlist *Mlist::Roomlist(CString per){
	Mlist *list = new Mlist();
	int i,j;
	POSITION pos = this->GetHeadPosition();
	while(pos){
		Room *p = (Room *)this->GetNext(pos);
		CString rno;
		CString person;
		p->getRoomInfo(rno,person);
		i=atoi((char*)(LPCTSTR)person); 
		j=atoi((char*)(LPCTSTR)per); 
		if(i>=j)
			list->AddTail(p);
	}
	return list;
}

Mlist *Mlist::Planlist(CString rno){
	Mlist *list = new Mlist();
	POSITION pos = GetHeadPosition();
	while(pos){
		Plan *p = (Plan *)GetNext(pos);
		CString roomno;
		p->getRoomno(roomno);
		if(strcmp(roomno,rno)==0)
			list->AddTail(p);
	}
	return list;
}
//////////////////////////////////////////////////////////////////////
// Room Class
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Room::Room()
{

}

Room::~Room()
{

}
Room::Room(CString rno){
	roomno=rno;
}
void Room::setRoomInfo(CString rno,CString per){
	roomno=rno;
	persons=per;
}

void Room::getRoomInfo(CString &rno,CString &per){
	rno=roomno;
	per=persons;
}

void Myplan::SaveRoomInfo()
{	
	OutFile  file;	//  文件
	file.Open("roominfo.txt");
	file.Write("roomno");
	file.Write("limitpnum");
	file.Write("\n");
	POSITION pos=rooms.GetHeadPosition();
	while(pos){
		Room *p = (Room *)rooms.GetNext(pos);
		CString rno;
		CString person;
		int i,j;
		p->getRoomInfo(rno,person);
		i=atoi((char*)(LPCTSTR)rno); 
		j=atoi((char*)(LPCTSTR)person); 
		file.Write(i);
		file.Write(j);
		file.Write("\n");
	}
	file.Write(9999);
	file.Close();
}

void Myplan::SavePlanInfo()
{
	OutFile  file;	//  文件
	file.Open("planinfo.txt");
	file.Write("plancd");
	file.Write("date");
	file.Write("pernum");
	file.Write("roomno");
	file.Write("startime");
	file.Write("endtime");
	file.Write("name");
	file.Write("\n");
	POSITION pos=allplans.GetHeadPosition();
	while(pos){
		Plan *p = (Plan *)allplans.GetNext(pos);
		CString plancode;
		int dat;
		CString nam;
		CString pern;
		CString rno;
		int st,ed;
		plancode=p->getCode();
		p->getDate(dat);
		p->getName(nam);
		p->getPersnum(pern);
		p->getRoomno(rno);
		p->getTime(st,ed);	
		
		int icode,jper,mrno;
		icode=atoi((char*)(LPCTSTR)plancode); 
		jper=atoi((char*)(LPCTSTR)pern);
		mrno=atoi((char*)(LPCTSTR)rno);
		char *name=(char*)(LPCTSTR)nam;
		file.Write(icode);
		file.Write(dat);
		file.Write(jper);
		file.Write(mrno);
		file.Write(st);
		file.Write(ed);
		file.Write(name);
		file.Write("\n");
	}
	file.Write(9999);
	file.Close();
}

void Myplan::ReadRoomInfo()
{
	InFile  file;	//  文件
	file.Open("roominfo.txt");
	char roomno[64],lpersnum[64];
	int rno,lpnum;
	file.Read(roomno);
	file.Read(lpersnum);
	while(1){
		file.Read(rno);
		if( rno == 9999)	break;
		file.Read(lpnum);
		CString rno2,lpnum2;
		rno2.Format("%d",rno);//int->CString
		lpnum2.Format("%d",lpnum);
		Room *p = new Room();
		p->setRoomInfo(rno2,lpnum2);
		rooms.AddTail(p);
	}
	file.Close();
}

void Myplan::ReadPlanInfo()
{
	InFile  file;	//  文件
	file.Open("planinfo.txt");
	char plancd[64],date[64],pernum[64],roomno[64],statime[64],entime[64],name[64];
	file.Read(plancd);
	file.Read(date);
	file.Read(pernum);
	file.Read(roomno);
	file.Read(statime);
	file.Read(entime);
	file.Read(name);
	int dat,st,ed,plcd,pern,rno;
	char nam[64];
	while(1){
		file.Read(plcd);
		if( plcd == 9999)	break;
		file.Read(dat);
		file.Read(pern);
		file.Read(rno);
		file.Read(st);
		file.Read(ed);
		file.Read(nam);
		CString plcd2,rno2,pern2,nam2;
		plcd2.Format("%d",plcd);
		rno2.Format("%d",rno);//int->CString
		pern2.Format("%d",pern);
		nam2=nam;
		Plan *p = new Plan(plcd2);
		p->setDate(dat);
		p->setName(nam);
		p->setPersnum(pern2);
		p->setRoomno(rno2);
		p->setTime(st,ed);
		allplans.AddTail(p);
	}
	file.Close();
}

⌨️ 快捷键说明

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