Implement the following functi
Implement the following function:a. float temp(float t, char ch) – this function takes temperature‘t’ and unit oftemperature ‘ch’ as parameter. The variable ‘ch’ will be either for c depending onwhether the temperature in variable ‘t’ is in Fahrenheit orCelsius. The functionreturns the converted temperature to the main method.Call the above function in the main method. Initialize temperatureand unit oftemperature from the user and pass them as parameter to the abovefunction. Theconverted temperature should be displayed in the main method.
Hi teacher can you please give me solution in c++& python
Answer:
The C++ code is as under
########################
#include <iostream>
using namespace std;
float temp(float t, char ch) {if (ch == ‘C’ || ch == ‘c’) {return t*1.8;}else if (ch == ‘F’|| ch == ‘f’) {return t/1.8;}else {float t;char ch;cout<<“Please input temperature, only numbers”;cin>>t;cout<<“Please input C for celcius and F forFahrenheit”;cin>>ch;cout<<temp(t,ch); }}
int main(){ float t;char ch;cout<<“Please input temperature, only numbers”;cin>>t;cout<<“Please input C for celcius and F forFahrenheit”;cin>>ch;if(ch == ‘F’|| ‘f’){cout<<temp(t,ch);cout<<“Converted to Celcius”;}else if(ch == ‘C’|| ‘c’){cout<<temp(t,ch);cout<<“Converted to F”;}
return 0;}
##########################
the python code is as under
##################
def temp(t,ch):if(ch == ‘C’ || ch == ‘c’):return t*1.8else if(ch == ‘F’ || ch == ‘f’):return t/1.8else:return temp(input(‘Please input temperature, only numbers’),input(‘Please input C for celcius and F for Fahrenheit’)
if __name__==”__main__”:t = input(‘Please input temperature, only numbers’);x = input(‘Please input C for celcius and F for Fahrenheit’);if(x==”C”||x==”c”):print(temp(t,x ))print(“Converted to F”)else:print(temp(t,x ))print(“Converted to C”)
"Our Prices Start at $11.99. As Our First Client, Use Coupon Code GET15 to claim 15% Discount This Month!!"
![](https://writinghelpe.com/wp-content/uploads/2022/08/save.jpg)