LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-03-2005, 08:11 PM   #1
leanieleanz
LQ Newbie
 
Registered: Mar 2005
Posts: 7

Rep: Reputation: 0
Question Convert Java to C++?


Is it possible to convert java programming code to c++ code? I have a C++ program I need to turn in but did it in java first because that is what I know. I then go through and convert it manually...it makes it easier for me. Is there a way I can just convert the code with a tool?????? I use .NET

Any input is greatly appreciated as the program is due in a couple days
 
Old 03-03-2005, 10:08 PM   #2
BubaDragon
LQ Newbie
 
Registered: Jan 2005
Location: Texas
Distribution: Suse 9.2 Professional
Posts: 5

Rep: Reputation: 0
Microsoft makes a Java to C# conversion tool. Also ANTLER (a parser-parser) has some languages that may do the trick. However, it looks like you are under the gun with a deadline. I suggest that you make a pot of coffee and get to work. Fortunetly Java to C++ is fairly straightforward, not like Java to ... COBOL?

Hope this helps..
 
Old 03-04-2005, 07:29 AM   #3
leanieleanz
LQ Newbie
 
Registered: Mar 2005
Posts: 7

Original Poster
Rep: Reputation: 0
Okay thanks BubaDragon....but what is the Microsoft conversion tool called and how do I get it? That would help! Unless you just want to do it for me (joke)
Thanks!!
 
Old 03-04-2005, 09:13 AM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
I don't think converting your Java to C# would be of much help... as C# and C++ are just about as different as Java and C++.

It seams to me, if you know Java well you should have the design philosophies down pretty well. If that is the case, then largely all your dealing with is syntax differences (ok... some other differences as well, but nothing that should be past your understand)... You'd probably be doing yourself a bigger favor if you got ride of your dependence on Java and just did everything from scratch in C++. It might be a little painful at first... but it is probably better for your learning.

The mark of a good programmer isn't his/her ability to code in a particular language.. it is his/her understand of programming and datatypes in general, and his/her ability to quickly pick up a new language in a new environment.
 
Old 03-04-2005, 09:46 AM   #5
leanieleanz
LQ Newbie
 
Registered: Mar 2005
Posts: 7

Original Poster
Rep: Reputation: 0
I am okay with C++ but not when it comes to array's. I am having a very hard time programming with arrays in C++! It is my only C++ class and I am not worried about knowing how to be a C++ programmer....since my bachelors is on Open Systems Technology (Linux administration) So it is very stressful trying to figure it out, thats why I would love to use a converter. The tutor that usually helps me out is on vacation

My code is as follows:

PHP Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <iomanip>
using std::setw;

void assignPassenger();
int checkFlight(intchar);
void printInfo();

int flight_number;
char class_type;
char repeat;
char first_name[10], second_name[10];
int priceE 0priceF 0total_income;

    
int f1[10] = {0};
    
int f2[10] = {0};
    
int f3[10] = {0};
    
int availability;

int main()
{

    
char new_passenger;

        
cout << "Do you want to assign a passenger ? " << "\t";
        
cin >> new_passenger;

    while (
new_passenger == 'y' || new_passenger == 'Y')
    {
        
assignPassenger();
        if(
availability == 0)
        {
            
cout << "Do you want to assign a new passenger ? " << "\t";
            
cin >> new_passenger;
        }
        else
        {
            
cout << "Sorry, all the three flights are full" << endl;
            break;
        }
    }
    
cout << "The total income of the economy class = " << priceE << endl;
    
cout << "The total income of the first class = " << priceF << endl;
    
total_income priceE priceF;
    
cout << "The total income of the three flights = " << total_income << endl;
    
cout << "__________________________________________________________" << endl << endl;
    
cout << "You will see now how the three flight's seats look like (1 = reserved , 0 = empty)" << endl;
    
printInfo ();

return 
0;

}

     

     

     
void printInfo()
    {

    
cout << setw(20) << "Flight Number / Seat number";
    
cout << setw(3) << "1" << setw(3) << "2" << setw(3) << "3" << setw(3) << "4" << setw(3) << "5";
    
cout << setw(3) << "6" << setw(3) << "7" << setw(3) << "8" << setw(3) << "9" << setw(3) << "10" << endl << endl;
    
cout << setw(15) << "flight 1";
    
cout << setw(15) << f1[0] << setw(3) << f1[1] << setw(3) << f1[2] << setw(3) << f1[3] << setw(3) << f1[4];
    
cout << setw(3) << f1[5] << setw(3) << f1[6] << setw(3) << f1[7] << setw(3) << f1[8] << setw(3) << f1[9] << endl;
    
cout << setw(15) << "flight 2";
    
cout << setw(15) << f2[0] << setw(3) << f2[1] << setw(3) << f2[2] << setw(3) << f2[3] << setw(3) << f2[4];
    
cout << setw(3) << f2[5] << setw(3) << f2[6] << setw(3) << f2[7] << setw(3) << f2[8] << setw(3) << f2[9] << endl;
    
cout << setw(15) << "flight 3";
    
cout << setw(15) << f3[0] << setw(3) << f3[1] << setw(3) << f3[2] << setw(3) << f3[3] << setw(3) << f3[4];
    
cout << setw(3) << f3[5] << setw(3) << f3[6] << setw(3) << f3[7] << setw(3) << f3[8] << setw(3) << f3[9] << endl;

    }


    
