如何将C ++代码更改为C#代码 [英] How to Change C++ Code to C# Code

查看:86
本文介绍了如何将C ++代码更改为C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <conio.h>
#include <cstdio>
#include <iostream>
#include <string.h>
#include <cstdlib>
using namespace std;
static int p = 0;
class a
{
	char busn[5], driver[10], arrival[5], depart[5], from[10], to[10], seat[8][4][10];
public:
	void install();
	void allotment();
	void empty();
	void show();
	void avail();
	void position(int i);
}
bus[10];
void vline(char ch)
{
	for (int i=80;i>0;i--)
	cout<<ch;
}
void a::install()
{
	cout<<"Enter bus no: ";
	cin>>bus[p].busn;
	cout<<"\nEnter Driver's name: ";
	cin>>bus[p].driver;
	cout<<"\nArrival time: ";
	cin>>bus[p].arrival;
	cout<<"\nDeparture: ";
	cin>>bus[p].depart;
	cout<<"\nFrom: \t\t\t";
	cin>>bus[p].from;
	cout<<"\nTo: \t\t\t";
	cin>>bus[p].to;
	bus[p].empty();
	p++;
}
void a::allotment()
{
	int seat;
	char number[5];
	top:
	cout<<"Bus no: ";
	cin>>number;
	int n;
	for(n=0;n<=p;n++)
	{
		if(strcmp(bus[n].busn, number)==0)
		break;
	}
	while(n<=p)
	{
		cout<<"\nSeat Number: ";
		cin>>seat;
		if(seat>32)
		{
			cout<<"\nThere are only 32 seats available in this bus.";
		}
		else
		{
		if (strcmp(bus[n].seat[seat/4][(seat%4)-1], "Empty")==0)
			{
				cout<<"Enter passanger's name: ";
				cin>>bus[n].seat[seat/4][(seat%4)-1];
				break;
			}
		else
			cout<<"The seat no. is already reserved.\n";
			}
			}
		if(n>p)
		{
			cout<<"Enter correct bus no.\n";
			goto top;
		}
	}

void a::empty()
{
	for(int i=0; i<8;i++)
	{
		for(int j=0;j<4;j++)
		{
			strcpy(bus[p].seat[i][j], "Empty");
		}
	}
}
void a::show()
{
	int n;
	char number[5];
	cout<<"Enter bus no: ";
	cin>>number;
	for(n=0;n<=p;n++)
	{
		if(strcmp(bus[n].busn, number)==0)
		break;
	}
while(n<=p)
{
	vline('*');
	cout<<"Bus no: \t"<<bus[n].busn
	<<"\nDriver: \t"<<bus[n].driver<<"\t\tArrival time: \t"
	<<bus[n].arrival<<"\tDeparture time:"<<bus[n].depart
	<<"\nFrom: \t\t"<<bus[n].from<<"\t\tTo: \t\t"<<
	bus[n].to<<"\n";
	vline('*');
	bus[0].position(n);
	int a=1;
	for (int i=0; i<8; i++)
	{
		for(int j=0;j<4;j++)
		{
			a++;
			if(strcmp(bus[n].seat[i][j],"Empty")!=0)
			cout<<"\nThe seat no "<<(a-1)<<" is reserved for "<<bus[n].seat[i][j]<<".";
		}
	}
	break;
	}
	if(n>p)
		cout<<"Enter correct bus no: ";
}
void a::position(int l)
{
	int s=0;p=0;
	for (int i =0; i<8;i++)
	{
		cout<<"\n";
		for (int j = 0;j<4; j++)
		{
			s++;
			if(strcmp(bus[l].seat[i][j], "Empty")==0)
				{
					cout.width(5);
					cout.fill(' ');
					cout<<s<<".";
					cout.width(10);
					cout.fill(' ');
					cout<<bus[l].seat[i][j];
					p++;
				}
				else
				{
				cout.width(5);
				cout.fill(' ');
				cout<<s<<".";
				cout.width(10);
				cout.fill(' ');
				cout<<bus[l].seat[i][j];
				}
			}
		}
	cout<<"\n\nThere are "<<p<<" seats empty in Bus No: "<<bus[l].busn;
	}
void a::avail()
{

	for(int n=0;n<p;n++)>
	{
		vline('*');
		cout<<"Bus no: \t"<<bus[n].busn<<"\nDriver: \t"<<bus[n].driver
		<<"\t\tArrival time: \t"<<bus[n].arrival<<"\tDeparture Time: \t"
		<<bus[n].depart<<"\nFrom: \t\t"<<bus[n].from<<"\t\tTo: \t\t\t"
		<<bus[n].to<<"\n";
		vline('*');
		vline('_');
	}
}
int main()
{
system("cls");
int w;
while(1)
{
    //system("cls");
	cout<<"\n\n\n\n\n";
	cout<<"\t\t\t1.Install\n\t\t\t"
	<<"2.Reservation\n\t\t\t"
	<<"3.Show\n\t\t\t"
	<<"4.Buses Available. \n\t\t\t"
	<<"5.Exit";
	cout<<"\n\t\t\tEnter your choice:-> ";
	cin>>w;
	switch(w)
	{
		case 1:	bus[p].install();
			break;
		case 2:	bus[p].allotment();
			break;
		case 3:	bus[0].show();
			break;
		case 4:	bus[0].avail();
			break;
		case 5:	exit(0);
	}
}
return 0;
}

推荐答案

我建​​议你代码重写 [ ^ ]。无论如何,请查看此博客文章

.NET代码转换 - 转换代码 - C ++ to .NET [ ^ ]
I suggest you to Code Rewrite[^]. Anyway check this blog post
.NET Code Conversion - Convert your code - C++ to .NET[^]


可能有一些在线转换器但是从C ++到C#我不相信它们。我建议用C#重新编写代码。
There may be some converters online but to go from C++ to C# I would not trust them. I would suggest re-writing the code in C#.


我的c ++代码中没有看到任何复杂的内容 - 所以只需找到ac#primer并给它一个镜头,从你的班级开始



想想(查看你的字符类型),在C#中是否合适(在这种情况下答案似乎是不) - 所以也许你想在c#中使用String类型。类似地,对于到达,离开时间,为什么不将输入读作String,而是将实际值作为DateTime字段存储在类中。
I don't see anything in your c++ code that is 'complex' - so just find a c# primer and give it a shot, starting with your class

Think about (looking at your char types), is that appropriate in C# (the answer in this case appears to be 'no') - so maybe you want to use String types in c# for instance. Similarly for the arrival, departure times, why not read input as a String, but store the real values in the class as a DateTime field.


这篇关于如何将C ++代码更改为C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