Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

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;
        }
    }
}

 

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education