void assignPassenger()
    {


        do
        {

        
cout << "Enter your flight number(1 or 2 or 3) :" << "\t";
        
cin >> flight_number;
        
cout << "Enter the class type(e or f) :" << "\t";
        
cin >> class_type;

        
availability checkFlight(flight_numberclass_type);

        if (
availability == 0)
        {
            
cout << "Enter you first name:" << "\t";
            
cin >> first_name;
            
cout << "Enter your second name:" << "\t";
            
cin >> second_name;

            if (
class_type == 'e')
                
priceE += 800;
            else
                
priceF += 1200;
        }

        else
        {
            
cout << "sorry, the the flight is full, Do you want to assign a seat in the same flight but in another class" << endl;
            
cout << "or assign a seat in another flight?" << endl;
            
cin >> repeat;
        }
        }

            while (
repeat == 'y' || repeat == 'Y');


    }

    
int checkFlight(int flight_numberchar class_type)
    {
        
int full 1;
        
int i;

        if (
flight_number == && class_type == 'f')
        {

            for (
i++)
            {
                if (
f1[i] == 0)
                {
                    
full 0;
                    
f1[i] = 1;
                }

                if (
full == 0)
                    break;

            }
        }

        else if (
flight_number == && class_type == 'e')
        {

            for (
10 i++)
            {
                if (
f1[i] == 0)
                {
                    
full 0;
                    
f1[i] = 1;
                }

                if (
full == 0)
                    break;

            }
        }
///////////////////////////////////////////////////////////////////

        
else if (flight_number == && class_type == 'f')
        {

            for (
i++)
            {
                if (
f2[i] == 0)
                {
                    
full 0;
                    
f2[i] = 1;
                }

                if (
full == 0)
                    break;

            }

        }
        else if (
flight_number == && class_type == 'e')
        {

            for (
10 i++)
            {
                if (
f2[i] == 0)
                {
                    
full 0;
                    
f2[i] = 1;
                }
                if (
full == 0)
                    break;

            }
        }
/////////////////////////////////////////////////////////////////////


        
else if (flight_number == && class_type == 'f')
        {

            for (
i++)
            {
                if (
f3[i] == 0)
                {
                    
full 0;
                    
f3[i] = 1;
                }

                if (
full == 0)
                    break;

            }

        }
        else if (
flight_number == && class_type == 'e')
        {

            for (
10 i++)
            {
                if (
f3[i] == 0)
                {
                    
full 0;
                    
f3[i] = 1;
                }

                if (
full == 0)
                    break;
            }

        }
        return 
full;

        } 
 
Old 03-04-2005, 11:37 AM   #6
leanieleanz
LQ Newbie
 
Registered: Mar 2005
Posts: 7

Original Poster
Rep: Reputation: 0
Anyone want to make a few bucks converting it let me know.
 
Old 03-04-2005, 12:14 PM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Your C++ program is lacking comments ...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java plugin installed correctly for Firefox but not able to view any java applet tvn Linux - Software 10 04-15-2010 02:13 AM
is there any tool avilable to convert java/sql code into asp.net/sql2000 rddreamz Programming 1 11-08-2004 02:16 PM
Web start java not working (java works fine) powadha Debian 5 06-05-2004 12:57 PM
can't convert o to FLoat in Java alaios Programming 4 04-24-2004 02:10 PM
How to convert a Java Program into.... anoop_chandran Programming 18 12-03-2001 05:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration