当前位置: 代码迷 >> C# >> 急用~怎样把下面的C语言程序改为C#程序
  详细解决方案

急用~怎样把下面的C语言程序改为C#程序

热度:487   发布时间:2016-05-05 02:53:17.0
急用~怎样把下面的C语言程序改成C#程序
#include<stdio.h>
struct struc { int a;
               int b;
               int c;
               int add;
               int grade;
               };
 
 
int sj(int n)
{ int t; 
              t=rand()%n;
              return t;
             }
 
 
void ctm_i(struct struc *t)
             { t->a=sj(51);
              t->c=sj(2);
              if(t->c==1) { t->b=sj(51-(t->a));
                         t->add=(t->a)+(t->b);}
    else { t->b=sj((t->a)+1);
         t->add=(t->a)-(t->b);}
    t->grade=10;
  }
 
void tcm_i(struct struc *t,int n)
  { int ad;
printf("********************************************************************************\n");
     printf("................................................................................\n");
   printf("现在进行第%d题\n\n",n+1);
   printf("本题你总共有三次机会\n\n");
   if(t->c==1)printf("%d+%d=",t->a,t->b);
   else printf("%d-%d=",t->a,t->b);
scanf("%d",&ad);
if(ad==t->add)
      { t->grade=10;
        printf("很好,本题得10分\n\n");
        }
   else { printf("结果不正确,你还有两次机会,加油\n\n");
scanf("%d",&ad);
if(ad==t->add)
             { t->grade=7;
               printf("不错,本题得7分\n\n");
              }
         else { printf("结果不正确,你还有一次机会,加油\n\n");
scanf("%d",&ad);
if(ad==t->add)
                   { t->grade=5;
                    printf("还行,本题得5分\n\n");
                    }
               else { t->grade=0;
                    printf("失败,本题得0分\n\n");
                    printf("正确结果是%d\n\n",t->add);
                       }
                 }
          }
      printf("................................................................................\n");
printf("********************************************************************************\n");
      }
 
 
void main()
  { int i,j,g=0;
    char x;
    struct struc test[10];
    srand((unsigned)time(NULL));
    printf("*************************************************  *******************************\n");
printf("................................................................................\n");
    printf("***********************欢迎进入小学生算术四则运算测试程序***********************\n\n");
    printf("...本程序是面向小学1~2年级学生,随机选择两个整数和加减法形成算式要求学生解答....\n");
    printf("功能说明:\n");
 printf("................................................................................\n");
printf("********************************************************************************\n");
  for(i=0;i<=9;i++)
      { ctm_i(&test[i]);
        for(j=0;j<i;j++)
           if(test[i].a==test[j].a&&test[i].b==test[j].b&&test[i].c==test[j]   .c)
                ctm_i(&test[i]);
        }
printf("准备好了吗?按任意键进入");
    scanf("%c",&x);
    for(i=1;i<=5;i++)
{ printf("********************************************************************************\n");
      printf("................................................................................\n");
}
for(i=0;i<=9;i++)
tcm_i(&test[i],i);
   printf("测试结束");
   for(i=0;i<=9;i++)
 g=g+test[i].grade;
   if(g>90) printf("SMART");
   else if (g>80) printf("GOOD");
        else if (g>70) printf("OK");
              else printf("TRY AGAIN");
   }

------解决思路----------------------
请楼主移驾C#论坛。http://bbs.csdn.net/forums/CSharp
------解决思路----------------------
将标准输入输出函数换成c#的,好想记得是writeline和readline,还有好像c#这玩意不认指针
------解决思路----------------------
namespace ConsoleApplication3
{
    public struct struc
    {
        public int a;
        public int b;
        public int c;
        public int add;
        public int grade;
    }

    class Program
    {
        static int sj(int n)
        {
            int t;
            t = new System.Random().Next() % n;
            return t;
        }

        static struc ctm_i()
        {
            struc t=new struc();
            t.a = sj(51);
            t.c = sj(2);
            if (t.c == 1)
            {
                t.b = sj(51 - (t.a));
                t.add = (t.a) + (t.b);
            }
            else
            {
                t.b = sj((t.a) + 1);
                t.add = (t.a) - (t.b);
            }
            t.grade = 10;
            return t;
        }

        static void tcm_i(struc t, int n)
        {
            int ad;

            Console.WriteLine("********************************************************************************\n");
            Console.WriteLine("................................................................................\n");
            Console.WriteLine("现在进行第"+(n+1)+"题\n\n");
            Console.WriteLine("本题你总共有三次机会\n\n");
            if (t.c == 1)
            {
                Console.WriteLine( t.a +"+"+ t.b+"=");
            }
            else
            {
                Console.WriteLine(t.a+"-" +t.b+"=");
            }
            ad = Int32.Parse(Console.ReadLine());

            if (ad == t.add)
            {
                t.grade = 10;
                Console.WriteLine("很好,本题得10分\n\n");
            }
            else
            {
                Console.WriteLine("结果不正确,你还有两次机会,加油\n\n");
                ad = Int32.Parse(Console.ReadLine());
                if (ad == t.add)
                {
                    t.grade = 7;
                    Console.WriteLine("不错,本题得7分\n\n");
                }
                else
                {
                    Console.WriteLine("结果不正确,你还有一次机会,加油\n\n");
                    ad = Int32.Parse(Console.ReadLine());
                    if (ad == t.add)
                    {
                        t.grade = 5;
                        Console.WriteLine("还行,本题得5分\n\n");
                    }
                    else
                    {
                        t.grade = 0;
                        Console.WriteLine("失败,本题得0分\n\n");
                        Console.WriteLine("正确结果是%d\n\n", t.add);
                    }
                }
            }
            Console.WriteLine("................................................................................\n");
            Console.WriteLine("********************************************************************************\n");
        }


        static void Main(string[] args)
        {
            int i, j, g = 0;
            char x;
            struc[] test = new struc[10];

            Console.WriteLine("*************************************************  *******************************\n");
            Console.WriteLine("................................................................................\n");
            Console.WriteLine("***********************欢迎进入小学生算术四则运算测试程序***********************\n\n");
            Console.WriteLine("...本程序是面向小学1~2年级学生,随机选择两个整数和加减法形成算式要求学生解答....\n");
            Console.WriteLine("功能说明:\n");
            Console.WriteLine("................................................................................\n");
            Console.WriteLine("********************************************************************************\n");
            for (i = 0; i <= 9; i++)
            {
                test[i] = ctm_i();
                for (j = 0; j < i; j++)
                {
                    if (test[i].a == test[j].a && test[i].b == test[j].b && test[i].c == test[j].c)
                    {
                        test[i] = ctm_i();
                    }
                }
            }
            Console.WriteLine("准备好了吗?按任意键进入");
            Console.ReadLine();
            for (i = 1; i <= 5; i++)
            {
                Console.WriteLine("********************************************************************************\n");
                Console.WriteLine("................................................................................\n");
            }
            for (i = 0; i <= 9; i++)
            {
                tcm_i(test[i], i);
                Console.WriteLine("测试结束");
                for (i = 0; i <= 9; i++)
                    g = g + test[i].grade;
                if (g > 90) Console.WriteLine("SMART");
                else if (g > 80) Console.WriteLine("GOOD");
                else if (g > 70) Console.WriteLine("OK");
                else Console.WriteLine("TRY AGAIN");
            }

            Console.ReadLine();

        }
    }
}
  相关解决方案