C++ PROGRAM Write a program for a thermocouple. This device uses a voltage to ca
ID: 3675287 • Letter: C
Question
C++ PROGRAM
Write a program for a thermocouple.
This device
uses a voltage to calculate
temperature. Use a namespace containing voltage and temperature float
variables.
Include in this namespace, three functions:
1.
GetV() - asks the user for the voltage.
2.
CalculateT() - calculates the temperature using the formula T = aV +b
where a and b are constants within the namespace
For constants, a is 12.41 and b is 40.01.
3.
Display() - prints the temperature, which is in
Celsius.
These three functions have no parameters.
Include a non-namespace function called Fahrenheit which converts the Celsius
temperature to Fahrenheit and prints it.
Use F = (9/5)0 + 32
Your program should ask for a voltage, find the temperature and display it in Celsius,
all from the namepsace.
Next call the non-namespace function to display the
temperature in Fahrenheit.
C++ PROGRAM
Write a program for a thermocouple.
Explanation / Answer
#include <iostream>
#define a 12.41 //constant
#define b 40.01 //constant
using namespace std;
namespace temp{
float voltage,temperature;
void getV(){
cout << "enter voltage: ";
cin>>voltage;
}
void calclateT(){
temperature=(a*voltage)+b;
}
void display(){
cout << "temperature is celsius is = "<<temperature<<"C"<<endl;
}
}
void Fahrenheit(){
float Ftemp;
Ftemp=((1.8)*temp::temperature)+32;//temperature from namespace temp.
cout << "Temperature in Fahrenheit is ="<<Ftemp <<endl;
}
int main()
{
temp::getV();//namespace function
temp::calclateT();
temp::display();
Fahrenheit();//non-namespace function
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.