Question

In: Computer Science

The MarsX Space Vehicles Company has been very successful. Due to an increase in demand for...

The MarsX Space Vehicles Company has been very successful. Due to an increase in demand for its STS’s, the company had to hire thousands of scientists, engineers and staff from all over the world. As we all know, not all countries use the same system of measurements. The U.S., Liberia and Burma use the English system; while the rest of the world uses the metric system. In addition scientists use specific scales for some of their applications. To avoid confusion among team members from different countries, the company has commissioned the development and deployment of conversion applications. Your job is to write a program that interchangeably converts between different temperature scales (Celsius, Fahrenheit and Kelvin).

Your job depends on the success of this application. Therefore, make sure you write clean code and test it thoroughly.

Your program must do the following:

  1. Display the menu below and get user input. Re-display the menu until the user enters 4.
  1. Convert from Celsius
  2. Convert from Fahrenheit
  3. Convert from Kelvin
  4. Quit Program

  1. If the user enters 1, prompt the user to enter 3 numbers that represent temperatures expressed in degree Celsius. The program must then convert the temperatures to degree Fahrenheit and Kelvin and output them in a table as follows:

Celsius

Fahrenheit

Kelvin

-10.00

14.00

263.15

0.00

32.00

273.15

100.00

212.00

373.15

  1. If the user enters 2, prompt the user to enter 3 numbers that represent temperatures expressed in degree Fahrenheit. The program should then convert the temperatures to degree Celsius and Kelvin and output them in a table as follows:

Fahrenheit

Celsius

Kelvin

-10.00

-23.33

249.82

0.00

-17.78

255.37

100.00

37.78

310.93

  1. If the user enters 3, prompt the user to enter 3 numbers that represent temperatures expressed in degree Kelvin (no negative numbers allowed, validate). The program should then convert the temperatures to degree Fahrenheit and Celsius and output them in a table as follows:

Kelvin

Fahrenheit

Celsius

0.00

-459.67

-273.15

100.00

-279.67

-173.15

1000.00

1340.33

726.85

  1. If the user enters 4, quit the program.

Needed conversion formulas:

From

To

       Formula

Celsius

Fahrenheit

F = C * (9.0/5.0) + 32

Celsius

Kelvin

K = C + 273.15

Fahrenheit

Celsius

C = (F – 32) * (5.0/9.0)

Fahrenheit

Kelvin

K = (F + 459.67) * (5.0 /9.0)

Kelvin

Fahrenheit

F = K * (9.0/5.0) – 459.67

Kelvin

Celsius

C = K – 273.15

Your program must comply with the following constraints:

  1. Must declare at least the following 4 function prototypes:

int getMenuSelection();                  /*Displays menu and gets user selection*/

void convertFromCelsius();             /*From Celsius to the other scales*/

void convertFromFahrenheit();        /*From Fahrenheit to the other scales*/

void convertFromKelvin();              /*From Kelvin to the other scales*/

  1. The main function must look exactly as shown below:

int main()

{

int menuSelection = 0;

do

       {

system(“cls”);

menuSelection = getMenuSelection();

             switch (menuSelection)

{

       case 1: convertFromCelsius();

             break;

       case 2: convertFromFahrenheit();

             break;

       case 3: convertFromKelvin ();

             break;

       case 4: break; /*Do nothing. Exit Condition*/

       default: printf(“Please enter a number between 1 and 4 \n”);

system(“pause”);

}

       } while (menuSelection != 4);

system(“pause”);

return 0;

}

Solutions

Expert Solution

Code:


#include <stdio.h>
#include<stdlib.h>
int getMenuSelection(){
  
        int r;
        printf("Enter 1 for convert from Celcius ");
        printf("Enter 2 for convert from Farenheit ");
        printf("Enter 3 for convert from Kelvin ");
        printf("Enter 4 for Quit ");
        scanf("%d",&r);
        printf(" ");
  

    return r;
}

