Question

In: Computer Science

1. Write a C++ code segment to read 50 temperature values in Fahrenheit and to convert...

1. Write a C++ code segment to read 50 temperature values in Fahrenheit and to convert them to Celsius. You convert a Fahrenheit temperature to Celsius by using the following formula: Celsius = 5.0 / 9 * (Fahrenheit - 32).


2.A client has purchased 20 products in a store. Write a C++ code segment to read the unit price and the number of items of each product and to compute and print the total price of all these products.


Solutions

Expert Solution

#include <iostream>

using namespace std;

int main()
{
int n = 5;//reading 5 temparatures, if you want to read 50 then change this 5 as 50.
double f[n];
for(int i=0; i<n; i++){
cout<<"Enter the temperature value in Fahrenheit: ";
cin >> f[i];
  
}
cout<<"Fahrenheit\tCelsius"<<endl;
for(int i=0; i<n; i++){
double c = 5.0 /( 9 * (f[i] - 32));
cout<<f[i]<<"\t"<<c<<endl;
}
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                             

Enter the temperature value in Fahrenheit: 50                                                                                                                                                                                                                            

Enter the temperature value in Fahrenheit: 60                                                                                                                                                                                                                            

Enter the temperature value in Fahrenheit: 70                                                                                                                                                                                                                            

Enter the temperature value in Fahrenheit: 80                                                                                                                                                                                                                            

Enter the temperature value in Fahrenheit: 90                                                                                                                                                                                                                            

Fahrenheit      Celsius                                                                                                                                                                                                                                                  

50      0.0308642                                                                                                                                                                                                                                                        

60      0.0198413                                                                                                                                                                                                                                                        

70      0.0146199                                                                                                                                                                                                                                                        

80      0.0115741                                                                                                                                                                                                                                                        

90      0.00957854

Question 2:

#include <iostream>

using namespace std;

int main()
{
int n = 5;//reading 5 products, if you want to read 20 then change this 5 as 20.
double price[n];
int numOfItems[n];
for(int i=0; i<n; i++){
cout<<"Enter theproduct "<<(i+1)<<" unit price: ";
cin >> price[i];
cout<<"Enter the number of items: ";
cin>> numOfItems[i];
  
}
cout<<"Product\tUnit Price\tItems\tTotal Price"<<endl;
for(int i=0; i<n; i++){
cout<<(i+1)<<"\t"<<price[i]<<"\t"<<numOfItems[i]<<"\t"<<numOfItems[i]*price[i]<<endl;
}
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                             

Enter theproduct 1 unit price: 2                                                                                                                                                                                                                                         

Enter the number of items: 2                                                                                                                                                                                                                                             

Enter theproduct 2 unit price: 3.3                                                                                                                                                                                                                                       

Enter the number of items: 3                                                                                                                                                                                                                                             

Enter theproduct 3 unit price: 4.4                                                                                                                                                                                                                                       

Enter the number of items: 4                                                                                                                                                                                                                                             

Enter theproduct 4 unit price: 5.5                                                                                                                                                                                                                                       

Enter the number of items: 5                                                                                                                                                                                                                                             

Enter theproduct 5 unit price: 6.6                                                                                                                                                                                                                                       

Enter the number of items: 6                                                                                                                                                                                                                                             

Product Unit Price      Items   Total Price                                                                                                                                                                                                                              

1       2       2       4                                                                                                                                                                                                                                                

2       3.3     3       9.9                                                                                                                                                                                                                                              

3       4.4     4       17.6                                                                                                                                                                                                                                             

4       5.5     5       27.5                                                                                                                                                                                                                                             

5       6.6     6       39.6   


Related Solutions

Write a fragment of MIPS code to convert temperature in Kelvin to Fahrenheit
Write a fragment of MIPS code to convert temperature in Kelvin to Fahrenheit
Java Script Ask the user for a Fahrenheit temperature Write the code needed to convert a...
Java Script Ask the user for a Fahrenheit temperature Write the code needed to convert a Fahrenheit temperature into a Celsius temperature. Use an alert box to show the result Ask the user for a Celsius temperature Write a function to convert from Celsius to Fahrenheit; use an alert box to show the results Decide on two other conversions (meters to feet, pounds to kilos, other) Ask the user for numbers to be converted; be sure to tell them what...
Convert the boiling temperature of gold, 2966 °C, into degrees Fahrenheit and kelvin.
Convert the boiling temperature of gold, 2966 °C, into degrees Fahrenheit and kelvin.  
In C Write a program that prompts the user to enter a Fahrenheit temperature calculate the...
In C Write a program that prompts the user to enter a Fahrenheit temperature calculate the corresponding temperature in Celsius and print it prompt the user if they want to do another temperature conversion if the user enters y, repeat 1), 2) and 3) if the user enters n, then print Bye and exit the program if the user enters any other character, ask the user to enter y or n only Note : c = (5.0/9.0)*(f-32.0) Sample output Enter...
Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin...
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....
Instructions Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow...
Instructions Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow the user to enter values for the original Fahrenheit value. Display the original temperature and the formatted converted value. Use appropriate value returning methods for entering (input), calculating, and outputting results.
Write a program read in data from the standard input stream (cin) representing temperature in Fahrenheit....
Write a program read in data from the standard input stream (cin) representing temperature in Fahrenheit. The program will then convert the values into Kelvin (using 5/9 (Fº-32) to convert to Celsius and a difference of 273.15 between Celsius and Kelvin) and print out the new total value. Convert temperature in Fahrenheit to Kelvin : Enter temperature in Fahrenheit: 80.33 The temperature in Kelvin is: 300 Write a second program which then does the reverse conversion (using a difference of...
Develop a routine to convert Celcius to Fahrenheit. Have a form pass the values and a...
Develop a routine to convert Celcius to Fahrenheit. Have a form pass the values and a parm indicating what time of conversion is taking place. Use a function (if possible). Return the correct value. Here is the formula: C = (F - 32) * 5/9 hw8.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title></head> <body> <p>Convert Temp</p> <form id="form1" name="form1" method="get" action="hw8.php"> <table width="300" border="1"> <tr> <td width="122">Enter Temp </td>...
Convert the following C++ code into MIPS assembely. For testing I will be change the values...
Convert the following C++ code into MIPS assembely. For testing I will be change the values for q,y,x with few different values. //q -> $s0 //y -> $s1 //x -> $s2 int main(){ int q = 5; int y = 17; int x = 77; if ( q < 10){ cout << "inside if"; } elseif ( x > 0 || y < 10) { cout << "inside elseif"; } else { cout << "inside else"; } }
Write a Temperature class that will hold a temperature in Fahrenheit, and provide methods to get...
Write a Temperature class that will hold a temperature in Fahrenheit, and provide methods to get the temperature in Fahrenheit, Celsius and Kelvin. The class should have the following field: ftemp – A double that hold a Fahrenheit temperature. The class should have the following methods: Constructor – The constructor accepts a Fahrenheit temperature (as a double) and stores it in the ftemp field. setFahrenheit – The setFahrenheit method accepts a Fahrenheit temperature (as a double) and stores it in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT