CS 135 Purpom: After completing this assigeanet, you will be able to: Demoustrat
ID: 3914300 • Letter: C
Question
CS 135 Purpom: After completing this assigeanet, you will be able to: Demoustrate bow to seC++ecomparison operators Explain the syntax of C4+ selection statements Task: Write aC++ prograan that reads in a temperature in eitber Fahrenbeit, Celsius, or Kelvin and converts the temperature to the other two formats Discussion: The program must take two command-line arguments the finst - gument is the namerical value of the temperature, and the second argumrnt is the temperature type (F, C or K). It must also do sone ernor checking to make sure that the correct taumber of argtiments are input as wvd1 asonly ???1id temperature types. The peogram stun as Sollow gt+ ca135-tHap-conv.epp s ./a.out 117 F 117F i 47.2C and 320.4x /a.out 25 c 25C a 77 and 298.2K /a.out 117 K 117K is-249.1F and -156.20 ./a.out 98.6 You must enter tuo argunents $ ,/a.out 37 Vis not a valid tesperature type Criteriaz Subenissions wast adhbere to the criteria specified in the syllabeas. Hig lights Sor this assinment include Test your pnogram by uning it a few times to make stre the out peat is comect Make sure you take isto account ngative as well as positive valuns Use the folloving formulas for temperature coeversion: K-(F 459.67)S/9Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
int main( int argc, char **argv)
{
double temp = stod(argv[1]);
double K,F,C;
if(!argv[2]) cout <<"You must enter two arguments"<<endl;
else
{
char *s = argv[2];
if(s[0]=='K')
{
K=temp;
F = 9/5.0 *temp - 459.67;
C = (F-32)*5/9.0;
cout << K<<"K is"<<F<<"F and "<<C<<"C"<<endl;
}
else if (s[0]=='F')
{
F=temp;
K = (F+459.67)*5/9.0;
C = (F-32)*5/9.0;
cout << F<<"F is"<<C<<"C and "<<K<<"K"<<endl;
}
else if(s[0]=='C')
{
C=temp;
F=C*9/5.0+32;
K = (F+459.67)*5/9.0;
cout << C<<"C is"<<F<<"F and "<<K<<"K"<<endl;
}
else
{
cout<<arg[2] <<" is not a valid argument"<<endl;
}
}
}
}