void convertFromCelsius(){
    float c1,c2,c3,f1,f2,f3,k1,k2,k3;
  
    //displaying message and taking input 3 celcius value c1,c2,c3 from user
    printf("Enter the first number that needs to be converted from Celcius: ");
    scanf("%f",&c1);
    printf("Enter the second number that needs to be converted from Celcius: ");
    scanf("%f",&c2);
    printf("Enter the thire number that needs to be converted from Celcius: ");
    scanf("%f",&c3);
  
    //calculating three farenheit f1,f2,f3 from c1,c2,c3
  
    f1= c1 * (9.0/5.0) + 32;
    f2= c2 * (9.0/5.0) + 32;
    f3= c3 * (9.0/5.0) + 32;
  
    //calculating three kelvin k1,k2,k3 from c1,c2,c3
    k1=c1 + 273.15;
    k2=c2 + 273.15;
    k3=c3 + 273.15;
  
  
    //displaying results in atabular form
    printf(" |-------------------------------| ");
    printf("| Celcius | Farenheit | Kelvin | ");
    printf("|---------|-----------|---------| ");
    printf("|%-9.2f|%-11.2f|%-9.2f| ",c1,f1,k1); //-9.f : - for left justification, 9 for 9 space , .2 for 2 decimal precision
    printf("|---------|-----------|---------| ");
    printf("|%-9.2f|%-11.2f|%-9.2f| ",c2,f2,k2);
    printf("|---------|-----------|---------| ");
    printf("|%-9.2f|%-11.2f|%-9.2f| ",c3,f3,k3);
    printf("|---------|-----------|---------| ");
  
  
}

void convertFromFahrenheit(){
    float c1,c2,c3,f1,f2,f3,k1,k2,k3;
  
    printf("Enter the first number that needs to be converted from Farenheit: ");
    scanf("%f",&f1);
    printf("Enter the second number that needs to be converted from Farenheit: ");
    scanf("%f",&f2);
    printf("Enter the thire number that needs to be converted from Farenheit: ");
    scanf("%f",&f3);
  
    c1=(f1-32)*(5.0/9.0);
    c2=(f2-32)*(5.0/9.0);
    c3=(f3-32)*(5.0/9.0);
  
  
    k1=(f1 + 459.67) * (5.0 /9.0);
    k2=(f2 + 459.67) * (5.0 /9.0);
    k3=(f3 + 459.67) * (5.0 /9.0);
  
   printf(" |-------------------------------| ");
    printf("| Farenheit | Celcius | Kelvin | ");
    printf("|-----------|---------|---------| ");
    printf("|%-11.2f|%-9.2f|%-9.2f| ",f1,c1,k1);
    printf("|-----------|---------|---------| ");
    printf("|%-11.2f|%-9.2f|%-9.2f| ",f2,c2,k2);
    printf("|-----------|---------|---------| ");
    printf("|%-11.2f|%-9.2f|%-9.2f| ",f3,c3,k3);
    printf("|-----------|---------|---------| ");
  

}

void convertFromKelvin(){
    float c1,c2,c3,f1,f2,f3,k1=-1,k2=-1,k3=-1;
  
    while(k1<0 || k2<0 || k3<0){
        printf("Kelvin cannot be negative ");
        printf("Enter the first number that needs to be converted from Kelvin: ");
        scanf("%f",&k1);
        printf("Enter the second number that needs to be converted from Kelvin: ");
        scanf("%f",&k2);
        printf("Enter the thire number that needs to be converted from Kelvin: ");
        scanf("%f",&k3);
    }
  
    c1=k1-273.15;
    c2=k2-273.15;
    c3=k3-273.15;
  
    f1= k1 * (9.0/5.0) - 459.67;
    f2= k2 * (9.0/5.0) - 459.67;
    f3= k3 * (9.0/5.0) - 459.67;
  
  
    printf(" |-------------------------------| ");
    printf("| Kelvin | Farenheit | Celcius | ");
    printf("|---------|-----------|---------| ");
    printf("|%-9.2f|%-11.2f|%-9.2f| ",k1,f1,c1);
    printf("|---------|-----------|---------| ");
    printf("|%-9.2f|%-11.2f|%-9.2f| ",k2,f2,c2);
    printf("|---------|-----------|---------| ");
    printf("|%-9.2f|%-11.2f|%-9.2f| ",k3,f3,c3);
    printf("|---------|-----------|---------| ");
  
  
  
  
}


int main(){
    int menuSelection = 0;
    do{
    system("cls");
    menuSelection = getMenuSelection();
    switch (menuSelection)
    {
        case 1: convertFromCelsius();
                break;
        case 2: convertFromFahrenheit();
                break;
        case 3: convertFromKelvin ();
                break;
        case 4: break; /*Do nothing. Exit Condition*/
        default: printf("Please enter a number between 1 and 4 ");

        system("pause");

    }

       } while (menuSelection != 4);

    system("pause");
  
    return 0;

}

