заключение В рамках данного дипломного проекта была успешно разработана компьютерная система контроля знаний и навыков для проверки уровня подготовки студентов по теории сложности вычислительных процессов и структур.
Данный программный продукт обеспечивает значительную экономию времени преподавателя (за счет механизации проверки знаний) и студентов. Кроме этого в каждой контрольной предусмотрен режим обучения, работая в котором, студенты могут обучиться выполнению данной контрольной работы с разными начальными условиями, понять и усвоить алгоритм решения, а также ознакомиться с интерфейсом и логикой работы программы.
Система позволяет выполнять контрольные работы не только в пределах СибГУТИ, но и из любого удобного места - связь с удаленной БД осуществляется посредством сети Интернет, а в режиме обучения программа способна работать локально.
Данная программа была успешно протестирована студентами. В ходе тестирования и постоянной доработки с учетом отзывов студентов и преподавателя, программа обрела удобный и интуитивно понятный интерфейс, а также максимально объективные критерии оценивания.
ПРИЛОЖение А Исходный текст программ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Matrixx
{ public partial class MainController : Form
{
LoginForm LF; MatrixChainOrder app;
int MatrixCount = 5;
int time = 30*60000;
bool keymode;
int allowedErrors = 2;
public List> user_solution = new List>(); List u_sizes = new List();
List u_values = new List(); List> kp = new List>();
public MainController(LoginForm lf)
{
LF = lf;
InitializeComponent();
} public void GenerateData(int example, int size)
{
int i;
int p, j;
app = new MatrixChainOrder();
app.dataStore = new cDataStore(); Random r;
r = new Random();
int t = r.Next(2, 30); if (example == 1)
{
MatrixCount = 5;
app.dataStore.sizes.Clear();
app.dataStore.sizes.Add(10);
app.dataStore.sizes.Add(20);
app.dataStore.sizes.Add(5);
app.dataStore.sizes.Add(4);
app.dataStore.sizes.Add(30);
app.dataStore.sizes.Add(6);
}
else if (example == 2)
{
MatrixCount = 4;
app.dataStore.sizes.Clear();
app.dataStore.sizes.Add(10);
app.dataStore.sizes.Add(20);
app.dataStore.sizes.Add(50);
app.dataStore.sizes.Add(1);
app.dataStore.sizes.Add(100);
}
else
{ MatrixCount = size;
if (t >= 10) t = t / 5 * 5;
for (i = 0; i < MatrixCount + 1; i++)
{
//if (i > 1) l_Cond.Text += "; ";
//l_Cond.Text += "M" + i + " = " + "[" + t + " X "; t = r.Next(2, 30);
if (t >= 10) t = t / 5 * 5;
app.dataStore.sizes.Add(t);
//l_Cond.Text += t + "] ";
} } l_Cond.Text = "";
lSizes.Text = "";
for (i = 0; i < MatrixCount; i++)
{
if (i > 0) l_Cond.Text += "; ";
l_Cond.Text += "M" + i + " = " + "[" + app.dataStore.sizes[i] + " X " + app.dataStore.sizes[i+1] + "] ";
lSizes.Text += "r" + i + " = " + app.dataStore.sizes[i] + ((i < MatrixCount-1)?", ":"");
//t = r.Next(2, 30);
// if (t >= 10) t = t / 5 * 5;
//app.dataStore.sizes.Add(t);
} //int n = 5;
l_Matrix.Text = "";
//if (MatrixCount == 6) l_Matrix.Font = F; else l_Matrix.Font.Size = 12;
for (t = 0; t < MatrixCount; t++) //l
{
for (int k = 0; k < MatrixCount; k++) //i
{
if (k < t) continue;
l_Matrix.Text += "f(" + (t + 1) + "," + (k + 1) + ") ";
}
l_Matrix.Text += "\n";
} app.matrixChainOrder();
app.printOrder(0, MatrixCount-1);
int border = app.dataStore.tCount; for (t = 0; t < MatrixCount; t++) //l
for (int k = 0; k < MatrixCount - t; k++) //i
{
//p = k + t; //j
//string str = new string('a', 0);
//label24.Text += string.Format("f({0},{1})", k + 1, p + 1)+"=";
//label24.Text += app.dataStore.solution[0][string.Format("f({0},{1})", k + 1, p + 1)];
//label24.Text += "\n";
//dataStore.solution1.Add(string.Format("f(%d,%d)", k + 1, p + 1), str);
}
string sname = new string('a',0); for (i = 0; i < panel1.Controls.Count; i++)
{
if ( panel1.Controls[i] is Panel)
{
sname = panel1.Controls[i].Name.Substring(4);
if (int.Parse(sname) <= app.dataStore.tCount) panel1.Controls[i].Show();
else panel1.Controls[i].Hide();
//for (i = 0; i < tb.Name.Length; i++)
// {
// if (tb.Name[i] != 't') snum += tb.Name[i];
// }
}
}
}
private void light(int i, int j)
{
int u, t; for (u = 0; u < panel1.Controls.Count; u++)
{
if (panel1.Controls[u] is Panel)
{
for (t = 0; t < panel1.Controls[u].Controls.Count; t++)
{
if (panel1.Controls[u].Controls[t] is TextBox
&& panel1.Controls[u].Controls[t].Name == string.Format("tt{0}", kp[i][j].tbNum))
{ ((TextBox)panel1.Controls[u].Controls[t]).BackColor = Color.Red;
}
}
}
}
} private void CheckAnswer()
{
int p,j;
int i=1,u,t;
Control ct;
string tname, tsname;
double mark = 10.0;
double ers=0.0;
List errorsList = new List(); for (i = 0; i < MatrixCount; i++)
{
for (j = 0; j < MatrixCount; j++)
{
if (j if (kp[i][j].rightAnswer == false)
{
ers += 1.0;
light(i, j);
errorsList.Add(string.Format("Неверный ответ в ({0},{1})", i + 1, j + 1) + Environment.NewLine);
}
if (kp[i][j].errors[0] == 0 && kp[i][j].errors[1] == 0 && kp[i][j].errors[2] == 0 && i!=j)
{
ers+=1.0;;
light(i, j);
errorsList.Add(string.Format("Нет подробного решения в ({0},{1})", i + 1, j + 1) + Environment.NewLine);
}
// if (!doneMinCondition(i, j)) { ers += 1.0; ; light(i, j); }
for (int y = 0; y < app.dataStore.dCount-1; y++)
{
if (kp[i][j].errors[y] > 1)
{
ers += 0.5;
errorsList.Add(string.Format("Ошибка в расчете трудоемкости({0},{1})", i + 1, j + 1) + Environment.NewLine);
}
}
}
} if (ers <= allowedErrors) ers = 0; mark -= ers*(10.0 / app.dataStore.tCount); if (app.dataStore.order != tAnswer.Text)
{
mark -= 5.0;
errorsList.Add("Неправильно расставлены скобки в ответе" + Environment.NewLine);
}
if (mark < 0.0) mark = 0; Form2 f;
f = new Form2(this);
f.setData(app.dataStore.order, tAnswer.Text, (int)mark, errorsList);
f.Show();
} private void Form1_Load(object sender, EventArgs e)
{
//tt1.TextChanged += new System.EventHandler(this.Parse);
//bAdd1.Click += new System.EventHandler(this.addLabor); if (LF.edu)
{
GenerateData(1, 0);
linkLabel1.Show();
button1.Hide();
this.Text = "Контрольная \"Оптимальная расстановка скобок при перемножении матриц\" (обучающий режим)";
}
else
{
linkLabel1.Hide();
button1.Show();
GenerateData(0, 5);
this.Text = "Контрольная \"Оптимальная расстановка скобок при перемножении матриц\" (режим контроля)";
}
int i=0; for (i=0;i {
user_solution.Add(new Dictionary()); } for (i = 0; i < MatrixCount;i++ )
{
kp.Add(new List());
for (int j = 0; j < MatrixCount; j++)
{
solution_data s = new solution_data();
s.entering = false;
//s.errors = 0;
for (int u = 0; u < app.dataStore.dCount; u++)
{
s.errors.Add(0);
}
s.tbNum = 0;
s.rightAnswer = false;
//kp[i][j]=0;
kp[i].Add(s);
}
} if (LF.edu)
{
timer1.Enabled = false;
lTime.Text = "∞";
//MessageBox.Show(Convert.ToString(LF.edu));
}
else
{
// MessageBox.Show(Convert.ToString(LF.edu));
timer1.Enabled = true;
lTime.Text = "" + time / 1000 / 60 + ":" + ((time / 1000 % 60) < 10 ? "0" : "") + (time / 1000 % 60);
}
} private void button1_Click_1(object sender, EventArgs e)
{
int p;
for (int t = 1; t < MatrixCount; t++)
{
for (int k = 0; k < MatrixCount - t; k++)
{
p = k + t;
// lAnswer.Text += "("+(k+1)+","+(p+1)+")";
}
}
CheckAnswer();
//lAnswer.Text = app.dataStore.order;
}
private void timer1_Tick(object sender, EventArgs e)
{
lTime.Text = "" + time / 1000 / 60 + ":" + ( (time /1000 % 60) < 10 ? "0":"" ) + (time /1000 % 60);
time -= 1000;
if (time <= 0)
{
// CheckAnswer();
//timer1.Enabled = false;
button1_Click_1(this, e) ;
timer1.Enabled = false;
}
} private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
LF.Show();
Hide();
} private void addLabor(object sender, EventArgs e)
{
//MessageBox.Show("asddd");
} private void LeaveField(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
String s = new String('a', 0);
string snum = new String('a', 0); int i, j, k, t, p, r;
snum = "";
for (i = 0; i < tb.Name.Length; i++)
{
if (tb.Name[i] != 't') snum += tb.Name[i];
} k = p = -1; for (i = 0; i < panel1.Controls.Count; i++)
{
if (String.Format("Unit{0}", snum) == panel1.Controls[i].Name)
{
for (j = 0; j < panel1.Controls[i].Controls.Count; j++)
{
if (String.Format("tk{0}", snum) == panel1.Controls[i].Controls[j].Name)
{
try
{
k = Convert.ToInt32(panel1.Controls[i].Controls[j].Text);
}
catch (System.Exception e2)
{
k = -1;
}
}
if (String.Format("tp{0}", snum) == panel1.Controls[i].Controls[j].Name)
{
try
{
p = Convert.ToInt32(panel1.Controls[i].Controls[j].Text);
}
catch (System.Exception e3)
{
p = -1;
}
}
}
}
} if (k == -1 || p == -1 || k > MatrixCount || p > MatrixCount)
{
//lStatus.Text = ;
//CurrentFail("Введите корректные k и p");
return;
} if (!doneMinCondition(k - 1, p - 1))
{
if (LF.edu) tb.BackColor = Color.Yellow;
} if (kp[k - 1][p - 1].entering && !kp[k - 1][p - 1].rightAnswer)
{
if (LF.edu) tb.BackColor = Color.Red;
}
} private void EnterField(object sender, EventArgs e)
{ } private void CurrentFail(String s)
{
lStatus.ForeColor = Color.Red;
lStatus.Text = s;
} bool tryMinCondition(int i, int j)
{ if ( kp[i][j].errors[0] >= 1 || kp[i][j].errors[1] >= 1 )
{
return true;
} return false;
} bool doneMinCondition(int i, int j)
{ if ((kp[i][j].errors[0] == 1 || kp[i][j].errors[1] == 1) || (i==j && kp[i][j].rightAnswer))
{
return true;
} return false;
} private void Parse(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
String s = new String('a',0);
string snum = new String('a', 0);
List sel = new List(); tb.BackColor = Color.White;
lStatus.Text = ""; int i,j,k,t,p,r;
snum = "";
for (i = 0; i < tb.Name.Length; i++)
{
if (tb.Name[i] != 't') snum += tb.Name[i];
}
k = p = -1; for (i = 0; i < panel1.Controls.Count; i++)
{
if (String.Format("Unit{0}", snum) == panel1.Controls[i].Name)
{
for (j = 0; j < panel1.Controls[i].Controls.Count; j++)
{
if (String.Format("tk{0}", snum) == panel1.Controls[i].Controls[j].Name)
{
try
{
k = Convert.ToInt32(panel1.Controls[i].Controls[j].Text);
}
catch (System.Exception e2)
{
k = -1;
}
}
if (String.Format("tp{0}", snum) == panel1.Controls[i].Controls[j].Name)
{
try
{
p = Convert.ToInt32(panel1.Controls[i].Controls[j].Text);
}
catch (System.Exception e3)
{
p = -1;
}
}
}
}
} for (i = 0; i < tb.Text.Length; i++)
{
if (tb.Text[i] != ' ')
{
s += tb.Text[i];
sel.Add(i);
}
else
{
}
} //lStatus.Text = s; if (k == -1 || p == -1 || k>MatrixCount || p>MatrixCount || k<1 || p<1)
{
//lStatus.Text = ;
CurrentFail("Введите корректные k и p");
return;
}
List sample = new List(); for (j = 0; j < app.dataStore.dCount; j++)
{
sample.Add(new string('a', 0));
kp[k-1][p-1].errors.Add(0);
} try
{
for (j = 0; j < app.dataStore.dCount; j++)
{
sample[j] = app.dataStore.solution[j][string.Format("f({0},{1})", k, p)];
}
}
catch (System.Exception e1)
{
//lStatus.Text = "Неверно введены k и p, повторите ввод";
CurrentFail("Неверно введены k и p, повторите ввод");
return;
} if (kp[k - 1][p - 1].tbNum != int.Parse(snum) && kp[k - 1][p - 1].tbNum != 0)
{
CurrentFail("Расчет для этой трудоемкости уже существует");
return;
} kp[k - 1][p - 1].tbNum = int.Parse(snum);
kp[k - 1][p - 1].entering = true;
if (tb.Text.Length == 0)
{
kp[k - 1][p - 1].tbNum = 0;
kp[k - 1][p - 1].entering = false;
} // for (j = 0; j < 4; j++) int dnum=0;
int lastpos = 0;
int errors=1; for (i = 0; i < s.Length; i++)
{
if (s[i] == '=' && (i-1 == sample[dnum].Length-1))
{
// if (i == sample[dnum].Length)
{
s = s.Substring(i + 1);
sel.RemoveRange(0, i+1);
i = -1; kp[k - 1][p - 1].errors[dnum] = errors; if (user_solution[dnum].ContainsKey(string.Format("f({0},{1})", k, p)))
user_solution[dnum][string.Format("f({0},{1})", k, p)] = errors;
else
user_solution[dnum].Add(string.Format("f({0},{1})", k, p), errors); // lStatus.Text = "Ошибка зафиксированна";
errors = 1;
dnum = 0;
continue;
}
} if (i < sample[dnum].Length)
{
if (s[i] != sample[dnum][i])
{
if (lastpos == 0) lastpos = i;
if (dnum < app.dataStore.dCount - 1)
{
dnum++;
i = -1;
errors = 1;
continue;
}
else
{
errors = 2; if (LF.edu)
{
tb.SelectionStart = sel[lastpos];
tb.SelectionLength = 1;
lStatus.ForeColor = Color.Red;
lStatus.Text = "Ошибка в выделенном фрагменте";
}
}
}
else if (lastpos == i)
{
lastpos = 0;
}
}
else
{
if (LF.edu) CurrentFail("Посторонние символы в поле для ввода");
} if ((dnum == app.dataStore.dCount - 1 && errors == 1 && s.Length == sample[dnum].Length) || (dnum == 0 && k == p && errors == 1))
{
kp[k - 1][p - 1].rightAnswer = true; if (LF.edu && dnum != 0 && !tryMinCondition(k-1,p-1))
CurrentFail("Введите более подробное решение в поле для ввода");
} //(kp[k - 1][p - 1].errors[0] != 1 && kp[k - 1][p - 1].errors[1] != 1 && kp[k - 1][p - 1].errors[2] != 1)
else
{
kp[k - 1][p - 1].rightAnswer = false;
}
//(kp[k - 1][p - 1].errors[0] == 1 || kp[k - 1][p - 1].errors[1] == 1 || k == p || kp[k - 1][p - 1].errors[2] == 1)
if (kp[k - 1][p - 1].rightAnswer && doneMinCondition(k-1,p-1))
{
if (LF.edu)
tb.BackColor = Color.PaleGreen;
}
else
{
tb.BackColor = Color.White;
} if (i >= sample[dnum].Length)
{
if (LF.edu)
{
kp[k - 1][p - 1].rightAnswer = false;
tb.BackColor = Color.White;
}
continue;
} }
}
private void tAnswer_TextChanged(object sender, EventArgs e)
{
int i, j, lastpos;
List sel = new List(); tAnswer.BackColor = Color.White;
lStatus.Text = "";
for (i = 0; i < MatrixCount; i++)
{
for (j = 0; j < MatrixCount; j++)
{
if (j < i) continue;
if (!kp[i][j].rightAnswer || ((j == i && !kp[i][j].rightAnswer) && kp[i][j].errors[0] != 1 && kp[i][j].errors[1] != 1 && kp[i][j].errors[2] != 1))
{
if (LF.edu)
{
CurrentFail("Рассчитанны не все трудоемкости");
tAnswer.Clear();
return;
}
}
}
} string s = new string('a',0); s = "";
sel.Clear();
for (i = 0; i < tAnswer.Text.Length; i++)
{
if (tAnswer.Text[i] != ' ')
{
s += tAnswer.Text[i];
sel.Add(i);
}
} lastpos = 0;
bool fail = false;
for (i = 0; i < s.Length; i++)
{ if (i >= app.dataStore.order.Length)
{
if (LF.edu) CurrentFail("Посторонние символы в поле для ввода");
continue;
}
if (s[i] != app.dataStore.order[i])
{
if (lastpos == 0) lastpos = i;
if (LF.edu)
{
tAnswer.SelectionStart = sel[lastpos];
tAnswer.SelectionLength = 1;
lStatus.ForeColor = Color.Red;
lStatus.Text = "Ошибка в выделенном фрагменте";
}
fail = true;
}
else if (lastpos == i)
{
lastpos = 0;
} } if (!fail && s.Length == app.dataStore.order.Length)
{
if (LF.edu)
{
tAnswer.BackColor = Color.PaleGreen;
lStatus.ForeColor = Color.Lime;
lStatus.Text = "Контрольная решена!";
}
}
else
{
tAnswer.BackColor = Color.White;
} } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Form3 cf = new Form3(this);
cf.Show();
} private void button2_Click(object sender, EventArgs e)
{
DialogResult d;
d = MessageBox.Show("Хотите очистить все поля для ввода?", "Сброс", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (d != DialogResult.OK) return; int i, j;
for (i = 0; i < panel1.Controls.Count; i++)
{
if (panel1.Controls[i] is Panel)
{
for (j = 0; j < panel1.Controls[i].Controls.Count; j++)
{
if (panel1.Controls[i].Controls[j] is TextBox)
{
((TextBox)panel1.Controls[i].Controls[j]).Clear();
}
}
}
} }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace Matrixx
{
public class solution_data
{
public int tbNum;
public List errors = new List();
public bool entering;
public bool rightAnswer;
}; public class cDataStore
{
public List> m;
public List> s;
public List sizes = new List();
public string order = new string('a', 0);
public List> solution = new List>();
public int dCount = 6;
public int tCount = 0;
}
class MatrixChainOrder
{
public cDataStore dataStore; public void matrixChainOrder()
{
// dataStore.solution[0][ for (int i1 = 0; i1 < dataStore.dCount; i1++)
{
dataStore.solution.Add(new Dictionary());
}
int n = dataStore.sizes.Count - 1;
dataStore.order = new string('a', 0);
dataStore.m = new List>();
dataStore.s = new List>(); for (int i = 0; i < n; i++)
{
dataStore.m.Add(new List());
dataStore.s.Add(new List()); for (int a = 0; a < n; a++)
{
dataStore.m[i].Add(0);
dataStore.s[i].Add(0);
}
} int p,t;
string str = new string('a', 0);
dataStore.tCount = 0;
for (t = 1; t <= n; t++)
{
dataStore.tCount++;
for (p = 0; p < dataStore.dCount; p++)
{
str = "0";
dataStore.solution[p].Add(string.Format("f({0},{0})", t), str);
}
} for (t = 1; t < n; t++) //l
for (int k = 0; k < n - t; k++) //i
{
dataStore.tCount++;
p = k + t; //j
dataStore.m[k][p] = int.MaxValue;
str = "";
str += "min(";
for (int j = k; j < p; j++) //k
{
int q = dataStore.m[k][j] + dataStore.m[j + 1][p] +
dataStore.sizes[k] * dataStore.sizes[j + 1] * dataStore.sizes[p + 1];
str += "f(" + (k + 1) + "," + (j + 1) + ")+f(" + (j + 2) + "," + (p + 1) + ")+r" + (k) + "*r" + (j + 1) + "*r" + (p + 1); if (q < dataStore.m[k][p])
{
dataStore.m[k][p] = q;
dataStore.s[k][p] = j;
}
if (j < p - 1) str += ";";
}
str += ")";
dataStore.solution[0].Add(string.Format("f({0},{1})", k + 1, p + 1), str);
if (p==k+1)
{
str = "";
for (int j = k; j < p; j++) //k
{
int q = dataStore.m[k][j] + dataStore.m[j + 1][p] +
dataStore.sizes[k] * dataStore.sizes[j + 1] * dataStore.sizes[p + 1];
str += "f(" + (k + 1) + "," + (j + 1) + ")+f(" + (j + 2) + "," + (p + 1) + ")+r" + (k) + "*r" + (j + 1) + "*r" + (p + 1); if (q < dataStore.m[k][p])
{
dataStore.m[k][p] = q;
dataStore.s[k][p] = j;
}
}
}
dataStore.solution[1].Add(string.Format("f({0},{1})", k + 1, p + 1), str);
str = "min(";
for (int j = k; j < p; j++) //k
{
str += dataStore.m[k][j] + "+" + dataStore.m[j + 1][p] + "+" + dataStore.sizes[k] + "*" + dataStore.sizes[j + 1] + "*" + dataStore.sizes[p + 1];
if (j < p - 1) str += ";";
}
str += ")";
dataStore.solution[3].Add(string.Format("f({0},{1})", k + 1, p + 1), str);
if (p == k + 1)
{
str = "";
str += dataStore.m[k][k] + "+" + dataStore.m[k + 1][p] + "+" + dataStore.sizes[k] + "*" + dataStore.sizes[k + 1] + "*" + dataStore.sizes[p + 1];
}
dataStore.solution[2].Add(string.Format("f({0},{1})", k + 1, p + 1), str);
str = "min(";
for (int j = k; j < p; j++) //k
{
int q = dataStore.m[k][j] + dataStore.m[j + 1][p] + dataStore.sizes[k] * dataStore.sizes[j + 1] * dataStore.sizes[p + 1];
str += q;
if (j < p - 1) str += ";";
}
str += ")";
dataStore.solution[4].Add(string.Format("f({0},{1})", k + 1, p + 1), str);
str = "";
str +=dataStore.m[k][p];
dataStore.solution[5].Add(string.Format("f({0},{1})", k + 1, p + 1), str); }
}
public void printOrder(int i, int j)
{
if (i == j) dataStore.order += "M" + (i+1).ToString();
else
{
if (i == 0 && j == dataStore.sizes.Count - 2) { }
else
dataStore.order += "("; printOrder(i, dataStore.s[i][j]);
dataStore.order += "*";
printOrder(dataStore.s[i][j] + 1, j); if (i == 0 && j == dataStore.sizes.Count - 2 ) { }
else
dataStore.order += ")";
}
} }
}
Контрольная «Задача грабителя» using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Matrixx
{ public partial class MainController : Form
{
LoginForm LF; Rukzak app;
int MatrixCount = 5;
int time = 30*60000;
bool keymode;
int allowedErrors = 2, fullSumm, userSumm;
public List> user_solution = new List>(); List u_sizes = new List();
List u_values = new List(); List kp = new List(); ListViewItem v = new ListViewItem(); public MainController(LoginForm lf)
{
LF = lf;
InitializeComponent();
} public void GenerateData(int example, int _W)
{
int i;
int p, j;
app = new Rukzak();
app.dataStore = new cDataStore(); Random r;
r = new Random();
int t = r.Next(2, 30);
ListViewItem value = new ListViewItem();
app.dataStore.w = new int[3];
app.dataStore.c = new int[3];
listView1.Items.Clear();
if (example == 1)
{
app.dataStore.w[0] = 5;
app.dataStore.w[1] = 7;
app.dataStore.w[2] = 11;
app.dataStore.c[0] = 9;
app.dataStore.c[1] = 13;
app.dataStore.c[2] = 21;
app.dataStore.W = 23;
}
else if (example == 2)
{
app.dataStore.w[0] = 5;
app.dataStore.w[1] = 7;
app.dataStore.w[2] = 11;
app.dataStore.c[0] = 9;
app.dataStore.c[1] = 13;
app.dataStore.c[2] = 21;
app.dataStore.W = 23;
}
else
{
app.dataStore.W = _W;
app.dataStore.w[0] = r.Next(2, app.dataStore.W / 3);
app.dataStore.c[0] = r.Next(2, app.dataStore.W / 2);
for (i = 1; i < 3; i++)
{
app.dataStore.w[i] = app.dataStore.w[i - 1] + r.Next(2, 5);
app.dataStore.c[i] = app.dataStore.c[i - 1] + r.Next(2, 7);
}
} for (i = 0; i < 3; i++)
{
value = new ListViewItem();
value.Text = "" + (i + 1);
value.SubItems.Add("" + app.dataStore.w[i]);
value.SubItems.Add("" + app.dataStore.c[i]);
listView1.Items.Add(value); }
//lStatus.Text = "W=" + app.dataStore.W + "; F(" + app.dataStore.W + ")=" +
fullSumm=app.knapsack(app.dataStore.w, app.dataStore.c, app.dataStore.W); userSumm = 0;
lRemain.Text = "Общая сумма: " + userSumm ;
lMax.Text = "Максимальная грузоподъемность: " + app.dataStore.W;
// app.printOrder(0, MatrixCount-1);
int border = app.dataStore.tCount; for (int k = 0; k <= app.dataStore.W; k++) //i
{
label3.Text += string.Format("f({0})", k) + "=";
for (int y = 0; y < app.dataStore.dCount; y++) //i
{
//p = k + t; //j
//string str = new string('a', 0);
label3.Text += app.dataStore.solution[y][string.Format("f({0})", k)];
label3.Text += "=";
}
label3.Text += "\n";
}
string sname = new string('a',0);
for (i = 0; i < panel1.Controls.Count; i++)
{
if ( panel1.Controls[i] is Panel)
{
sname = panel1.Controls[i].Name.Substring(4);
if (int.Parse(sname) <= app.dataStore.W) panel1.Controls[i].Show();
else panel1.Controls[i].Hide();
}
}
}
private void light(int i)
{
int u, t; for (u = 0; u < panel1.Controls.Count; u++)
{
if (panel1.Controls[u] is Panel)
{
for (t = 0; t < panel1.Controls[u].Controls.Count; t++)
{
if (panel1.Controls[u].Controls[t] is TextBox
&& panel1.Controls[u].Controls[t].Name == string.Format("tt{0}", kp[i].tbNum))
{ ((TextBox)panel1.Controls[u].Controls[t]).BackColor = Color.Red;
}
}
}
}
} private void CheckAnswer()
{
int p,j;
int i=1,u,t;
Control ct;
string tname, tsname;
double mark = 10.0;
double ers=0.0;
List errorsList = new List();
for (j = 0; j < app.dataStore.W; j++)
{
if (kp[j].rightAnswer == false)
{
ers += 1.0;
light(j);
errorsList.Add(string.Format("Неверный ответ в f({0})", j) + Environment.NewLine);
}
if (kp[j].errors[0] == 0 && kp[j].errors[1] == 0 && kp[j].errors[2] == 0)
{
ers += 1.0; ;
light(j);
errorsList.Add(string.Format("Нет подробного решения в f({0})", j) + Environment.NewLine);
}
// if (!doneMinCondition(i, j)) { ers += 1.0; ; light(i, j); }
for (int y = 0; y < app.dataStore.dCount - 1; y++)
{
if (kp[j].errors[y] > 1)
{
ers += 0.5;
errorsList.Add(string.Format("Ошибка в расчете f({0})", j ) + Environment.NewLine);
} }
} if (ers <= allowedErrors) ers = 0; mark -= ers * (10.0 / app.dataStore.tCount); if (userSumm != fullSumm)
{
mark -= 3.0;
errorsList.Add("Неправильно выбраны товары" + Environment.NewLine);
}
if (mark < 0.0) mark = 0;
Form2 f;
f = new Form2(this);
f.setData(userSumm, fullSumm, (int)mark, errorsList);
f.Show();
} private void Form1_Load(object sender, EventArgs e)
{
//tt1.TextChanged += new System.EventHandler(this.Parse);
//bAdd1.Click += new System.EventHandler(this.addLabor); if (LF.edu)
{
GenerateData(0, 23);
linkLabel1.Show();
button1.Hide();
this.Text = "Контрольная \"Задача грабителя (задача о рюкзаке)\" (обучающий режим)";
}
else
{
linkLabel1.Hide();
button1.Show();
GenerateData(0, 23);
this.Text = "Контрольная \"Задача грабителя (задача о рюкзаке)\" (режим контроля)";
}
int i=0; for (i=0;i {
user_solution.Add(new Dictionary()); } for (i = 0; i < MatrixCount;i++ )
{
//kp.Add(new List());
for (int j = 0; j < MatrixCount; j++)
{
solution_data s = new solution_data();
s.entering = false;
//s.errors = 0;
for (int u = 0; u < app.dataStore.dCount; u++)
{
s.errors.Add(0);
}
s.tbNum = 0;
s.rightAnswer = false;
//kp[i][j]=0;
kp.Add(s);
}
} if (LF.edu)
{
timer1.Enabled = false;
lTime.Text = "∞";
//MessageBox.Show(Convert.ToString(LF.edu));
}
else
{
// MessageBox.Show(Convert.ToString(LF.edu));
timer1.Enabled = true;
lTime.Text = "" + time / 1000 / 60 + ":" + ((time / 1000 % 60) < 10 ? "0" : "") + (time / 1000 % 60);
}
} private void button1_Click_1(object sender, EventArgs e)
{
int p;
for (int t = 1; t < MatrixCount; t++)
{
for (int k = 0; k < MatrixCount - t; k++)
{
p = k + t;
// lAnswer.Text += "("+(k+1)+","+(p+1)+")";
}
}
CheckAnswer();
//lAnswer.Text = app.dataStore.order;
}
private void timer1_Tick(object sender, EventArgs e)
{
lTime.Text = "" + time / 1000 / 60 + ":" + ( (time /1000 % 60) < 10 ? "0":"" ) + (time /1000 % 60);
time -= 1000;
if (time <= 0)
{
// CheckAnswer();
//timer1.Enabled = false;
button1_Click_1(this, e) ;
timer1.Enabled = false;
}
} private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
LF.Show();
Hide();
} private void addLabor(object sender, EventArgs e)
{
//MessageBox.Show("asddd");
} private void LeaveField(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
String s = new String('a', 0);
string snum = new String('a', 0); int i, j, k, t, p, r,m;
snum = "";
for (i = 0; i < tb.Name.Length; i++)
{
if (tb.Name[i] != 't') snum += tb.Name[i];
} m = -1; for (i = 0; i < panel1.Controls.Count; i++)
{
if (String.Format("Unit{0}", snum) == panel1.Controls[i].Name)
{
for (j = 0; j < panel1.Controls[i].Controls.Count; j++)
{
if (String.Format("tk{0}", snum) == panel1.Controls[i].Controls[j].Name)
{
try
{
m = Convert.ToInt32(panel1.Controls[i].Controls[j].Text);
}
catch (System.Exception e2)
{
m = -1;
}
} }
}
} if (m == -1 || m > app.dataStore.W || m<0)
{
//lStatus.Text = ;
//CurrentFail("Введите корректные k и p");
return;
} if (!doneMinCondition(m))
{
if (LF.edu) tb.BackColor = Color.Yellow;
} if (kp[m].entering && !kp[m].rightAnswer)
{
if (LF.edu) tb.BackColor = Color.Red;
}
} private void EnterField(object sender, EventArgs e)
{ } private void CurrentFail(String s)
{
lStatus.ForeColor = Color.Red;
lStatus.Text = s;
} bool tryMinCondition(int i)
{ if ( kp[i].errors[0] >= 1 || kp[i].errors[1] >= 1 )
{
return true;
} return false;
} bool doneMinCondition(int i)
{ if ((kp[i].errors[0] == 1 || kp[i].errors[1] == 1) || i {
return true;
} return false;
} private void Parse(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
String s = new String('a',0);
string snum = new String('a', 0);
List sel = new List(); tb.BackColor = Color.White;
lStatus.Text = ""; int i,j,k,t,p,r,m;
snum = "";
for (i = 0; i < tb.Name.Length; i++)
{
if (tb.Name[i] != 't') snum += tb.Name[i];
} m = -1; for (i = 0; i < panel1.Controls.Count; i++)
{
if (String.Format("Unit{0}", snum) == panel1.Controls[i].Name)
{
for (j = 0; j < panel1.Controls[i].Controls.Count; j++)
{
if (String.Format("tk{0}", snum) == panel1.Controls[i].Controls[j].Name)
{
try
{
m = Convert.ToInt32(panel1.Controls[i].Controls[j].Text);
}
catch (System.Exception e2)
{
m = -1;
}
}
}
}
} for (i = 0; i < tb.Text.Length; i++)
{
if (tb.Text[i] != ' ')
{
s += tb.Text[i];
sel.Add(i);
}
else
{
}
} //lStatus.Text = s; if (m == -1 || m > app.dataStore.W || m < 0)
{
//lStatus.Text = ;
CurrentFail("Введите корректное значение M");
return;
} List sample = new List(); for (j = 0; j < app.dataStore.dCount; j++)
{
sample.Add(new string('a', 0));
kp[m].errors.Add(0);
} try
{
for (j = 0; j < app.dataStore.dCount; j++)
{
sample[j] = app.dataStore.solution[j][string.Format("f({0})", m)];
}
}
catch (System.Exception e1)
{
//lStatus.Text = "Неверно введены k и p, повторите ввод";
CurrentFail("Неверно введено M, повторите ввод");
return;
} if (kp[m].tbNum != int.Parse(snum) && kp[m].tbNum != 0)
{
CurrentFail("Расчет для этой грузоподъемности уже существует");
return;
} kp[m].tbNum = int.Parse(snum);
kp[m].entering = true;
if (tb.Text.Length == 0)
{
kp[m].tbNum = 0;
kp[m].entering = false;
} // for (j = 0; j < 4; j++) int dnum=0;
int lastpos = 0;
int errors=1; for (i = 0; i < s.Length; i++)
{
if (s[i] == '=' && (i-1 == sample[dnum].Length-1))
{
// if (i == sample[dnum].Length)
{
s = s.Substring(i + 1);
sel.RemoveRange(0, i+1);
i = -1; kp[m].errors[dnum] = errors;
// lStatus.Text = "Ошибка зафиксированна";
errors = 1;
dnum = 0;
continue;
}
} if (i < sample[dnum].Length)
{
if (s[i] != sample[dnum][i])
{
if (lastpos == 0) lastpos = i;
if (dnum < app.dataStore.dCount - 1)
{
dnum++;
i = -1;
errors = 1;
continue;
}
else
{
errors = 2; if (LF.edu)
{
tb.SelectionStart = sel[lastpos];
tb.SelectionLength = 1;
lStatus.ForeColor = Color.Red;
lStatus.Text = "Ошибка в выделенном фрагменте";
}
}
}
else if (lastpos == i)
{
lastpos = 0;
}
}
else
{
if (LF.edu) CurrentFail("Посторонние символы в поле для ввода");
} if ((dnum == app.dataStore.dCount - 1 && errors == 1 && s.Length == sample[dnum].Length) || (dnum == 0 && errors == 1 && m {
kp[m].rightAnswer = true; if (LF.edu && dnum != 0 && !tryMinCondition(m))
CurrentFail("Введите более подробное решение в поле для ввода");
} //(kp[k - 1][p - 1].errors[0] != 1 && kp[k - 1][p - 1].errors[1] != 1 && kp[k - 1][p - 1].errors[2] != 1)
else
{
kp[m].rightAnswer = false;
}
//(kp[k - 1][p - 1].errors[0] == 1 || kp[k - 1][p - 1].errors[1] == 1 || k == p || kp[k - 1][p - 1].errors[2] == 1)
if (kp[m].rightAnswer && doneMinCondition(m))
{
if (LF.edu)
tb.BackColor = Color.PaleGreen;
}
else
{
tb.BackColor = Color.White;
} if (i >= sample[dnum].Length)
{
if (LF.edu)
{
kp[m].rightAnswer = false;
tb.BackColor = Color.White;
}
continue;
} }
}
} private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Form3 cf = new Form3(this);
cf.Show();
} private void button2_Click(object sender, EventArgs e)
{
DialogResult d;
d = MessageBox.Show("Хотите очистить все поля для ввода?", "Сброс", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (d != DialogResult.OK) return; int i, j;
for (i = 0; i < panel1.Controls.Count; i++)
{
if (panel1.Controls[i] is Panel)
{
for (j = 0; j < panel1.Controls[i].Controls.Count; j++)
{
if (panel1.Controls[i].Controls[j] is TextBox)
{
((TextBox)panel1.Controls[i].Controls[j]).Clear();
}
}
}
} } private void listView1_DragLeave(object sender, EventArgs e)
{
} private void listView1_MouseLeave(object sender, EventArgs e)
{
} private void listView1_MouseDown(object sender, MouseEventArgs e)
{
} private void listView2_MouseUp(object sender, MouseEventArgs e)
{ } private void listView1_DoubleClick(object sender, EventArgs e)
{
lStatus.Text = ""; for (int j = 0; j < app.dataStore.W; j++)
{
if (!doneMinCondition(j) || !kp[j].rightAnswer)
if (LF.edu)
{
CurrentFail("Рассчитанны не все стоимости");
listView2.Items.Clear();
return;
}
}
ListViewItem v1 = new ListViewItem();
v1.Text = listView1.SelectedItems[0].Text;
v1.SubItems.Add( listView1.SelectedItems[0].SubItems[1]);
v1.SubItems.Add ( listView1.SelectedItems[0].SubItems[2]); listView2.Items.Add(v1); userSumm += Convert.ToInt32(v1.SubItems[2].Text);
lRemain.Text = "Общая сумма: " + userSumm;
if (userSumm == fullSumm)
{
lStatus.Text = "Контрольная решена!";
}
}
}
} using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace Matrixx
{
public class solution_data
{
public int tbNum;
public List errors = new List();
public bool entering;
public bool rightAnswer;
}; public class cDataStore
{
public List> solution = new List>();
public int dCount = 5;
public int tCount = 0;
public int[] w;
public int[] c;
public int W;
} class Rukzak
{
public cDataStore dataStore;
public int knapsack(int[] weights, int[] costs, int W)
{ for (int i1 = 0; i1 < dataStore.dCount; i1++)
{
dataStore.solution.Add(new Dictionary());
} int p, t;
string str = new string('a', 0);
dataStore.tCount = 0;
int n = weights.Length;
int[] dp = new int[W + 1];
dp[0] = 0;
dataStore.solution[0].Add(string.Format("f({0})", 0), "0");
for (int w = 1; w <= W; w++)
{
dp[w] = dp[w - 1];
str = "";
str += "max(";
for (int i = 0; i < n; i++)
{
str += "f(" + "M" + "-" + "m" + (i + 1) + ")+C" + (i + 1);
if (weights[i] <= w)
{
dp[w] = Math.Max(dp[w], dp[w - weights[i]] + costs[i]);
}
if (i < n - 1) str += ",";
}
str += ")";
dataStore.solution[0].Add(string.Format("f({0})", w), str);
str = "";
str += "max(";
for (int i = 0; i < n; i++)
{
str += "f(" + w + "-" + weights[i] + ")+" + costs[i];
if (weights[i] <= w)
{
dp[w] = Math.Max(dp[w], dp[w - weights[i]] + costs[i]);
}
if (i }
str += ")";
dataStore.solution[1].Add(string.Format("f({0})", w), str);
str = "";
str += "max(";
for (int i = 0; i < n; i++)
{
if (weights[i] <= w)
{
if (i > 0) str += ",";
str += dp[w - weights[i]] +"+"+ costs[i];
dp[w] = Math.Max(dp[w], dp[w - weights[i]] + costs[i]);
}
}
str += ")";
dataStore.solution[2].Add(string.Format("f({0})", w), str); str = "";
str += "max(";
for (int i = 0; i < n; i++)
{ if (weights[i] <= w)
{
if (i > 0) str += ",";
str += dp[w - weights[i]] + costs[i];
dp[w] = Math.Max(dp[w], dp[w - weights[i]] + costs[i]); } }
str += ")";
dataStore.solution[3].Add(string.Format("f({0})", w), str); str = ""+dp[w];
dataStore.solution[4].Add(string.Format("f({0})", w), str); }
for (t = 0; t < weights[0]; t++)
{
for (p = 0; p < dataStore.dCount; p++)
{
str = "0";
dataStore.solution[p][string.Format("f({0})", t)] = str;
}
} return dp[W];
}
}
}
ПРИложение Б Библиография
Секунов, Н. Самоучитель C#.— СПб: БХВ-Петербург, 2004 .— 576 с.
Зайцева Л.В., Прокофьева Н.О. Модели и методы адаптивного
контроля знаний / Educational Technology & Society. - Nr.7(4), 2004 ISSN 1436-4522 (Международный электронный журнал).
Зайцева Л.В., Прокофьева Н.О. Проблемы компьютерного контроля
знаний / Proceedings. IEEE International Conference on Advanced Learning
Technologies (ICALT 2002). 9-12 September 2002. Kazan, Tatrstan, Russia, 2002, - p. 102- 106.
Ник Рендольф, Дэвид Гарднер, Майкл Минутилло, Крис Андерсон Visual Studio 2010 для профессионалов. - М: Диалектика, 2011 г.- 1184 с.- ISBN 978-5-8459-1683-9
Эндрю Троелсен C# и платформа .NET 3.0.- СПб: Питер, 2008.-1456 с.- ISBN 978-5-91180-518-0
Карли Ватсон C# .- М:Лори, 2004. – 880 с. - ISBN 5-85582-228-1
Джозеф Албахари, Бен Албахари C# 3.0. Справочник. – СПб: БХВ-Петербург, 2009 г. – 944 с. - ISBN 978-5-9775-0245-0
Интернет-Университет Информационных Технологий [Электронный ресурс]. — Режим доступа: http://www.intuit.ru. — Загл. с экрана. — яз. рус.
Wikipedia, the free encyclopedia [Электронный ресурс] : Cвободная общедоступная многоязычная универсальная энциклопедия. — Режим доступа: http://en.wikipedia.org/wiki/Main_Page. — Загл. с экрана. — яз. англ.
1> |