#include <math.h>
#include "Windw.h"
#define MAX 100
#define SIZE 50
class PCB
{
private :
int ID;
int Size;
int Ts;
int Flag;
public :
PCB()
{
ID=0;
Size=0;
Ts=0;
Flag=0;
}
void SetID(int I){ID=I;}
void SetMFlag(){Flag=1;}
void SetDFlag(){Flag=0;}
void SetSizeTs(void)
{
int number;
randomize();
number=rand()%4;
Size=ldexp(2,number-1);
Ts=(number+1)*5;
}
int GetFlag(void) {return Flag;}
int GetID(void){return ID;}
int GetSize(void){return Size;}
int GetTs(void){return Ts;}
};
class Rectangle
{
friend class Grid;
private :
int left,top,right,bottom;
char content[SIZE];
public :
void Outtextxy(char text[SIZE])
{
strcpy(content,text);
outtextxy(left+9,top+7,content);
}
void Fill(int Number)
{
setfillstyle(SOLID_FILL,Number);
bar3d(left+1,top+1,right-1,bottom-1,0,0);
}
void Test(int Temp,int Interval)
{
if (Temp==0) outtextxy(left+45+Interval,top+7,"0");
if (Temp==1) outtextxy(left+45+Interval,top+7,"1");
if (Temp==2) outtextxy(left+45+Interval,top+7,"2");
if (Temp==3) outtextxy(left+45+Interval,top+7,"3");
if (Temp==4) outtextxy(left+45+Interval,top+7,"4");
if (Temp==5) outtextxy(left+45+Interval,top+7,"5");
if (Temp==6) outtextxy(left+45+Interval,top+7,"6");
if (Temp==7) outtextxy(left+45+Interval,top+7,"7");
if (Temp==8) outtextxy(left+45+Interval,top+7,"8");
if (Temp==9) outtextxy(left+45+Interval,top+7,"9");
}
void Display(int number)
{
int Temp=number;
if ((Temp>=0) && (Temp<=9)) Test(Temp,0);
if ((Temp>=10) && (Temp<=99))
{
Temp=int (Temp/10);
Test(Temp,0);
Temp=number-Temp*10;
Test(Temp,5);
}
}
};
class Grid
{
private :
Rectangle *Array[MAX];
public :
Grid(){};
void NewRectangle(int number,int a,int b,int c,int d)
{
Rectangle *Newrect;
Newrect=new Rectangle;
Newrect->left=a;
Newrect->top=b;
Newrect->right=c;
Newrect->bottom=d;
rectangle(a,b,c,d);
Array[number]=Newrect;
}
Rectangle *GetRectangle(int number) {return Array[number];}
};
void Exit(void);
void Version(void);
void Running(void);
void InitGrid(void);
void InitGraph(void);
void InitRecord(void);
void Allocation(void);
void Compact(int number);
int Returncolor(int number);
Grid Record,Graph;
PCB MEMORY[MAX];
PCB HARDDISK[MAX];
int Screen[MAX];
int CurrentMIDM=0,CurrentMIDD=0,CurrentMMp=0,CurrentMDp=0;
int LeftSpace=SIZE,LeftD=SIZE,CurrentEIDM,CurrentEIDD;
int main()
{
int i;
InitGraph();
InitRecord();
InitGrid();
EventMsg eventMsg;
mouse.SetLimits(0,getmaxx(),0,getmaxy());
mouse.ShowMouse();
Button wndw1(220,360,"^OK");
Button wndw2(300,360,"^CANCEL");
wndw1.DrawWindow();
wndw2.DrawWindow();
int button=0;
while (!button)
{
GetEvent(eventMsg);
if (wndw1.Clicked(eventMsg)) Allocation();
if (wndw2.Clicked(eventMsg)) button=CANCEL;
else if (!wndw1.Clicked(eventMsg)&&!wndw2.Clicked(eventMsg))
Running();
}
Exit();
return 0;
}
void Exit(void)
{
mouse.HideMouse();
Version();
getch();
closegraph();
exit(1);
}
void InitGraph(void)
{
int Gdriver=DETECT,Gmode,Errorcode;
initgraph(&Gdriver,&Gmode,"D:\\Tools\\Tc3.0\\Bgi");
Errorcode=graphresult();
if (Errorcode!=grOk)
{
printf("Graphics Error: %s\n",grapherrormsg(Errorcode));
printf("Press any key to exit & Change the dictory :");
getch();
exit(1);
}
}
void InitRecord(void)
{
int number=0,circle,i;
for (i=0;i<5;i++)
{
for (circle=0;circle<6;circle++)
{
Record.NewRectangle(number,15+circle*100,20+i*20,
circle*100+115,20+((i+1)*20));
number=number+1;
}
}
setcolor(14);
Record.GetRectangle(0)->Outtextxy(" SIZE ");
Record.GetRectangle(1)->Outtextxy(" INTERVAL ");
Record.GetRectangle(2)->Outtextxy(" TOTAL ");
Record.GetRectangle(3)->Outtextxy(" READY ");
Record.GetRectangle(4)->Outtextxy(" RUNNING ");
Record.GetRectangle(5)->Outtextxy(" COLOR ");
setcolor(12);
Record.GetRectangle(6)->Outtextxy(" 1M ");
Record.GetRectangle(12)->Outtextxy(" 2M ");
Record.GetRectangle(18)->Outtextxy(" 4M ");
Record.GetRectangle(24)->Outtextxy(" 8M ");
for (i=7,circle=0;i<=25,circle<4;i=i+6,circle++)
Record.GetRectangle(i)->Display(i-circle-2);
setcolor(15);
for (i=8,circle=0;i<=26,circle<4;i=i+6,circle++)
Record.GetRectangle(i)->Outtextxy(" Random ");
for (i=9,circle=0;i<=27,circle<4;i=i+6,circle++)
Record.GetRectangle(i)->Outtextxy(" Random ");
for (i=10,circle=0;i<=28,circle<4;i=i+6,circle++)
Record.GetRectangle(i)->Outtextxy(" Random ");
setcolor(12);
Record.GetRectangle(11)->Outtextxy(" RED ");
setcolor(9);
Record.GetRectangle(17)->Outtextxy(" BLUE ");
setcolor(10);
Record.GetRectangle(23)->Outtextxy(" GREEN ");
setcolor(14);
Record.GetRectangle(29)->Outtextxy(" YELLOW ");
}
void InitGrid(void)
{
int number=0,circle=0;
setcolor(11);
outtextxy(130,150,"***** The FIFO Method of Memory Distribute *****");
line(15,180,625,180);
line(15,340,625,340);
setcolor(13);
for (circle=0;circle<50;circle++)
{
Graph.NewRectangle(number,110+circle*10,230,circle*10+120,240);
number=number+1;
}
for (circle=0;circle<50;circle++)
{
Graph.NewRectangle(number,110+circle*10,300,circle*10+120,310);
number=number+1;
}
setcolor(14);
outtextxy(20,210,"Main Memory");
outtextxy(20,280,"Hard Disk");
}
int Returncolor(int number)
{
if (number==1) return 12;
if (number==2) return 9;
if (number==4) return 10;
if (number==8) return 14;
else return 0;
}
void Allocation(void)
{
PCB NewNode;
int color,circle;
NewNode.SetSizeTs();
if(HARDDISK[CurrentEIDD].GetSize()==0
&&CurrentMMp+NewNode.GetSize()<=SIZE)
{
NewNode.SetID(CurrentMIDM);
NewNode.SetMFlag();
color=Returncolor(NewNode.GetSize());
for (circle=CurrentMMp;circle<CurrentMMp+NewNode.GetSize();circle++)
{
Graph.GetRectangle(circle)->Fill(color);
Screen[circle]=color;
}
MEMORY[CurrentMIDM]=NewNode;
CurrentMIDM=CurrentMIDM+1;
CurrentMMp=CurrentMMp+NewNode.GetSize();
LeftSpace=LeftSpace-NewNode.GetSize();
}
else
{
NewNode.SetID(CurrentMIDD);
NewNode.SetDFlag();
color=Returncolor(NewNode.GetSize());
for (circle=CurrentMDp;circle<CurrentMDp+NewNode.GetSize();circle++)
{
Graph.GetRectangle(circle+SIZE)->Fill(color);
Screen[circle+SIZE]=color;
}
HARDDISK[CurrentMIDD]=NewNode;
CurrentMIDD=CurrentMIDD+1;
CurrentMDp=CurrentMDp+NewNode.GetSize();
LeftD=LeftD-NewNode.GetSize();
}
}
void Running(void)
{
int circle=0;
PCB TempNode;
TempNode=MEMORY[CurrentEIDM];
if(LeftSpace<50)
{
for (circle=0;circle<TempNode.GetSize();circle++)
{
delay(MAX);
Graph.GetRectangle(circle)->Fill(0);
Screen[circle]=0;
}
if (HARDDISK[CurrentEIDD].GetSize()==0)
{
CurrentMMp=CurrentMMp-TempNode.GetSize();
LeftSpace=LeftSpace+TempNode.GetSize();
Compact(1);
}
else Compact(2);
CurrentEIDM=CurrentEIDM+1;
}
}
void Compact(int number)
{
int i=0,circle=0,TempID,j;
if (number==1)
{
while ((Screen[i]==0) && (i<SIZE)) i=i+1;
if (i>0)
{
for (circle=0;circle<MAX-i;circle++)
Screen[circle]=Screen[circle+i];
for (circle=MAX-i;circle<MAX;circle++) Screen[circle]=0;
for (circle=0;circle<MAX;circle++)
Graph.GetRectangle(circle)->Fill(Screen[circle]);
}
}
if (number==2)
{
while ((Screen[i]==0) && (i<SIZE)) i=i+1;
if (i>0)
{
for (circle=0;circle<SIZE-i;circle++)
Screen[circle]=Screen[circle+i];
for (circle=SIZE-i;circle<SIZE;circle++) Screen[circle]=0;
CurrentMMp=CurrentMMp-i;
LeftSpace+=i;
TempID=CurrentEIDD;
while(HARDDISK[TempID].GetSiz
没有合适的资源?快使用搜索试试~ 我知道了~
C++编程实例100篇
共552个文件
cpp:107个
bmp:106个
obj:106个
5星 · 超过95%的资源 需积分: 9 2.7k 下载量 184 浏览量
2011-07-09
23:11:28
上传
评论 27
收藏 2.49MB RAR 举报
温馨提示
C++编程实例100篇C++编程实例100篇C++编程实例100篇C++编程实例100篇
资源推荐
资源详情
资源评论
收起资源包目录
C++编程实例100篇 (552个子文件)
EGAVGA.BGI 5KB
EGAVGA.BGI 5KB
EGAVGA.BGI 5KB
EGAVGA.BGI 5KB
EGAVGA.BGI 5KB
EGAVGA.BGI 5KB
65.BMP 902KB
62.BMP 902KB
57A.BMP 902KB
77.BMP 902KB
57B.BMP 902KB
70.BMP 902KB
52.BMP 902KB
68.BMP 902KB
100.BMP 902KB
69.BMP 902KB
60.BMP 902KB
66.BMP 902KB
64.BMP 902KB
56B.BMP 902KB
63.BMP 902KB
56A.BMP 902KB
80.BMP 902KB
61.BMP 902KB
75.BMP 902KB
58A.BMP 902KB
58B.BMP 902KB
99.BMP 902KB
67.BMP 902KB
76.BMP 902KB
59.BMP 902KB
46.BMP 900KB
48.BMP 900KB
34.BMP 900KB
32.BMP 900KB
41.BMP 900KB
74.BMP 900KB
39.BMP 900KB
55.BMP 900KB
36.BMP 900KB
50.BMP 900KB
40.BMP 900KB
38.BMP 900KB
37.BMP 900KB
45.BMP 900KB
44.BMP 900KB
42.BMP 900KB
43.BMP 900KB
49.BMP 900KB
47.BMP 900KB
33.BMP 900KB
35.BMP 900KB
73.BMP 750KB
72.BMP 750KB
71.BMP 750KB
84.BMP 460KB
08.BMP 458KB
86.BMP 458KB
16.BMP 458KB
78.BMP 458KB
09.BMP 458KB
79.BMP 458KB
27.BMP 458KB
93.BMP 458KB
01.BMP 458KB
22.BMP 458KB
15.BMP 458KB
18.BMP 458KB
87.BMP 458KB
11.BMP 458KB
88.BMP 458KB
25.BMP 458KB
02.BMP 458KB
98.BMP 458KB
26.BMP 458KB
97.BMP 458KB
91.BMP 458KB
05.BMP 458KB
07.BMP 458KB
29.BMP 458KB
51.BMP 458KB
92.BMP 458KB
13.BMP 458KB
82.BMP 458KB
96.BMP 458KB
30.BMP 458KB
83.BMP 458KB
19.BMP 458KB
23.BMP 458KB
89.BMP 458KB
10.BMP 458KB
85.BMP 458KB
04.BMP 458KB
28.BMP 458KB
12.BMP 458KB
17.BMP 458KB
95B.BMP 458KB
90.BMP 458KB
95A.BMP 458KB
20.BMP 458KB
共 552 条
- 1
- 2
- 3
- 4
- 5
- 6
bi_longxin
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 实验二:IP协议分析.zip
- 驱动代码驱动代码驱动代码驱动代码
- SVID_20240523_141155_1.mp4
- Code for the complete guide to tkinter tutorial
- 关于百货中心供应链管理系统.zip
- SimpleFolderIcon-master 修改Unity的Project下的文件夹图标
- A python Tkinter widget to display tile based maps
- A pure Python library for adding tables to a Tkinter application
- Vector资源文件.zip
- MobaXterm-Installer
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页