pesareh shoja
کاربر تازه وارد
- تاریخ عضویت
- 19 آپریل 2006
- نوشتهها
- 1
- لایکها
- 0
:lol: يك برنامه بنويسيد كه حاصل ضرب دو ماتريس مرتبه nرا در ماتريسي ديگر قرار داده و نمايش دهد؟
به نقل از taia :
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace Questions
{
/// <summary>
/// Summary description for MainForm.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox output;
private System.Windows.Forms.ListBox logger;
private System.Windows.Forms.TextBox input;
private System.Windows.Forms.Button OK;
private System.Windows.Forms.Button save;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
string path;
public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
path = Environment.CurrentDirectory + "\\";
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.output = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.logger = new System.Windows.Forms.ListBox();
this.input = new System.Windows.Forms.TextBox();
this.OK = new System.Windows.Forms.Button();
this.save = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.SuspendLayout();
//
// output
//
this.output.Location = new System.Drawing.Point(8, 8);
this.output.Multiline = true;
this.output.Name = "output";
this.output.Size = new System.Drawing.Size(272, 40);
this.output.TabIndex = 0;
this.output.TabStop = false;
this.output.Text = "textBox1";
this.output.TextChanged += new System.EventHandler(this.output_TextChanged);
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 112);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 24);
this.button1.TabIndex = 1;
this.button1.Text = "بلي";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(192, 112);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(80, 24);
this.button2.TabIndex = 2;
this.button2.Text = "خير";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// logger
//
this.logger.ItemHeight = 15;
this.logger.Location = new System.Drawing.Point(8, 144);
this.logger.Name = "logger";
this.logger.Size = new System.Drawing.Size(272, 94);
this.logger.TabIndex = 3;
//
// input
//
this.input.Enabled = false;
this.input.Location = new System.Drawing.Point(8, 64);
this.input.Multiline = true;
this.input.Name = "input";
this.input.Size = new System.Drawing.Size(272, 40);
this.input.TabIndex = 4;
this.input.Text = "";
//
// OK
//
this.OK.Enabled = false;
this.OK.Location = new System.Drawing.Point(104, 112);
this.OK.Name = "OK";
this.OK.Size = new System.Drawing.Size(80, 24);
this.OK.TabIndex = 5;
this.OK.Text = "ورود";
this.OK.Click += new System.EventHandler(this.OK_Click);
//
// save
//
this.save.Location = new System.Drawing.Point(168, 248);
this.save.Name = "save";
this.save.Size = new System.Drawing.Size(104, 24);
this.save.TabIndex = 6;
this.save.Text = "ذخيره دانسته ها";
this.save.Click += new System.EventHandler(this.save_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(16, 248);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(104, 24);
this.button3.TabIndex = 7;
this.button3.Text = "ذخيره سياهه";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// saveFileDialog1
//
this.saveFileDialog1.Filter = "text file (*.txt)|*.txt";
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 278);
this.Controls.Add(this.button3);
this.Controls.Add(this.save);
this.Controls.Add(this.OK);
this.Controls.Add(this.logger);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.output);
this.Controls.Add(this.input);
this.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(178)));
this.Name = "MainForm";
this.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.Text = "MainForm";
this.Load += new System.EventHandler(this.MainForm_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
const int cap = 1000;
int Length = 0;
row[] A = new row[cap];
private void MainForm_Load(object sender, System.EventArgs e)
{
load ();
newGame ();
}
int lastc;
int _c;
int c
{
get
{
return _c;
}
set
{
lastc = _c;
_c = value;
}
}
bool first = true;
void newGame ()
{
if ( !first && MessageBox.Show ( "آيا ميخواهيد بازي كنيد؟", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.No )
{
save_Click ( this, new EventArgs () );
Close ();
}
first = false;
logger.Items.Add ( "بازي جديد" );
_c = 0;
c = 0;
think ();
}
void think ()
{
if ( !A[c].isQuestion )
{
output.Text = "آيا " + A[c].text + " است؟";
return;
}
while ( !A[c].isQuestion )
{
c++;
/*if ( Length == c )
{
giveUp ();
return;
}*/
}
output.Text = A[c].text;
}
private void button1_Click(object sender, System.EventArgs e)
{
logger.Items.Add ( "Human : بلي" );
if ( !A[c].isQuestion )
{
output.Text = "من بردم!!!";
newGame ();
return;
}
c = A[c].yes;
withYes = true;
think ();
}
private void button2_Click(object sender, System.EventArgs e)
{
logger.Items.Add ( "Human : خير" );
if ( !A[c].isQuestion )
{
output.Text = "من باختم!!! كلمه مورد نظر چه بود؟";
input.Enabled = true;
button1.Enabled = false;
button2.Enabled = false;
OK.Enabled = true;
OKlevel = false;
input.Focus ();
return;
}
c = A[c].no;
withYes = false;
think ();
}
private void output_TextChanged(object sender, System.EventArgs e)
{
logger.Items.Add ( "AI : " + output.Text );
}
bool OKlevel;
string newAnimal;
bool withYes;
private void OK_Click(object sender, System.EventArgs e)
{
logger.Items.Add ( "Human : " + input.Text );
if ( OKlevel )
{
int a;
if ( withYes )
{
a = A[lastc].yes;
A[lastc].yes = Length;
}
else
{
a = A[lastc].no;
A[lastc].no = Length;
}
A[Length] = new row ( input.Text, Length + 1, a );
A[Length+1] = new row ( newAnimal );
Length += 2;
input.Enabled = false;
button1.Enabled = true;
button2.Enabled = true;
OK.Enabled = false;
input.Text = "";
newGame ();
}
else
{
output.Text = "فرق بين " + input.Text + " و " + A[c].text + " را با چه سؤالي مي توان فهميد؟";
newAnimal = input.Text;
input.Text = "";
OKlevel = true;
input.Focus ();
}
}
void load ()
{
if ( !File.Exists ( path + "Knows" ) )
{
A[0] = new row ( "آيا جاندار است؟", 1, 2 );
A[1] = new row ( "گربه" );
A[2] = new row ( "دفتر" );
Length += 3;
return;
}
FileStream sw = new FileStream ( path + "Knows", FileMode.Open );
BinaryReader w = new BinaryReader ( sw );
Length = w.ReadInt32 ();
for ( int i = 0; i < Length; i++ )
A[i] = new row ( w.ReadBoolean(), w.ReadString (), w.ReadInt32 (), w.ReadInt32 () );
w.Close ();
}
private void save_Click(object sender, System.EventArgs e)
{
FileStream sw = new FileStream ( path + "Knows", FileMode.Create );
BinaryWriter w = new BinaryWriter ( sw );
w.Write ( Length );
for ( int i = 0; i < Length; i++ )
{
w.Write ( A[i].isQuestion );
w.Write ( A[i].text );
w.Write ( A[i].yes );
w.Write ( A[i].no );
}
w.Close ();
MessageBox.Show ( "دانسته ها ذخيره شد" );
}
private void button3_Click(object sender, System.EventArgs e)
{
if ( saveFileDialog1.ShowDialog () == DialogResult.OK )
{
StreamWriter sw = new StreamWriter ( saveFileDialog1.FileName );
foreach ( object c in logger.Items )
sw.WriteLine ( c.ToString () );
sw.Close ();
}
}
}
public class row
{
public bool isQuestion;
public string text;
public int yes;
public int no;
public row ( string _text, int _yes, int _no )
{
isQuestion = true;
text = _text;
yes = _yes;
no = _no;
}
public row ( string _text )
{
isQuestion = false;
text = _text;
yes = -1;
no = -1;
}
public row ( bool _isQuestion, string _text, int _yes, int _no )
{
isQuestion = _isQuestion;
text = _text;
yes = _yes;
no = _no;
}
}
}