• پایان فعالیت بخشهای انجمن: امکان ایجاد موضوع یا نوشته جدید برای عموم کاربران غیرفعال شده است

درخواست حل تمرين سي++ --------بدون جواب

pesareh shoja

کاربر تازه وارد
تاریخ عضویت
19 آپریل 2006
نوشته‌ها
1
لایک‌ها
0
:lol: يك برنامه بنويسيد كه حاصل ضرب دو ماتريس مرتبه nرا در ماتريسي ديگر قرار داده و نمايش دهد؟
 

taia

کاربر تازه وارد
تاریخ عضویت
29 آپریل 2006
نوشته‌ها
6
لایک‌ها
2
محل سکونت
Melaka, Malaysia
اگر کسی احیاناً راه حل سوال زیر را می دونه، یه ندایی بده.
فوری



Problem 1

Background:
One of the possible usages of graph data structure is to show the relations among the cities in a state. Assume that you are given a state, which consist of TEN cities as shown in the following table:

From City To City Distance
A B 8
A D 2
B C 8
B D 7
B F 9
C G 12
D I 10
E F 7
F G 14
G J 6
H D 1
I E 8


Task:
You are given a file that contains the information shown in the table. The file is named as Input.txt and it is in the following structure:

A
B
C
D
E
F
G
H
I
J
=====
I E 8
G J 6
B F 9
H D 1
F G 14
B D 7
E F 7
A D 2
B C 8
D I 10
A B 8
C G 12

The file basically contains two important sections that are separated by FIVE “=” symbols. The lines before the “=====” are the sets of cities in the state. The lines after the “=====” are the set of relationships among the cities. For instance, I E 8; this basically reflects that we can travel from city I to city E with the distance 8 units.
You are to implement a graph data structure to illustrate the relationships among those cities based on the text file given. You must employ the adjacency list method to implement the graph. You can make use of the STL container​
.
 

taia

کاربر تازه وارد
تاریخ عضویت
29 آپریل 2006
نوشته‌ها
6
لایک‌ها
2
محل سکونت
Melaka, Malaysia
دوستان عزیز اگر کسی راه حلی برای 2 سوال آپلود شده به ذهنش می رسد، پست کند.

DOWNLOAD-e Proje
 

firebird

Registered User
تاریخ عضویت
2 جولای 2005
نوشته‌ها
1,424
لایک‌ها
10
سن
47
یه کتاب هربرت شیلد داره خودآموز ++C هست فکر کنم ترجمه فارسیش شده بود "راهنمای سریع ++C" یکی دو فصل دقیقاً موضوعش همین هست فقط اون به جای ای بی سی اسم شهرهای ایالات متحده است :D
 

meti_tricky

کاربر تازه وارد
تاریخ عضویت
18 آپریل 2006
نوشته‌ها
1
لایک‌ها
0
سلام یه سوال نسبتا ساده داشتم
یک چوب یک متری را هزار دفعه به صورت تصادفی به سه قسمت می کنیم برنامه ای بنویسید که احتمال تشکیل مثلث را در این هزار دفعه محاسبه و نمایش دهد:)
 

arman_o71

کاربر تازه وارد
تاریخ عضویت
18 آپریل 2006
نوشته‌ها
3
لایک‌ها
0
به نقل از taia :
دوستان عزیز اگر کسی راه حلی برای 2 سوال آپلود شده به ذهنش می رسد، پست کند.

DOWNLOAD-e Proje

من جواب سؤال 2 رو با C#.Net نوشتم:
کد:
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;
		}
	}
}
 

فایل های ضمیمه

  • Questions.zip
    10.1 KB · نمایش ها: 8

taia

کاربر تازه وارد
تاریخ عضویت
29 آپریل 2006
نوشته‌ها
6
لایک‌ها
2
محل سکونت
Melaka, Malaysia
ممنون دوست عزيز.
ولي آيا شما کانورتر c++ به .net را نداريد و يا خود برنامه را به زبان c++؟
 
بالا