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; } }}
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;
}
}
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)