Question

In: Physics

Implement the following function: a. float temp(float t, char ch) – this function takes temperature ‘t’...

Implement the following function:
a. float temp(float t, char ch) – this function takes temperature ‘t’ and unit of
temperature ‘ch’ as parameter. The variable ‘ch’ will be either f or c depending on
whether the temperature in variable ‘t’ is in Fahrenheit or Celsius. The function
returns the converted temperature to the main method.
Call the above function in the main method. Initialize temperature and unit of
temperature from the user and pass them as parameter to the above function. The
converted temperature should be displayed in the main method.

Hi teacher can you please give me solution in c++ & python

Solutions

Expert Solution

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 for Fahrenheit";
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 for Fahrenheit";
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.8
else if(ch == 'F' || ch == 'f'):
return t/1.8
else:
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")
  


Related Solutions

Implement function noVowel() that takes a string s as input and returns True if no char-...
Implement function noVowel() that takes a string s as input and returns True if no char- acter in s is a vowel, and False otherwise (i.e., some character in s is a vowel). >>> noVowel('crypt') True >>> noVowel('cwm') True >>> noVowel('car') False Implement function allEven() that takes a list of integers and returns True if all integers in the list are even, and False otherwise. >>> allEven([8, 0, -2, 4, -6, 10]) True >>> allEven([8, 0, -1, 4, -6, 10])...
Using C: Implement function types that takes no input, declares 3 variables of type char, 3...
Using C: Implement function types that takes no input, declares 3 variables of type char, 3 of type short, 3 of type int, and 3 of type double---in that order---and prints the addresses of the 12 variables---in the same order---in both hex (use %p conversion instruction) and unsigned long format. &a1 = 0x7ffd45e3ac0f, 140725776002063 &a2 = 0x7ffd45e3ac0e, 140725776002062 &a3 = 0x7ffd45e3ac0d, 140725776002061 &b1 = 0x7ffd45e3ac0a, 140725776002058 &b2 = 0x7ffd45e3ac08, 140725776002056 ...
The following is a structure template: struct box { char maker[40]; float height; float width; float...
The following is a structure template: struct box { char maker[40]; float height; float width; float length; float volume; }; a. Write a function that has a reference to a box structure as its formal argument and displays the value of each member. b. Write a function that has a reference to a box structure as its formal argument and sets the volume member to the product of the other three dimensions.
C Implement the function Append (char** s1, char** s2) that appends the second character array to...
C Implement the function Append (char** s1, char** s2) that appends the second character array to the first, replaces the first array with the result and replaces the second character array with the original first array. For example, if the first character array is "hello" and the second is "world" at the end of the function the new value of the first character array should be"helloworld" and the second array should be "hello". If the input is invalid the function...
Write in C programming language Write the function replace(char b[], char f[], char t[]). which finds...
Write in C programming language Write the function replace(char b[], char f[], char t[]). which finds the string 'f' in the string 'b' and replaces it with the string 't'. You can assume that f and t same length Example: char string[] = "zap";     replace(string, "ap", "oo"); --changes 'string' to "zoo".     *don't assume substring being replaced is singular, or that its own substrings are unique.     *Don't re scan letters already checked and replaced         char string[] =...
Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints...
Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints a message with information about the total amount owed and how much the tip was. As a reminder, the tip amounts are 10%, 15% and 20% for stingy, regular, and generous customers. And the tax amount should be 7%. The total amount is calculated as the sum of two amounts: check_amount = base_cost*1.07 tip_amount = tip_percentage*check_amount To receive full credit, you must use string...
'PYTHON' 1. Write a function called compute_discount which takes a float as the cost and a...
'PYTHON' 1. Write a function called compute_discount which takes a float as the cost and a Boolean value to indicate membership. If the customer is a member, give him/her a 10% discount. If the customer is not a member, she/he will not receive a discount. Give all customers a 5% discount, since it is Cyber Tuesday. Return the discounted cost. Do not prompt the user for input or print within the compute_discount function. Call the function from within main() and...
Translate the following C program to Pep/9 assembly language: #include <stdio.h> char toLower(char ch) { if...
Translate the following C program to Pep/9 assembly language: #include <stdio.h> char toLower(char ch) { if (ch >= 'A' && ch <= 'Z' )        ch += 'a' - 'A'; return ch; } int main() { char ch, conversion; printf("Enter an uppercase letter: "); scanf("%c", &ch); conversion = toLower(ch); printf("\nLetter after conversion: %c\n\n", conversion); return 0; }
c++ Write the definition of a function named ‘isLower’ that takes as input a char value...
c++ Write the definition of a function named ‘isLower’ that takes as input a char value and returns true if the character is lowercase; otherwise, it returns false.•Print the message “The character xis lowercase” when returned value above is true, and vice versa.
Write a boolean function named isMember that takes two arguments: an array of type char and...
Write a boolean function named isMember that takes two arguments: an array of type char and a value. It should return true if the value is found in the array, or false if the value is not found in the array. PLEASE WRITE FULL PROGRAM IN C++ AND USE RECURSION AND DO NOT USE LOOPS
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT