Question

In: Computer Science

2. Write a C++ program that; Takes in the weight of a person in Kilograms, converts...

2. Write a C++ program that;

Takes in the weight of a person in Kilograms, converts and outputs the equivalent weight in pounds. Format your output to 3 decimal places. Your output should look like this

53.000 Kg is equivalent to 123.459 Ibs

(Note 1Kg = 2.2046226218488 lbs)

Takes in the price of an item on an online store in pound sterling, converts and outputs the equivalent price in U.S dollars. Format your output to 2 decimal places.

Your output should look like this

£24.49 is equivalent to $31.96

To output the pound symbol, you need to display char(156). 156 signifies the pound notation's location on the ascii table shown in class

cout << char(156);

(Note £1 = $1.3048)

*BOTH CONVERSIONS SHOULD BE DONE IN THE SAME PROGRAM*

Solutions

Expert Solution

#include <iomanip>
#include<iostream>

using namespace std;

int main()
{
    //declare variable
    double kg_weight, lbs_weight, dollar_price,pound_price;
    cout<<"Enter weight of a person in Kilograms: ";
    
    //takes weight entered by user in kg_weight variable
    cin>>kg_weight;
    
    //converts kg to pounds
    lbs_weight = kg_weight * 2.2046226218488;
    
    //below 2 lines are used to format output to 3 decimal places
    cout <<fixed;
    cout <<setprecision(3);
    cout<<kg_weight<< " Kg is equivalent to "<<lbs_weight<<" lbs"<<endl;
    
    cout<<"Enter price of an item in pound sterling: ";
    //takes price entered by user in pound_price variable
    cin>>pound_price;
    
    //converts pound to dollars
    dollar_price = pound_price * 1.3048;
    
    //below 2 lines are used to format output to 2 decimal places
    cout <<fixed;
    cout <<setprecision(2);
    cout<<"£"<<pound_price<< " is equivalent to "<<char(36)<<dollar_price<<" lbs";
    
    return 0;
}

OUTPUT:


Related Solutions

a C++ program that reads in weight in pounds and outputs the equivalent length in Kilograms...
a C++ program that reads in weight in pounds and outputs the equivalent length in Kilograms and grams. Use at least three functions: one for input, one or more for calculating, and one for output. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. 1 pound (lb) is equal to 0.45359237 kilograms (kg). There are 1000 grams in a kilogram and 16 ounces...
a C++ program that reads in weight in pounds and outputs the equivalent length in Kilograms...
a C++ program that reads in weight in pounds and outputs the equivalent length in Kilograms and grams. Use at least three functions: one for input, one or more for calculating, and one for output. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. 1 pound (lb) is equal to 0.45359237 kilograms (kg). There are 1000 grams in a kilogram, and 16 ounces...
Write a C++ function that takes in an arithmetic expression in prefix notation and converts it...
Write a C++ function that takes in an arithmetic expression in prefix notation and converts it into a binary tree, such that each operation is stored in a node whose left subtree stores the left operand, and whose right subtree stores the right operand.
Write a C function str_to_float() that takes a numeric string as input and converts it to...
Write a C function str_to_float() that takes a numeric string as input and converts it to a floating point number. The function should return the floating point number by reference. If the conversion is successful, the function should return 0, and -1 otherwise (e.g. the string does not contain a valid number). The prototype of the function is given below int str_to_float(char * str, float * number);
Write a C++ program that converts an infix expression, which includes (, ), +, -, *,...
Write a C++ program that converts an infix expression, which includes (, ), +, -, *, and / operations to postfix notation. The program should allow the user to enter an infix expression using lower case characters, then it will display the result of conversion on the screen. (Note: Use the STL stack class to accomplish the solution.).
Write a program in C++ that converts a positive integer into the Roman number system. The...
Write a program in C++ that converts a positive integer into the Roman number system. The Roman number system has digits I      1 V    5 X    10 L     50 C     100 D    500 M    1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (3) The numbers 1 to 9 are expressed as...
Write a program in C++ that converts a positive integer into the Roman number system. The...
Write a program in C++ that converts a positive integer into the Roman number system. The Roman number system has digits I      1 V    5 X    10 L     50 C     100 D    500 M    1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (3) The numbers 1 to 9 are expressed as...
2. Write a c++ program that takes from the user the ​number of courses​ and constructs...
2. Write a c++ program that takes from the user the ​number of courses​ and constructs 3 ​dynamic 1D arrays​ with size courses+1. Each array represents a student. Each cell in the array represents a student’s mark in a course. In the last cell of each 1D array you should calculate the average mark of that student. Then output the average mark of all students in each course. Delete any allocated memory. Example Number of courses : 4 50 60...
using C program Assignment Write a computer program that converts a time provided in hours, minutes,...
using C program Assignment Write a computer program that converts a time provided in hours, minutes, and seconds to seconds Functional requirements Input MUST be specified in hours, minutes, and seconds MUST produce the same output as listed below in the sample run MUST correctly compute times Nonfunctional requirements MUST adhere to program template include below MUST compile without warnings and errors MUST follow the code template provided in this assignment MUST NOT change " int main() " function MUST...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT