foot (12 inches) yard (36 inches), centimeter (2.54 inches) and meter (39.37 inc
ID: 3723861 • Letter: F
Question
foot (12 inches) yard (36 inches), centimeter (2.54 inches) and meter (39.37 inches). Screen sample (bold is user input). W'ite a program that converts and prints a user-supplied measurement in inches into Inch Conversion Program*** Please enter how many inches you want to convert: 69 That is 5.75 feet 1.92 yard 175.26 centimeter 1.75 meter Write a program that reads a product type (a character), the quantity sold (an integer) and the dollar amount (a double). Use setw & setfill. 2. Please enter the product type, quantity sold and price: F 10 210.50 Thank you. You entered: Type: F Qty: 10 Price: $***210.50 Write a program segment that will ask the user to input a number and it will display the square and cube of the number. The space between "' and the number should be 10 blank spaces filled with dashes (). Use setw& setfill. 3. Please enter a number: 5 The square of the number is25 The cube of the number is125Explanation / Answer
/*
Answer1
copy the below code and save the file and run it on the compiler and give the input you will get the desired output
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
float inches,feet,yard,centimeter,meter;
cout<<"***Inch Conversion Program"<<endl;
cout<<"Please enter how many inches you want to convert:";
cin>>inches;
//1 feet=12 inches
feet=inches/12;
//1 yard = 36inches
yard=inches/36;
//1 inch = 2.54cm
centimeter=inches*2.54;
//1 meter=39.37 inches
meter=inches/39.37;
//std::setprecision(2) is used for giving the output of the float values to correctly 2 places after decimal
cout<<"That is "<<std::fixed<<std::setprecision(2)<<feet<<"feet "<<std::fixed<<std::setprecision(2)<<yard<<"yard "<<std::fixed<<std::setprecision(2)<<centimeter<<"centimeter "<<std::fixed<<std::setprecision(2)<<meter<<"meter"<<endl;
return 0;
}
/*
Answer2
copy the below code and save the file and run it on the compiler and give the input you will get the desired output
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
char product_type;
int quantity_sold;
double dollar_amount;
cout<<"Please enter the product type, quantity sold and the price:"<<endl;
cin>>product_type>>quantity_sold>>dollar_amount;
cout<<"Type:"<<product_type;
cout<<" Qty:"<<quantity_sold;
//setw is used for setting the field width
cout<<" Price:$"<<std::setw(9);
//setfille(*) is used for filling the character as here * is given for the vacant field spaces
cout<<std::setfill('*')<<std::fixed<<std::setprecision(2)<<dollar_amount<<endl;
return 0;
}
// Answer3
// copy the below code and save the file and run it on the compiler and give the input you will get the desired output
#include <bits/stdc++.h>
using namespace std;
int main()
{
int input;
cout<<"Please enter a number: ";
cin>>input;
int no_dig_square=0;
int no_dig_cube=0;
int square=input*input;
int cube=input*input*input;
while(square>0){
no_dig_square++;
square/=10;
}
while(cube>0){
no_dig_cube++;
cube/=10;
}
//here we calculate the no of digits in cube and square as we need the fixed no of'-' character after ':'
//and for setting the field it is necessary
cout<<"The square of the number is:"<<std::setw(10+no_dig_square)<<std::setfill('-')<<input*input<<endl;
cout<<"The cube of the number is:"<<std::setw(10+no_dig_cube)<<std::setfill('-')<<input*input*input;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.