In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation.
Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature readings they wish to enter. This value must be numeric and between 1 and 365. Do not forget to check for non-numeric input.
Array allocation: Once you have determined how many temperature readings to store, allocate the appropriate amount of memory to a pointer using the new[] operator. This should happen in a try {} block. If the memory allocation fails at run-time, the new[] operator throws a bad_alloc exception. Include a catch{} block that displays the error message “Error allocating memory” to the user if this happens. Remember that all memory allocated with the new[] operator should be freed when you are done with it. The final statement of your try block should delete[] your pointer.
Getting valid temperature readings: The temperatures the user enters should fall between the range -90.0°C and +60.0°C. Do not accept an input value outside of that range.
Processing: Converting Celsius to Fahrenheit To generate the required output, you will need to convert each Celsius temperature to Fahrenheit. Given this is a fairly generic task that could be re-used in another program, you should create a function to do this. The actual calculation is straight forward; the function body may only need to be one line of code, so the function should be ‘inline’. Keep in mind that a processing function should only do processing, not input or output. Pass the Celsius temperature in as a parameter and send the Fahrenheit temperature back using a ‘return’ statement.
Output: This Week’s Temperature Report Use an Output Function: Write a function that will display the temperatures entered in Celsius and Fahrenheit formatted as above. You must pass this function a pointer to the array storing the Celsius temperatures and the number of items in that array and you are required to use pointer arithmetic to move from one index of the array to the next. You may not use the array subscript operator in this function. Formatting Hints: Look up the ASCII code value for the degrees symbol. Each ‘column’ of the report is right aligned ten characters wide.
#include<iostream>
#include<new>
using namespace std;
double convertTemp(double celTemp);
void displayTemp(double *tmp,int size);
int main()
{
double * temp = NULL,cel;
int numberOfDays;
x:
cout << "Enter the number of days: ";
cin >> numberOfDays;
while (!cin)
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Enter numeric value: ";
cin >> numberOfDays;
}
if (numberOfDays < 1 || numberOfDays>365)
goto x;
try
{
//allocate dynamic memory
temp = new double[numberOfDays];
cout << "Enter temperature in Celsius: ";
for (int i = 0; i < numberOfDays; i++)
{
cin >> cel;
while (!(cel >= -90 && cel <= 60))
{
cout << "Enter valid temperature: " << endl;
cin >> cel;
}
*(temp + i)=cel;
}
//output the temperature
displayTemp(temp,numberOfDays);
}
catch (std::bad_alloc& ba)
{
std::cerr << "Error allocating memory.... " << ba.what() << '\n';
throw;
}
//delete the entire array
delete[] temp;
//to hold the output screen
system("pause");
return 0;
}
double convertTemp(double celTemp)
{
return ((9 * celTemp) / 5) + 32;
}
void displayTemp(double *tmp,int size)
{
char degree =248 ;
for(int i=0;i<size;i++)
{
cout << *(tmp+i) << degree<<"F ";
int temp = convertTemp(*(tmp+i));
cout << temp << degree << "C " << endl;;
}
}
//output

//Need any help regarding this solution just leave a comment ................. Thanks
In this project you will create a console C++ program that will have the user to...
Write a program in C that will convert all 12 months' average temperature from Celsius to Fahrenheit. You need to create an array named aye jump and prompt the user to input average temperature in Celsius for all 12 months. After that, you need to develop a user temperatures from Celsius to Fahrenheit and pass the array as reference and convert all temperatures from Celsius to Fahrenheit. Next, compute the average temperature of the year and assign it to a...
Can
you help me to create this program, please?
Prompt the user for the user for a number of degrees in Fahrenheit as an int. That number should be passed to a function named ffocREFO. This function will do the necessary calculation to convert the passed temperature to degrees Celsius as a double. The function MUST have a void return type and have the following prototype: void ffccREF(double& celsius, int Faren); In your main, display both the entered temperature and...
Write a C++ program that prompts a user to enter a temperature in Fahrenheit as a real number. After the temperature is entered display the temperature in Celsius. Your program will then prompt the user if they want to continue. If the character n or N is entered the program will stop; otherwise, the program will continue. After your program stops accepting temperatures display the average of all the temperatures entered in both Fahrenheit and Celsius. Be sure to use...
Create a program in Python that will allow the user to enter a temperature in Fahrenheit which will then be converted to degrees Celsius. The program will keep asking the user for a Fahrenheit temperature until the user enters Q to quit. After each conversion the program needs to print out the degrees Celsius. The input prompts for this problem need to look like the following: Degrees Fahrenheit: Continue: For these input prompts watch the capitalization and spacing. There are...
Write a Python program with a function that will take as input from the user the temperature in Celsius and will convert and display temperature values in both Fahrenheit and Celsius, using the equation: F = (C ∗ 9/5)+ 32 Note: below is what a sample input line to your program should look like and the resulting output. User input lines always start with >>>. This convention will be used for all of the problem sets. >>>Enter temperature in Celsius:...
Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin Newton Your program should take a character which represents the temperature to convert from and a value to be converted to using the following specification: C - Celsius K - Kelvin N - Newton In addition your program should take in the following character to exit the program: X - eXit the program The numeric input for your program should be of type double....
For this assignment you will create a program converting Fahrenheit temperatures to Celsius temperatures. The formula for converting a temperature from Celsius to Fahrenheit is: F = C x 1.8 + 32, where F is the Fahrenheit temperature and C is the Celsius temperature. Write a function named Fahrenheit that accepts a Celsius temperature as an argument and returns the temperature converted to Fahrenheit. Demonstrate the function by accepting a Celsius temperature from a user and displaying the temperature converted...
using C language
Create an array of doubles with 5 elements. In the array prompt the user to enter 5 temperature values (in degree Fahrenheit). Do this within main. Create a user defined function called convert2Cels. This function will not return any values to main with a return statement. It should have parameters that include the temperature array and the number of elements. The function should convert the values for Fahrenheit to Celsius and save them back into the same...
Write a C++ program that shows the following menu options and lets the user to convert from Metric to Imperial system: Converter Toolkit -------------------- 1. Temperature Converter 2. Distance Converter 3. Weight Converter 4. Quit If the user enters 1, the program should ask for the temperature in Celsius and convert it to Fahrenheit If the user enters 2, the program should ask for the distance in Kilometer and convert it to Mile If the user...
Write a program that would ask the user to enter an input file name, and an output file name. Then the program reads the content of the input file, and read the data in each line as a number (double). These numbers represent the temperatures degrees in Fahrenheit for each day. The program should convert the temperature degrees to Celsius and then writes the numbers to the output file, with the number of day added to the beginning of the...