0 Replies Latest reply on Feb 27, 2007 4:29 AM by sue_uya

    How to export C++ program to lingo

    sue_uya
      Hi,
      i have a coding using Visual Basic C++.
      HOw I can making changes the code in lingo,so i can see the output..

      The code is here...

      #include<iostream.h>


      int processMinterm(char [][4], int);

      char final[16][4],mintermAll[30][4];
      int countf=0;


      void main()
      {

      char array[4], mint1[16][4],mint2[30][4];
      int input,check,c1=0,count;


      cout<<endl<<endl;
      cout<< " CD 00 01 11 10 "<<endl;
      cout<< " AB --------------- "<<endl;
      cout<< " 00| 1 | 2 | 3 | 4 |"<<endl;
      cout<< " |---|---|---|---|"<<endl;
      cout<< " 01| 5 | 6 | 7 | 8 |"<<endl;
      cout<< " |---|---|---|---|"<<endl;
      cout<< " 11| 9 | 10| 11| 12|"<<endl;
      cout<< " |---|---|---|---|"<<endl;
      cout<< " 10| 13| 14| 15| 16|"<<endl;
      cout<< " --------------- "<<endl;
      cout<<endl;

      while (input != -1)
      {
      cout<<"Enter minterm positions (-1 if you're done): ";
      cin>>input;

      if (0<input && input<17)
      {
      switch (input)
      {
      case 1:
      array[0] = '0';
      array[1] = '0';
      array[2] = '0';
      array[3] = '0';
      break;
      case 2:
      array[0] = '0';
      array[1] = '0';
      array[2] = '0';
      array[3] = '1';
      break;
      case 3:
      array[0] = '0';
      array[1] = '0';
      array[2] = '1';
      array[3] = '1';
      break;
      case 4:
      array[0] = '0';
      array[1] = '0';
      array[2] = '1';
      array[3] = '0';
      break;
      case 5:
      array[0] = '0';
      array[1] = '1';
      array[2] = '0';
      array[3] = '0';
      break;
      case 6:
      array[0] = '0';
      array[1] = '1';
      array[2] = '0';
      array[3] = '1';
      break;
      case 7:
      array[0] = '0';
      array[1] = '1';
      array[2] = '1';
      array[3] = '1';

      break;
      case 8:
      array[0] = '0';
      array[1] = '1';
      array[2] = '1';
      array[3] = '0';
      break;
      case 9:
      array[0] = '1';
      array[1] = '1';
      array[2] = '0';
      array[3] = '0';
      break;
      case 10:
      array[0] = '1';
      array[1] = '1';
      array[2] = '0';
      array[3] = '1';
      break;
      case 11:
      array[0] = '1';
      array[1] = '1';
      array[2] = '1';
      array[3] = '1';
      break;
      case 12:
      array[0] = '1';
      array[1] = '1';
      array[2] = '1';
      array[3] = '0';
      break;
      case 13:
      array[0] = '1';
      array[1] = '0';
      array[2] = '0';
      array[3] = '0';
      break;
      case 14:
      array[0] = '1';
      array[1] = '0';
      array[2] = '0';
      array[3] = '1';
      break;
      case 15:
      array[0] = '1';
      array[1] = '0';
      array[2] = '1';
      array[3] = '1';
      break;
      case 16:
      array[0] = '1';
      array[1] = '0';
      array[2] = '1';
      array[3] = '0';
      break;
      default:
      break;
      }//switch

      //cout<<count1<<endl;
      for (int i = 0; i < 4; i++)
      {
      mint1[c1] = array;

      }//for

      c1=c1+1;
      //cout<<endl;
      }//if
      }//while

      if (c1<16)
      {
      //display minterm1
      cout<<endl;
      cout<<" You have entered:"<<endl<<endl;
      for (int x = 0; x<(c1); x++){
      cout<<" ";
      for (int y=0; y<4; y++)
      cout<<mint1[x][y]<<" ";
      cout<<endl;}

      check = processMinterm(mint1, c1);
      if (check>0)
      {
      while (check>0)
      {
      for (int in1=0; in1<check; in1++)
      for (int in2=0; in2<4; in2++)
      mint2[in1][in2] = mintermAll[in1][in2];

      count=check;
      check = processMinterm(mint2,count);

      }//while
      }//if
      //display final
      //cout<<endl;
      /* cout<<"final"<<endl;
      for (int c = 0; c<countf; c++){
      {for (int d=0; d<4; d++)
      cout<<final[c][d];}
      cout<<endl;}
      */
      cout<<endl<<"Final answer: ";
      for (int c = 0; c<countf; c++)
      {
      switch (final[c][0])
      {
      case '1':
      cout<<"A";
      break;
      case '0':
      cout<<"A'";
      break;
      case '-':
      cout<<"";
      }
      switch (final[c][1])
      {
      case '1':
      cout<<"B";
      break;
      case '0':
      cout<<"B'";
      break;
      case '-':
      cout<<"";
      }
      switch (final[c][2])
      {
      case '1':
      cout<<"C";
      break;
      case '0':
      cout<<"C'";
      break;
      case '-':
      cout<<"";
      }
      switch (final[c][3])
      {
      case '1':
      cout<<"D";
      break;
      case '0':
      cout<<"D'";
      break;
      case '-':
      cout<<"";
      }
      if (c!=(countf-1))
      cout<<" + ";

      }//for
      cout<<endl<<endl;

      }

      else
      cout<<endl<<"Final answer = 1"<<endl;


      }//main


      int processMinterm(char minterm1[][4], int count1)
      {
      char minterm2[30][4],array2[4];
      int count3=0, count2;

      for (count2 = 0; count2 < (count1); count2++){

      int fdiff=0;
      for (int j = 0; j < (count1); j++)
      {
      int same=0, diff=0;
      for (int k = 0; k < 4; k++)
      {
      if (minterm1[count2][k] == minterm1[j][k])
      same=same+1;
      else
      diff=diff+1;

      }//nested nested for

      if (diff!=1)
      fdiff++;

      //cout<<endl;
      //cout<<same<<" "<<diff<<endl;
      //cout<<endl;


      if (diff==1)
      {
      for (int l = 0; l < 4; l++)
      {
      if (minterm1[count2][l] == minterm1[j][l])
      array2[l] = minterm1[j][l];
      else
      array2[l] = '-';
      }//for

      if (count3>0)
      {
      int s=0;
      int m = 0;

      while ( m < count3 && s!=4)
      {

      while (s!=4)
      {
      if (m>0)
      s=0;

      if (m == count3)
      {
      for (int p = 0; p < 4; p++)
      minterm2[count3][p] = array2[p];

      count3=count3+1;
      m++;
      s=4;
      }

      else
      {
      for (int n = 0; n < 4; n++)
      {
      if (array2[n] == minterm2[m][n])
      s=s+1;

      }//nested for
      m++;
      }
      //cout<<"s:"<<s<<endl;
      //same2=s;

      //if(same2!=4)
      // cout<<"in"<<endl;

      }//while

      }//for

      }//if

      else
      {
      for (int q = 0; q < 4; q++)
      minterm2[count3]
      quote:

      = array2
      quote:

      ;

      count3=count3+1;

      }

      }//if



      }//nested for

      //cout<<"fdiff:"<<fdiff<<endl<<endl;

      if (fdiff==(count1))
      {
      for(int f=0; f<4; f++)
      final[countf][f] = minterm1[count2][f];
      countf++;
      }

      /* cout<<endl;
      cout<<"minterm2"<<endl;
      for (int a = 0; a<count3; a++){
      {for (int b=0; b<4; b++)
      cout<<minterm2[a] ;}
      cout<<endl;}
      */

      }//for

      if (count3>0)
      {
      for (int n1=0; n1<count3; n1++)
      for (int n2=0; n2<4; n2++)
      mintermAll[n1][n2] = minterm2[n1][n2];


      }//if
      /* cout<<endl;
      cout<<"mintermAll"<<endl;
      for (int a = 0; a<count3; a++){
      {for (int b=0; b<4; b++)
      cout<<mintermAll[a]
      ;}
      cout<<endl;}
      */


      return count3;
      }