Results 1 to 5 of 5

Thread: pls convert this c++ to java code

  1. #1
    Join Date
    Nov 2010
    Posts
    7

    pls convert this c++ to java code

    Please help me to convert C++ program in Java code...
    I am putting C++ code below

    Code:
    #include <stdio.h> // for input/output operations
    
    #ifndef hr_timer
    #include "hr_time.h"
    #define hr_timer
    #endif
    
    char map[50][88]; // the map... the input file will be stored here
    int island_area[20]; // array to store the various island's area
    int island; // variable to store the number of islands found
    int area; // temporary variable to store the + count for each island
    
    
    // find a piece of land to start from.
    int find(int* row, int* col)
    {
    int i, j;
    for(i = 2; i < 83; i++)
    {
    for(j = 0; j < 50; j++)
    {
    if(map[j][i] == '+')
    {
    *row = j;
    *col = i;
    return 1;
    }
    }
    }
    return 0;
    }
    
    
    // look for more land, given a piece
    int count(int row, int col)
    {
    // if it's either out of bounds or on sea, it is not land
    if(row > 49 || col < 3 || col > 82 || map[row][col] != '+')
    {
    return 0;
    }
    // else, we found another bit, and will keep looking
    else
    {
    map[row][col] = '-';
    area++;
    
    if(count(row + 1, col )) return 1; // S
    if(count(row + 1, col + 1)) return 1; // SE
    if(count(row , col + 1)) return 1; // E
    if(count(row - 1, col + 1)) return 1; // NE
    if(count(row - 1, col )) return 1; // N
    if(count(row - 1, col - 1)) return 1; // NW
    if(count(row , col - 1)) return 1; // W
    if(count(row + 1, col - 1)) return 1; // SW
    }
    
    // if there is none around, we looked everywhere....
    return 0;
    }
    
    
    int main()
    {
    int index;
    FILE * input;
    int row, col;
    
    stopWatch tick;
    
    
    // open the input (text)file for reading operations
    input = fopen("E:\\PC2\\map.txt", "rt");
    startTimer(&tick);
    /* lets assume there's no problem
    
    if(!input)
    {
    printf("error opening input file");
    getint();
    return (1);
    }*/
    
    // read the lines from the input file to a
    // bidimensional array (interpreted as a map)
    for(index = 0; index < 50; index++)
    {
    fgets(map[index], 88, input);
    }
    
    // i'm pretty sure this should be the only part being clocked,
    // as this is actually where i start solving the problem itself
    
    while(find(&row, &col)) // while there's a piece of land not scanned
    {
    area = 0;
    count(row, col); // i'll start counting the + in it
    island_area[++island] = area; // and store the count
    }
    
    printf("There are %d Continents\n", island);
    for(index = 1; index < island + 1; index++)
    {
    printf("Continent %d has %d .\n", index, island_area[index]);
    }
    
    stopTimer(&tick);
    printf("took %12.10f secs\n", getElapsedTime(&tick));
    
    // close the input file, as it is no longer needed
    fclose(input);
    
    getchar();
    return (0);
    }
    Please anyone convert this C++ program into Java as soon as possible.

    Thanks in advance

  2. #2
    Join Date
    Nov 2008
    Posts
    1,192

    Re: pls convert this c++ to java code

    Did you tried the coding in Java and are you aware about JAVA programming? Where have been stuck or you got any error message? The program that you are asking for requires a lot of practice because it is related to computer graphics. In JAVA you can also code a similar kind of program but the thing is that I would recommend you to try it on your own. We can't code it for you everything. If, however, you need help you can ask us at any point of time and we are here to help you. You can even read some books if you don't have any expertise in this fields. Some of the books which deals in Computer Graphics include "Introduction to Computer Graphics", "Computer Graphics for Java Programmers".

  3. #3
    Join Date
    Nov 2010
    Posts
    7

    Re: pls convert this c++ to java code

    Our school is using JAVA, that code is our project and now , I searched in the internet about it . The problem is that the source code is c++ and I do not know how to convert it to JAVA . They never discussed the c++ in our school that's why I do not know what the code is equivalent to JAVA code .

    Please make a way to convert it to java because the DEADLINE is coming .
    Thank You.

  4. #4
    Join Date
    Nov 2010
    Posts
    7

    Re: pls convert this c++ to java code

    By the way , that is not c++ its a C .
    Sorry for the inconvenience .

  5. #5
    Join Date
    Mar 2012
    Posts
    1

    Re: pls convert this c++ to java code

    #include<iostream.h>
    #include<conio.h>
    #include<stdio.h>
    #include<math.h>
    int main()
    {

    // INPUT parameters

    float power,gr,z1,z2,n1,y1,y2,ag,sigmaci,sigmas,sigmas1,sigmac1;
    int zi,zs,zc;
    float fw,fs,vm,Vm,ft,fd,cv,fd1,ef,fe,fo,ab,rg;
    //for material properties

    int ci[3][2]={{460,5000},{550,6000},{750,7500}},st[3][2]={{1350,5000},{3000,9500},{3800,11000}};

    cout<<"enter the value of Z1 = ";
    cin>>z1;
    cout<<"enter the value of Z2 = ";
    cin>>z2;
    cout<<"enter the power = ";
    cin>>power;
    cout<<"enter the RPM of pinion = ";
    cin>>n1;
    gr=z2/z1;
    //cout<<"the gear ratio will be = "<<gr;


    cout<<"\nenter the type \n1. involute \n 2. stub teeth\n";
    cin>>zi;
    if(zi==1)
    {
    cout<<"enter the value of Angle = ";
    cin>>ag;

    if(ag==14.5)
    {
    y1=(0.124-(0.864/z1));
    y2=(0.124-(0.864/z2));
    fe=7850*22.5;
    fo=1;
    }
    else if(ag==20)
    {
    y1=(0.154-(0.912/z1));
    y2=(0.154-(0.912/z2));
    fe=8150*22.5;
    fo=1;
    }
    }
    else if(zi==2)
    {
    y1=(0.175-(0.95/z1));
    y2=(0.175-(0.95/z2));
    fe=8450*22.5;
    fo=0.8;
    }

    //for cast iron

    cout<<"\nenter the grade for gear :- ";
    cout<<"\n1. Grade 20 \n2. Grade 25\n3. Grade 35\n";
    cin>>zc;
    if(zc==1)
    {
    sigmaci=ci[zc][0];
    sigmac1=ci[zc][1];
    }
    else if(zc==2)
    {
    sigmaci=ci[zc][0];
    sigmac1=ci[zc][1];
    }
    else if(zc==3)
    {
    sigmaci=ci[zc][0];
    sigmac1=ci[zc][1];
    }
    float P,Q;
    P=sigmaci*y2;

    //for steel

    cout<<"\nenter the grade for pinion :- ";
    cout<<"\n1. C 45 \n2. 15 Ni 2 Cr 1 Mo 15\n3. 40 Ni 2 Cr 1 Mo 28\n";
    cin>>zs;
    if(zs==1)
    {
    sigmas=st[zs][0];
    sigmas1=st[zs][1];

    }
    else if(zs==2)
    {
    sigmas=st[zs][0];
    sigmas1=st[zs][1];
    }
    else if(zs==3)
    {
    sigmas=st[zs][0];
    sigmas1=st[zs][1];
    }
    Q=sigmas*y1;

    // Design basis


    double a,b=0,c,d,e,f,g,h,i,j,k,l,m,n,p,r,s,t,u,x1,x2,x3;

    int w;
    printf("\nThe cubic equation is of type a*x^3+b*x^2+c*x+d \n");
    if(P<Q)
    {
    cout<<"\n Design for strength and check for wear \n";

    a=39.47*P;
    c=(-25)*power;
    d=((-23.87)*power)/(n1*z1);
    e=2.7182818284590;
    f=((3*c/a)-(b*b/(a*a)))/3;
    g=((2*b*b*b/(a*a*a))-(9*b*c/(a*a))+(27*d/a))/27;
    h=(g*g/4)+(f*f*f/27);
    i=sqrt(((g*g/4)-h));
    j=exp(log10(i)/log10(e)/3);
    k=acos((-1)*(g/(2*i)));
    l=j*(-1);
    m=cos(k/3);
    n=sqrt(3)*sin(k/3);
    p=(b/3*a)*(-1);
    r=(-1)*(g/2)+sqrt(h);
    s=exp(log10(r)/log10(e)/3);
    t=(-1)*(g/2)-sqrt(h);
    u=exp(log10(t)/log10(e)/3);
    if (h>0) w=1;
    if (h<=0) w=3;
    if ((f==0) && (g==0) && (h==0)) w=2;
    switch (w)
    {
    case 1:
    x1=(s+u)-(b/3*a);
    x2=(-1)*(s+u)/2-(b/3*a);
    x3=(s-u)*sqrt(3)/2;
    //cout<<"x1 = "<<x1;
    printf("\nA 3 pont:\n%lf\n%lf +i*%lf\n%lf -i*%lf", x1, x2, x3, x2, x3);
    break;
    case 2:
    x1=exp(log10(d/a)/log10(e)/3)*(-1);
    printf("\n\n%lf", x1);
    break;
    case 3:
    x1=2*j*cos(k/3)-(b/3*a);
    x2=l*(m+n)+p;
    x3=l*(m-n)+p;
    //cout<<"x1 = "<<x1;
    printf("\nMODULE are :- \n%lf\n%lf\n%lf", x1, x2, x3);
    break;
    }



    }
    else
    {
    cout<<"\n Design for wear and check for strength \n";

    a=(1.2)*(z1*z1)*n1*gr*sigmas1*sigmas1;
    c=(1414*1000)*(gr+1)*n1*z1*(-1)*power;
    d=(-1)*8.1*power*(gr+1)*pow(10,9);

    e=2.7182818284590;
    f=((3*c/a)-(b*b/(a*a)))/3;
    g=((2*b*b*b/(a*a*a))-(9*b*c/(a*a))+(27*d/a))/27;
    h=(g*g/4)+(f*f*f/27);
    i=sqrt(((g*g/4)-h));
    j=exp(log10(i)/log10(e)/3);
    k=acos((-1)*(g/(2*i)));
    l=j*(-1);
    m=cos(k/3);
    n=sqrt(3)*sin(k/3);
    p=(b/3*a)*(-1);
    r=(-1)*(g/2)+sqrt(h);
    s=exp(log10(r)/log10(e)/3);
    t=(-1)*(g/2)-sqrt(h);
    u=exp(log10(t)/log10(e)/3);
    if (h>0) w=1;
    if (h<=0) w=3;
    if ((f==0) && (g==0) && (h==0)) w=2;
    switch (w)
    {
    case 1:
    x1=(s+u)-(b/3*a);
    x2=(-1)*(s+u)/2-(b/3*a);
    x3=(s-u)*sqrt(3)/2;
    //cout<<"x1 = "<<x1;
    printf("\nMODULE are :- \n%lf\n%lf +i*%lf\n%lf -i*%lf", x1, x2, x3, x2, x3);
    break;
    case 2:
    x1=exp(log10(d/a)/log10(e)/3)*(-1);
    printf("\n\n%lf", x1);
    break;
    case 3:
    x1=2*j*cos(k/3)-(b/3*a);
    x2=l*(m+n)+p;
    x3=l*(m-n)+p;
    //cout<<"x1 = "<<x1;
    printf("\nA 3 pont:\n%lf\n%lf\n%lf", x1, x2, x3);
    break;
    }


    }

    if(x1<0.1||x1>2)
    {
    cout<<"\n ERROR !!!! ";
    }
    else
    {
    int mec=1;
    while(mec==1)
    {

    x1=x1*10;
    float table[14]={1,1.25,1.5,2,2.5,3,4,5,6,8,10,12,16,20},nm;
    for(int y=1;y<=13;y++)
    {
    if(x1>table[y-1]&&x1<=table[y])
    {
    x1=table[y];
    nm=table[y+1];

    break;
    }
    }

    //cout<<" new x1 = "<<x1;


    x1=x1/10;
    vm=(3.14*n1*x1*z1)/6000;
    Vm=vm*60;
    ef=fe/Vm;
    ft=(power*75)/vm;
    cv=(1+(vm/3));
    fd=ft*cv;
    ab=0.164*Vm*((ef*4*3.14*x1)+ft);
    rg=(0.164*Vm)+(1.485*(sqrt((ef*4*3.14*x1)+ft)));
    fd1=ft+(ab/rg);
    printf("\n BUCKINGHAM DYNAMIC LOAD = %lfkgf",fd1);

    cout<<"\n new module = "<<x1;
    if(P<Q)
    {
    fw=(sigmas1*sigmas1*1.685*sin(ag)*x1*z1*gr)/(1000000*(gr+1));
    cout<<"\n wear force Fw = "<<fw<<" KgF";
    }
    else
    {
    fs=4*Q*3.14159*3.14159*x1*x1;
    cout<<"\n Fs = "<<fs<<" KgF";
    }

    if(P<Q)
    {

    if(fw>=fd&&fw>=fd1)
    {
    cout<<"\n SAFE ";
    mec=2;
    }
    else
    {
    cout<<"\n UNSAFE ";
    mec=1;
    nm=nm/10;
    x1=nm;
    }
    }
    else
    {
    if(fs>=fd&&fs>=fd1)
    {
    cout<<"\n SAFE ";
    mec=2;
    }
    else
    {
    cout<<"\n UNSAFE ";
    mec=1;
    nm=nm/10;
    x1=nm;
    }
    }
    }

    printf("\n BASIC DIMENSIONS:-\n");
    float module;
    module=x1*10;
    printf("\n Module= %lfmm",module);
    float cd;
    cd=(0.5*module*(z1+z2));
    printf("\n Centre Distance = %lfmm",cd);
    float bc,pd1,pd2,td,da1,da2,df1,df2;
    if(fo==1)
    {
    bc=0.25*module;
    }
    else
    {
    bc=0.3*module;
    }
    printf("\n Bottom Clearance = %lfmm",bc);
    if(fo==1)
    {
    td=2.25*module;
    }
    else
    {
    td=1.9*module;
    }
    printf("\n Tooth Depth = %lfmm",td);
    pd1=module*z1;
    pd2=module*z2;
    printf("\n Pitch Diameter di= %lfmm",pd1);
    printf("\n Pitch Diameter d2= %lfmm",pd2);
    da1=(z1+(2*fo))*module;
    da2=(z2+(2*fo))*module;
    df1=(((z1-(2*fo))*module)-(2*bc));
    df2=(((z2-(2*fo))*module)-(2*bc));
    printf("\n Tip Diameter da1 = %lfmm",da1);
    printf("\n Tip Diameter da2 = %lfmm",da2);
    printf("\n Root Diameter df1 = %lfmm",df1);
    printf("\n Root Diameter df2 = %lfmm",df2);
    }
    getch();
    return(0);
    }

Similar Threads

  1. Convert C++ Program to Java Code!! Please help
    By jessesaini in forum Software Development
    Replies: 1
    Last Post: 24-04-2012, 12:24 AM
  2. Convert C++ code into JAVA
    By Macario in forum Software Development
    Replies: 6
    Last Post: 13-11-2011, 07:36 PM
  3. Need help to convert c++ to java code program
    By xSim21 in forum Software Development
    Replies: 2
    Last Post: 27-11-2010, 04:42 PM
  4. Convert a Java Bean Code
    By KALYAN23 in forum Software Development
    Replies: 5
    Last Post: 02-08-2010, 10:34 AM
  5. convert C++ program in Java code
    By vaibhavsri in forum Software Development
    Replies: 7
    Last Post: 16-07-2010, 10:08 AM

Tags for this Thread

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
  •  
Page generated in 1,711,724,440.27156 seconds with 17 queries