SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Convert C++ to PHP/HTML

    Can anyone help me how to Convert this Code to A PHP program


    Code:
    /*Banker safety Algorithm
    
    #include < iostream >
    using namespace std;
    #define MAX 200 // Maximum no of process & Resource type
    int main()
    {
    	int Allocation[MAX][MAX],Maxi[MAX][MAX],Available[MAX],Need[MAX][MAX],n,m,i,j,Work[MAX],Safe[MAX],l,k;
    	bool Finish[MAX];
    	while(printf("\nInput No of process & No of resource type: "),~scanf("%d%d",&n,&m))//n=no of process;m=no of resource type
    	{
    		printf("Input Allcation Matrix :\n");
    		for(i=0;i<n;i++)
    			for(j=0;j<m;j++)
    				scanf("%d",&Allocation[i][j]);
    
    		printf("Input Max Matrix :\n");
    		for(i=0;i<n;i++)
    			for(j=0;j<m;j++)
    				scanf("%d",&Maxi[i][j]);
    
    		printf("Input Available for each resource type:\n");
    		for(j=0;j<m;j++)
    			scanf("%d",&Available[j]);
    
    		// Create Need matrix for each process
    		for(i=0;i<n;i++)
    			for(j=0;j<m;j++)
    				Need[i][j]=Maxi[i][j]-Allocation[i][j];
    
    		//initialize work & finish
    		for(i=0;i<m;i++)
    			Work[i]=Available[i];
    		for(i=0;i<n;i++) Finish[i]=false;
    
    		l=0;
    
    		int  loop,start=0;bool f;
    
    		//STEP 2 FOR BANKERS ALGORITHM
    step2:
    			for(i=start,loop=0;loop<n;i++,loop++)
    			{
    				if(i==n)
    					i=0;
                    f=false;
    				if(Finish[i]==false)
    				{
                        for(j=0;j<m;j++)
    					if(Need[i][j]>Work[j])
    						f=true;
                        if(f==false)
    					goto step3;
    				}
    			}
    			if(f==false)
    			goto step4;
    
             //STEP 3 FOR BANKERS ALGORITHM
    step3:
               Safe[l++]=i;
    			for(k=0;k<m;k++)
    				Work[k]+=Allocation[i][k];
    			Finish[i]=true;
    			start=i+1;
                goto step2;							
    
                //STEP 4 FOR BANKERS ALGORITHM
    step4:
    				for(i=0;i<n;i++)
    					if(Finish[i]==false)
    						printf("System is not in Safe state\n");
    				if(i==n)
    				{
    					printf("System is in Safe state\nThe sequence of process is to be execute:");
    					for(i=0;i<l;i++)
    						printf(" %d ",Safe[i]);
    					printf("\n");
    				}
    
    }
    return 0;
    }

  2. #2
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    That looks like a fairly straight-forward task, if you know a minimum of PHP. I'd recommend taking a look at a PHP tutorial and the PHP documentation.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  3. #3
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by C. Ankerstjerne View Post
    That looks like a fairly straight-forward task, if you know a minimum of PHP. I'd recommend taking a look at a PHP tutorial and the PHP documentation.



    i know a minimum of PHP but I dont know how to covert a C to a PHP..
    where you are going to input number of rows and columns in textfield
    and the textfield will have its unique ID..

    hope that you will help me

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Well see that is your problem you are trying to convert existing code. What you should be doing is writing new code in PHP the has the same result.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •