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

📄 diaodudlg.cpp

📁 主要使用了时间片轮转算法和高响应比算法模拟进程的调度过程
💻 CPP
字号:
// diaoduDlg.cpp : implementation file
//

#include "stdafx.h"
#include "diaodu.h"
#include "diaoduDlg.h"
#include<math.h>
#include<iostream.h>
#include <stdio.h> 
#include <stdlib.h> 
#include <time.h>
#include<string.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString str,str1,str2;
int sum=0;
int m=0,m1=0,m2=0,m3=0;
int front=0,front2=0,front3=0,frontt;
int end;
int time1;
int i;
int front1=0;
	int fu[4];
	int k[4];
	int num=3;
	int max=0;
	int a,a1,a2;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CDiaoduDlg dialog

CDiaoduDlg::CDiaoduDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDiaoduDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDiaoduDlg)
	m_edit1 = _T("");
	m_edit4 = 0;
	m_edit6 = 0;
	m_edit8 = 0;
	m_edit10 = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	n=0;n1=0;n2=0;n3=0;
    nn=0;nn1=0;nn2=0;nn3=0;
	dui[0]=1;
	dui[1]=2;
	dui[2]=3;
	dui[3]=4;
	end=3;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDiaoduDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDiaoduDlg)
	DDX_Control(pDX, IDC_PROGRESS4, m_progress4);
	DDX_Control(pDX, IDC_PROGRESS3, m_progress3);
	DDX_Control(pDX, IDC_PROGRESS2, m_progress2);
	DDX_Control(pDX, IDC_PROGRESS1, m_progress1);
	DDX_Control(pDX, IDC_COMBO2, m_combo2);
	DDX_Text(pDX, IDC_EDIT1, m_edit1);
	DDX_Text(pDX, IDC_EDIT4, m_edit4);
	DDX_Text(pDX, IDC_EDIT6, m_edit6);
	DDX_Text(pDX, IDC_EDIT8, m_edit8);
	DDX_Text(pDX, IDC_EDIT10, m_edit10);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDiaoduDlg, CDialog)
	//{{AFX_MSG_MAP(CDiaoduDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDiaoduDlg message handlers

BOOL CDiaoduDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.
    
     m_combo2.SetCurSel(3);
	m_progress1.SetRange(0,500);
	 m_progress2.SetRange(0,475);
	 m_progress3.SetRange(0,515);
	 m_progress4.SetRange(0,480);
	 m_progress1.SetPos(0);
     m_progress2.SetPos(0);
	 m_progress3.SetPos(0);
	 m_progress4.SetPos(0);

	// 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 CDiaoduDlg::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 CDiaoduDlg::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 CDiaoduDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDiaoduDlg::OnTimer(UINT nIDEvent)   
{
	// TODO: Add your message handler code here and/or call default

	sum++;
	front=front1;  
	    UpdateData(true);
	    
	    m_edit1.Format("%d",dui[front]);
		m_edit4=(m_progress1.GetPos()/500.0)*100;
		m_edit6=(m_progress2.GetPos()/475.0)*100;
		m_edit8=(m_progress3.GetPos()/515.0)*100;
		m_edit10=(m_progress4.GetPos()/480.0)*100;
		UpdateData(false);
	  if(sum==time1)
	  {
		  if(dui[front]==1)
		  {
			  if(m!=1)
			  {
				  end++;
			      dui[end]=dui[front];
			      front1++;

			  }
			  else
			  {
				  front1++;
			  }
		  }
		  if(dui[front]==2)
		  {
			  if(m1!=1)
			  {
			    end++;
		        dui[end]=2;
			    front1++;
			  }
		      else
			  {
			     front1++;
			  }		  
		  }
		  if(dui[front]==3)
		  {
              if(m2!=1)
		  {
			  end++;
		      dui[end]=3;
			  front1++;
		  }
		  else
		  {
			  front1++;
		  }		  
		  }
		  if(dui[front]==4)
		  {
              if(m3!=1)
		  {
			  end++;
		      dui[end]=4;
			  front1++;
		  }
		  else
		  {
			  front1++;
		  }		  
		  }
		  sum=0;
		  front=-1;
	  }
	  if(dui[front]==1)
	  {
		  if(m==0)
		  {
		  n=n+20;
		  m_progress1.SetPos(n);
		  
		  if(n>500)
		  {
			  m=1;
		  }

		  }
	
        //  CDialog::OnTimer(nIDEvent);
	  }
	  if(dui[front]==2)
	  {
		 if(m1==0)
		  {n1=n1+20;
		  m_progress2.SetPos(n1);
		  
		  if(n1>475)
		  {
			  m1=1;
		  }

		  }
		  
         // CDialog::OnTimer(nIDEvent); 
	  }
       if(dui[front]==3)
	  {
		 if(m2==0)
		  {n2=n2+20;
		  m_progress3.SetPos(n2);
		  
		  if(n2>515)
		  {
			  m2=1;
		  }

		  }
		  
          //CDialog::OnTimer(nIDEvent); 
	  }
	    if(dui[front]==4)
	  {
		 if(m3==0)
		  {n3=n3+20;
		  m_progress4.SetPos(n3);
		  
		  if(n3>475)
		  {
			  m3=1;
		  }

		  }
		  
	  }

	CDialog::OnTimer(nIDEvent);
}

void CDiaoduDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	SetTimer(0,400,NULL);
	
	UpdateData(true);
	
    if(m_combo2.GetCurSel()==0)
	{
		time1=10;
	}
	if(m_combo2.GetCurSel()==1)
	{
		time1=15;
	}
	if(m_combo2.GetCurSel()==2)
	{
		time1=20;
	}
	if(m_combo2.GetCurSel()==3)
	{
		time1=5;
	}
   UpdateData(false);

}


void CDiaoduDlg::OnButton5() 
{
	OnOK();
}




⌨️ 快捷键说明

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