C++ 1A. (1) Draw a complete and neat flowchart that converts the temperature in
ID: 3928949 • Letter: C
Question
C++
1A. (1) Draw a complete and neat flowchart that converts the temperature in °C to °F or temperature in °F to °C. The user is prompted to enter the choice of conversion (for example, enter 1 for Celcius; 2 for Farenheit) and prompted to enter the temperature value. Display the original temperature value and the converted temperature value. Note: Celcius = 5 * ( F - 32 ) / 9.
(2) Write a complete C++ program according to your flowchart developed in (1).
B (1) Draw a complete and neat flowchart to display the message “Bring an umbrella” if it is a raining day. If it is not raining and the temperature is at least 65° F, display “Go to Picnic”; if it is not raining and the temperature is less than 65° F, display “Stay home”. Prompt the user to enter a ‘y’ or ‘Y’ for a raining day and to enter an integer for the temperature.
(2) Write a complete C++ program according to your flowchart developed in (1).
Explanation / Answer
// C++ code to do conversion between celsius and fahrenheit
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <stdlib.h>
#include <math.h>
using namespace std;
int main()
{
double celsius;
double fahrenheit;
int choice;
double temperature;
cout << "1.Fahrenheit to Celsius 2.Celsius to Fahrenheit Enter your choice: ";
cin >> choice;
cout << "Enter temperature: ";
cin >> temperature;
if(choice == 1)
{
fahrenheit = temperature;
cout << "Temperature in fahrenheit: " << fahrenheit << endl;
celsius = (5*(fahrenheit-32.0))/9;
cout << "Temperature in celsius: " << celsius << endl;
}
else if (choice == 2)
{
celsius = temperature;
cout << "Temperature in celsius: " << celsius << endl;
fahrenheit = (celsius * 9.0) / 5.0 + 32;
cout << "Temperature in fahrenheit: " << fahrenheit << endl;
}
else
cout << "Invalid Input ";
return 0;
}
/*
output:
1.Fahrenheit to Celsius
2.Celsius to Fahrenheit
Enter your choice: 2
Enter temperature: 100
Temperature in celsius: 100
Temperature in fahrenheit: 212
1.Fahrenheit to Celsius
2.Celsius to Fahrenheit
Enter your choice: 1
Enter temperature: 100
Temperature in fahrenheit: 100
Temperature in celsius: 37.7778
*/
// C++ code to do plan picnic on basis of temperature and rain
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <stdlib.h>
#include <math.h>
using namespace std;
int main()
{
double temperature;
char day;
cout << "Rainy day(y/n)? ";
cin >> day;
if(day == 'n' || day == 'N')
{
cout << "Bring an Umbrella ";
return 0;
}
cout << "Enter temperature: ";
cin >> temperature;
if( (day == 'y' || day == 'Y') && temperature >= 65)
cout << "Go to Picnic ";
else if( (day == 'y' || day == 'Y') && temperature < 65)
cout << "Stay Home ";
return 0;
}
/*
output:
Rainy day(y/n)? y
Enter temperature: 34
Stay Home
Rainy day(y/n)? y
Enter temperature: 78
Go to Picnic
Rainy day(y/n)? n
Bring an Umbrella
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.