| | |
java---->c++
Thread Solved |
Good day. How do i convert the following code to C++?
java Syntax (Toggle Plain Text)
// Lets import our file functions. import java.io.*; public class Grades { // Setup an array of test students private static Grades.test student[] = new Grades.test[50]; // Just for spunk we will create an inner class to keep this in one file. private static class test { public String id = ""; public String answer = ""; public double score = 0.0; public double grade = 0.0; } public static void main(String args[]) { int total=0; // initialize(); This was removed because we initialize when we create students. getdata(); int i = 1; // Loop through students until we reach our 50 limit or there were not that many in our class to begin with. while ((i < student.length - 1) && (student[i] != null)) { total = 0; for(int j = 0; j < 22; j++) { // Here we are going to check student answer against "master key" student (at index 0) if(student[0].answer.substring(j,j+1).equals(student[i].answer.substring(j,j+1))) { total = total + 5; } else if(student[i].answer.substring(j,j+1).equals(" ")) { total = total - 4; } else { total = total - 2; } } // Obviously if they end up leaving all blank or go negative, they get a zero for the grade. if (total < 0) { total = 0; } // Here we print out the student id, their answers and total points (not grade point average!) System.out.println(student[i].id + " " + student[i].answer + " " + total); i++; } } // This fills our students answers from file. private static void getdata() { try { // We setup a reader to read in text file students and answers. BufferedReader infile = new BufferedReader(new FileReader("tftest.txt")); String id = ""; String answers = ""; // We loop until we get all 50 students for (int i = 0; i < student.length - 1; i++) { // Or until we hit the end of the line on our file. if (((id = infile.readLine()) != null) && ((answers = infile.readLine()) != null)) { student[i] = new Grades.test(); student[i].id = id; student[i].answer = answers; } else { break; } } infile.close(); } catch (IOException e) { System.out.println(e.toString()); } } }
•
•
•
•
..in other words, i heard that the two languages are similar and are different in other respects(such as speed and efficiency). What i was reffering to was are the commands the same, headers, mathematical calculations...ect....I didn't need you to convert the entire program...i'm not studying java.
Some key words are the same. Java doesn't have headers. Many math calculations are the same, though Java does not allow for operator overlading.
If you expect to convert the code from Java to C++, you are obviously going to need to study a little bit of Java. That would require some homework on your part... though it seems like it would be easier to just do your own C++ homework instead of trying to convert someone else's Java homework into C++
![]() |
Similar Threads
- Java 3D Environment (Java)
- Java 3D (Java)
- Java Expert (Needed) (Java)
- Java Chat Reboots (Java)
Other Threads in the Java Forum
- Previous Thread: Help with ending a program
- Next Thread: SOAP-XML-Exceptions
| Thread Tools | Search this Thread |
-xlint add android api applet application applications array arrays automation bank bi binary blackberry bluetooth chat class client code compile compiler component database development digit eclipse equation error event fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image infinite input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying pearl problem program programming project qt recursion scanner screen scrollbar server set sms sort sorting spamblocker sql sqlserver string superclass swing system text-file thread threads tree variablebinding windows xor






