C++ in Linux Program 1: Write a small Linux program that will calculate the temp
ID: 3774775 • Letter: C
Question
C++ in Linux
Program 1:
Write a small Linux program that will calculate the temperature in degrees F, given the temperature in degrees C, where C is 34.5. (The formula is.. F = (9/5) * C + 32.0).
You must perform the calculation as a separate function such as convert(C). The caller invokes the function as in convert(34.5)
Your program should print out the corresponding Fahrenheit degrees, and then terminate.
Program 2:
Write a small Linux program that will calculate the temperature in degrees F, given the temperature in degrees C. (The formula is.. F = (9/5) * C + 32.0).
From Program 1, you must perform the calculation as a separate function, namely convert(C).
Your program should ask the user to input a temperature in Centigrade and then return Fahrenheit. Continue until the user quits.
Explanation / Answer
Program 1:
#include<iostream>
using namespace std;
void convert(float);
int main()
{
float celsius=34.5;
convert(celsius);
return 0;
}
void convert(float c)
{
float fahrenheit;
fahrenheit = (c * 9.0) / 5.0 + 32;
cout << "Fahrenheit Temperature: " << fahrenheit << endl;
}
Program 2:
#include<iostream>
using namespace std;
void convert(float);
int main()
{
float celsius;
char ch;
do{
cout << "Enter the temperature in Celsius : ";
cin >> celsius;
convert(celsius);
cout<<"Do you want to enter temperature in Celsius again ? (y/Y)";
}while(ch=='y' || ch=='Y');
return 0;
}
void convert(float c)
{
float fahrenheit;
fahrenheit = (c * 9.0) / 5.0 + 32;
cout << "Fahrenheit Temperature: " << fahrenheit << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.