
Convert this code Java code to C++ and get the same output:
public class Problem3 {
// method to accept a temperature in fahrenheit and convert it to celsius
public static double fahrenheitToCelsius(double fahrenheit) {
// declaring a variable to store the temperature in celsius
double celsius;
// converting temperature to celsius using formula C/5 = (F-32)/9
celsius = 5 * (fahrenheit - 32) / 9;
// returning temperature in celsius
return celsius;
}
// method to accept a temperature in celsius and convert it to fahrenheit
public static double celsiusToFahrenheit(double celsius) {
// declaring a variable to store the temperature in fahrenheit
double fahrenheit;
// converting temperature to fahrenheit using formula C/5 = (F-32)/9
fahrenheit = 9 * celsius / 5 + 32;
// returning temperature in fahrenheit
return fahrenheit;
}
public static void main(String[] args) {
// variables to store temperature, temperatur in fahrenheit and in celsius
double temperature, fahrenheit, celsius;
// displaying header of the conversion table
System.out.println("\n Temperature Convertion Tables\n");
System.out.println(" Temperature | Temperature");
System.out.println(" (degrees) | (degrees)");
System.out.println(" F C | C F");
// initializing variable temperature with -40
temperature = -40;
// loop will continue for 100 times
for (int i = 1; i <= 100; i++) {
// converting same tempertature to fahrenheit and celsius
fahrenheit = celsiusToFahrenheit(temperature);
celsius = fahrenheitToCelsius(temperature);
// displaying formatted output
System.out.format("%10.3f %10.3f | %10.3f %10.3f\n", temperature, celsius, temperature, fahrenheit);
// incrementing temperature by 5
temperature += 5;
}
}
}

Step by stepSolved in 2 steps

- PROBLEM STATEMENT: Return a number, 1 lesser than the given number. public class Decrement{public static int solution(int x){// ↓↓↓↓ your code goes here ↓↓↓↓return 0;}} Can you please use The source code i providedarrow_forwardbasic java please Write a method called findTip that finds the value of a meal as a double after adding the tip to the cost. Then return this value to the calling function. For example findTip(120.10, 5) would 126.105 because that is a 5% tip. While findTip(48.0, 15) would return 55.2 because that is a 15% tip. Note that the bill is a double while the tip is an int. Don’t worry about rounding to two decimal places, just return the full value as a double.arrow_forwardpublic static class Lab2{public static void Main(){int idNum;double payRate, hours, grossPay;string firstName, lastName;// prompt the user to enter employee's first nameConsole.Write("Enter employee's first name => ");firstName = Console.ReadLine();// prompt the user to enter employee's last nameConsole.Write("Enter employee's last name => ");lastName = Console.ReadLine()// prompt the user to enter a six digit employee numberConsole.Write("Enter a six digit employee's ID => ");idNum = Convert.ToInt32(Console.ReadLine());// prompt the user to enter the number of hours employeeworkedConsole.Write("Enter the number of hours employee worked =>");// prompt the user to enter the employee's hourly pay rateconsole.Write("Enter employee's hourly pay rate: ");payRate = Convert.ToDouble(Console.ReadLine());// calculate gross paygrossPay = hours * payRate;// output resultsConsole.WriteLine("Employee {0} {1}, (ID: {2}) earned {3}",firstName, lastName, idNum,…arrow_forward
- Find the error of the following method definition: public static void timesTwo( int x, int y) { int sum=x + y; return sum; }arrow_forwardIn C++ class rectangleType { public: void setLengthWidth(double x, double y); //Sets the length = x; width = y; void print() const; //Output length and width double area(); //Calculate and return the area of the rectangle (length*width) double perimeter(); //Calculate and return the perimeter (length of outside boundary of the rectangle) private: double length; double width; }; Print out the area of the rectangle.arrow_forward11arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