output:


Related Solutions

The Olsen Mining Company has been very successful in the last five years. Its $1,000 par...
The Olsen Mining Company has been very successful in the last five years. Its $1,000 par value convertible bonds have a conversion ratio of 34. The bonds have a quoted interest rate of 9 percent a year. The firm’s common stock is currently selling for $46.10 per share. The current bond price has a conversion premium of $10 over the conversion value. a. What is the current price of the bond? (Do not round intermediate calculations and round your final...
mcdonalds has been very successful in its international expansion. in some ways it has remaind very "american" in everything it does
mcdonalds has been very successful in its international expansion. in some ways it has remaind very "american" in everything it does. people around the workd want an american experience when they go to mcdonalds. however, the company knows the importance of service culture and for this reason, service culture is an important part of mcdonalds business model. analyze how the exisrence of service culture must have contributed to the success of mcdonalds
Now, assume that the tennis racquet manufacturer has been very successful in manufacturing and marketing a...
Now, assume that the tennis racquet manufacturer has been very successful in manufacturing and marketing a single line of inexpensive tennis racquets, aimed at beginners and casual players. The manufacturer’s current distribution channel is through large discount retailers, such as Kmart and Walmart. Recently, three major sporting goods chains also began to carry the racquets. The company puts most of its promotion budget into sales promotion to the retailers and into in-store displays. The competitive advantage for this company is...
Homser Lake, Oregon, has an Atlantic salmon catch and release program that has been very successful....
Homser Lake, Oregon, has an Atlantic salmon catch and release program that has been very successful. The average fisherman’s catch has been μ=8.8 Atlantic salmon per day. (Source: National Symposium on Catch and Release Fishing, Humboldt State University). Suppose that a new quota system restricting the number of fishermen has been put into effect this season. A random sample of fishermen gave the following catches per day: 12 6 11 13 5 0 3 7 8 7 6 3 9...
Due to the corona virus pandemic there has been a decrease in the demand for luxury...
Due to the corona virus pandemic there has been a decrease in the demand for luxury goods especially in the airline industry where revenue has decreased,  a decrease in consumer income and factories have closed due to the virus causing a supply shortage to companies such as Apple and Toyota. Fully Explain this change using elasticity measurements and determinants (price elasticity and its relationship to revenue, price elasticity of supply and income elasticity of demand . Provide graphs and calculations to...
Wildly Successful Company The corporation has been wildly successful, in this, the third year of operation....
Wildly Successful Company The corporation has been wildly successful, in this, the third year of operation. While operating in the social media advertising arena can be risky, the corporation has been able through strategic alliances and timely hires, to stay ahead of the profit curve. While the stock price continues to escalate since IPO, some shareholders grow weary of no dividends. A dividend would allow the firm to finally be listed on the NYSE, opening more capital potential to the...
Audio Co. Manages a chain of stores that sell audio systems. It has been very successful,...
Audio Co. Manages a chain of stores that sell audio systems. It has been very successful, but also many failures. The analysis of these failures has led it to adopt the policy of not opening a store unless they are reasonably sure that at least 15% of the students of the place have stereo systems with a cost of $ 1,100 or more. In a survey of 300 of the 2,400 students at a small arts school in the Midwest,...
Pick a local (city, region, or country) brand that has been very successful competing against the...
Pick a local (city, region, or country) brand that has been very successful competing against the bigger global brands in its product category. What are the elements of its strategy that have enabled it to achieve this success?
2. Due to the increasing demand for essential items, Quant Goods Company decided to increase the...
2. Due to the increasing demand for essential items, Quant Goods Company decided to increase the weekly production amounts. The local grocery stores reached out to the company to sign a short-term contract to receive these items from Quant Goods. They noted that the demand for toilet papers, hand sanitizers, chicken breast, and ground beef in three neighborhoods (neighborhood A, B, C) is significantly © N. Orkun Baycik, 2020 high. Due to production capacities, Quant Goods cannot supply for all...
Your uncle has always owned several companies and has been very successful despite not studying Finance...
Your uncle has always owned several companies and has been very successful despite not studying Finance in university. He has heard about several finance methods to evaluate whether to take on a project or not. Explain to him what the three basic decisions that a financial manager must make when overseeing a company. (1 mark) Explain to him what the ultimate objective of a financial manager is. Explain to him what characteristics the best methods have to determine whether or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT