PDA

View Full Version : سوال: تبدیل قطعه کد از ++c به vb.net



mehran5
جمعه 24 آبان 1387, 20:38 عصر
سلام
ببخشید کسی میدونه کد زیر چطوری از سی سی پلا س پلاس به ویبی دات نت تبدیل میشه کرذ؟


#include<iostream.h>

#include<conio.h>

#define MAX 10

int *Vcolor,n,m;

int w[MAX][MAX]={0};

bool promising(int);

void m_coloring(int i)
{

int color;

if(promising(i))
if(i==n)
{
for(int index=1;index<=n;index++)
cout<<Vcolor[index]<<" ";
cout<<endl;
}
else

for(color=1;color<=m;color++)
{
Vcolor[i+1]=color;
m_coloring(i+1);
}
}

bool promising(int i)
{
int k;
bool myswitch;
k=1;
myswitch = true;
while (k<i && myswitch)
{
if(w[i][k] && Vcolor[i]==Vcolor[k])
myswitch = false;
k++;
}
return myswitch;
}

void main()
{
cout<<"Enter Number Of Vertices:\n";
cin>>n;
cout<<"Enter Number Of Color (m):\n";
cin>>m;
Vcolor=new int[m+1];
cout<<"Enter Your Graph Using Weight Matrix 1 If Exciting Edge And Else 0\n";

for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if((i!=j)&&(i<j))
{
cout<<i<<" and "<<j<<" : ";
cin>>w[i][j];
w[j][i]=w[i][j];
}
if(i==j)
w[i][j]=0;
}
cout<<"\nOutput\n\n";
m_coloring(0);
cout<<"\nPress Any Key...\n";
getch();
}

saadatfar
جمعه 24 آبان 1387, 20:55 عصر
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2575&lngWId=10

reza1944
جمعه 24 آبان 1387, 21:11 عصر
يك نه از كد vb

Imports Microsoft.VisualBasic
Imports System

'ORIGINAL LINE: #define MAX 10int *Vcolor,n,m;int w[MAX][MAX]={0};bool promising(int);
#Const MAX = True
Private Sub m_coloring(ByVal i As Integer)
Dim color As Integer
If promising(i) Then
If i =n Then
For index As Integer = 1 To n
Console.Write(Vcolor(index))
Console.Write(" ")
Next index
Console.Write(ControlChars.Lf)
Else
For color = 1 To m
Vcolor(i+1)=color
m_coloring(i+1)
Next color
End If
End If
End Sub
Private Function promising(ByVal i As Integer) As Boolean
Dim k As Integer
Dim myswitch As Boolean
k =1
myswitch = True
Do While k<i AndAlso myswitch
If w(i)(k) AndAlso Vcolor(i)=Vcolor(k) Then
myswitch = False
End If
k += 1
Loop
Return myswitch
End Function
Private Shared Sub Main()
Console.Write("Enter Number Of Vertices:" & Constants.vbLf)
n = SimulateCin.ReadToWhiteSpace(True)
Console.Write("Enter Number Of Color (m):" & Constants.vbLf)
m = SimulateCin.ReadToWhiteSpace(True)
Vcolor = New Integer(m){}
Console.Write("Enter Your Graph Using Weight Matrix 1 If Exciting Edge And Else 0" & Constants.vbLf)
For i As Integer = 1 To n
For j As Integer = 1 To n
If (i<>j) AndAlso (i<j) Then
Console.Write(i)
Console.Write(" and ")
Console.Write(j)
Console.Write(" : ")
w(i)(j) = SimulateCin.ReadToWhiteSpace(True)
w(j)(i)=w(i)(j)
End If
If i =j Then
w(i)(j)=0
End If
Next j
Next i
Console.Write(Constants.vbLf & "Output" & Constants.vbLf + Constants.vbLf)
m_coloring(0)
Console.Write(Constants.vbLf & "Press Any Key..." & Constants.vbLf)
Console.ReadKey(True).KeyChar
End Sub
''----------------------------------------------------------------------------------------
Friend Class SimulateCin
Private Sub New()
'to prevent instantiation
End Sub
Private Shared goodlastread As Boolean = False
Friend Shared ReadOnly Property LastReadWasGood As Boolean
Get
Return goodlastread
End Get
End Property
Friend Shared Function ReadToWhiteSpace(ByVal skipleadingwhitespace As Boolean) As String
Dim input As String = ""
Dim nextchar As Char
If skipleadingwhitespace Then
nextchar = ChrW(Console.Read())
Do While Char.IsWhiteSpace(nextchar)
nextchar = ChrW(Console.Read())
Loop
input &= nextchar
End If
nextchar = ChrW(Console.Read())
Do While Not Char.IsWhiteSpace(nextchar)
input &= nextchar
nextchar = ChrW(Console.Read())
Loop
goodlastread = input.Length > 0
Return input
End Function
End Class


گه به دردت خورد روي تشكر كليك كن

mehran5
دوشنبه 27 آبان 1387, 23:49 عصر
متغیر vcolor در ++cاین طوری معرفی شده int *Vcolor,n,m
اما شما در vb.net این جور تبدیل کردید:Vcolor = NewInteger(m){} .یعنی این همون اشاره گره؟
همچین نامفهومه اگه تو تگ می زاشتید بهتر بود واگه یه توضیح کوچک برای توابع بعد از مین میدادید خیلی جالب می شد ممنون؟!

reza1944
سه شنبه 28 آبان 1387, 09:52 صبح
اقاي مهران استاد گرامي فرصت نداشم معذرت مي خواهم از شما و دوستان

hz26262
پنج شنبه 17 دی 1388, 10:14 صبح
تبديل آنلاين vb به c و بالعكس
http://www.developerfusion.com/tools/convert/csharp-to-vb/