Find Jobs
Hire Freelancers

Converting Java to C++ code

$10-30 USD

Finalizat
Data postării: peste 7 ani în urmă

$10-30 USD

Plata la predare
I have a java code that needs to work in C++ This is what the code should do: Define a struct called "Car" with the following member variables:  Total Odometer Miles  Speed in miles per hour  Driver Name  Sponsor  Car Number You should also include the following functions:  A function to make progress down the course  A function to convert your speed from MPH to MPS  A function to “pretty print” your car’s information including Number, Sponsor, Driver and Progress  A function to re-randomize speed  Include any useful functions you might need to accomplish the goal The total odometer miles should be initialized to zero, and speed initialized to a random value between 60 and 120. Create a list of 20 vehicles with driver and sponsor names. You should not re-use a driver name or sponsor name (note – worry about this specification last, if you can make the race work w/o this, that’s better than getting hung up on this algorithm) Your main program should simulate the progress of the vehicles in the race. You should accomplish this with a loop. Every 5 iterations of the loop (should be considered 1 minute of time), the vehicles pick a new random speed. Every iteration through the loop their odometer miles are updated: odometer_miles = odometer_miles + speed*time Since speed is in miles per hour, time should be in hours as well (1 minute is 1/60th of an hour). Remember for the sake of this assignment 1 minute = 5 loop iterations. The first car to reach the race’s limit (100 miles is a good number) should be declared the winner by printing the driver name and sponsor name. You should set this as a variable – consider asking the user for the value as well. --------------------------------------------------------------Code below----------------------------------------------------- import java.util.*; import java.io.*; import java.lang.*; //CLASS CAR class Car { //DECLARE VARIABLES double odometer_miles; double speed; String DriverName; String sponsorName; int carNumber; ///CONSTRUCTOR public Car(String dName,String sName,int carNo) { odometer_miles=0; generateRandomSpeed(); DriverName=dName; sponsorName=sName; carNumber=carNo; } //UPDATE THE TOTAL ODOMETER MILES public void updateOdometerMiles() { odometer_miles=odometer_miles+(convertSpeed()); } //GET THE MILES RUN public double getOdometerMiles() { return odometer_miles; } //CONVERT mph TO mps public double convertSpeed() { return speed*0.44704; } //GENERATE RANDOM SPEED IN 60 T0 120 public void generateRandomSpeed() { Random r=new Random(); speed=60.00+(120.00-60.00)*[login to view URL](); } //OVERRIDDEN toString() public String toString() { String s; s="Car Number:"+carNumber+"\n Driver Name:"+DriverName+" \n Sponsor NAme:"+sponsorName+"\n Odometer Miles:"+odometer_miles; return s; } } public class CARRACE { //MAIN METHOD public static void main(String[] args) { //CREATE CAR LIST TO HOLD 20 VEHICLES Car[] carList=new Car[20]; //STRING ARRAY FOR DRIVER NAME String[] drivers={"JK","Jerry","fermin","jude"}; String[] sponsors={"A","B","C","D","E"}; //STRING ARRAY FORSPONSORS Random r=new Random(); for(int k1=0;k1<20;k1++) { //ADD VEHICLE TO THE CARLIST carList[k1]=new Car(drivers[[login to view URL](4)],sponsors[[login to view URL](5)],k1+1); } boolean reached=false; //CHECK FOR THE WINNER while(!reached) { for(int k2=0;k2<20;k2++) { //CHECK IF ANY OF THE CAR REACHED 100 MILES IF SOPRINT THE CAR //INFORMATION THEN EXIT THE PROGRAM if(carList[k2].getOdometerMiles()>=100) { reached=true; [login to view URL]("The winner is:"); [login to view URL](carList[k2].toString()); [login to view URL](0); } } //GENRATE RANDOM SPEED //UPDATE THE ODOMETER MILES for(int k2=0;k2<20;k2++) { carList[k2].generateRandomSpeed(); carList[k2].updateOdometerMiles(); } } }//END MAIN }//END CARRACE
ID-ul proiectului: 12260120

Despre proiect

5 propuneri
Proiect la distanță
Activ: 7 ani în urmă

Vrei să câștigi bani?

Avantajele de a licita pe platforma Freelancer

Stabilește bugetul și intervalul temporal
Îți primești plata pentru serviciile prestate
Evidențiază-ți propunerea
Te înregistrezi și licitezi gratuit pentru proiecte
Acordat utilizatorului:
Avatarul utilizatorului
I have participated in programming competition (ACM-ICPC,codeforces,topcoder). My language of choice is C ++ and java it is easy for me.
$15 USD în 0 zi
5,0 (15 recenzii)
5,1
5,1
5 freelanceri plasează o ofertă medie de $32 USD pentru proiect
Avatarul utilizatorului
hi, i'm a professional c++ developer, i could help you get it done very quick. could we discuss the details? thanks, wentell
$25 USD în 1 zi
5,0 (7 recenzii)
3,5
3,5
Avatarul utilizatorului
Hello, I have more than 4 years of experience in c++ programming and I can deliver You finished project within few hours. Look forward to hearing from You.
$30 USD în 0 zi
5,0 (11 recenzii)
2,9
2,9
Avatarul utilizatorului
I am Java and C++ Programmer. You can see evaluation by github or bitbucket. The code will tested for linux and macos.
$55 USD în 1 zi
0,0 (0 recenzii)
0,0
0,0

Despre client

Steagul UNITED STATES
Phoenix, United States
5,0
1
Membru din dec. 2, 2016

Verificarea clientului

Mulțumim! Ți-am trimis prin e-mail linkul pe care trebuie să-l accesezi pentru a revendica creditul gratuit.
A apărut o eroare la trimiterea e-mailului. Încearcă din nou.
Utilizatori înregistrați Totalul proiectelor postate
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Se încarcă previzualizarea
S-a oferit permisiunea de depistare a locației.
Ți-a expirat sesiunea pentru conectare sau te-ai deconectat. Conectează-te din nou.