You are on page 1of 34

Assignment # 1

BS-Software Engineering

Section X

Due Date: 14 December 2013

Submitted to:

Afia Mufti

Submitted by:

Muhammad Yousaf Ruhani

ID: 13005065118

Chapter 2

Questions from exercise:

Q2) Which of the following are valid C++ identifiers?

a) myFirstProgram= valid b) MIX_UP= valid

c) C++Program2= invalid d) quiz7= valid

e) ProgrammingLecture2= valid f) 1footEquals12Inches= invalid

g) Mike’sFirstAttempt= invalid h) Update Grade= invalid

i) 4th= invalid j) New_Student= valid

Q7) If x = 5, y = 6, z = 4, and w = 3.5, evaluate each of the following statements, if possible. If it is


not possible, state the reason.

a) (x + z) % y = 3 b) (x + y) % w = 0.5
c) ( y + w) % x = 4.5 d) (x + y) * w = 38.5

e) ( x % y) % z = 1 f) (y % z) % x = 2

g) (x * z) % y = 2 h) ((x * y) * w) * z = 420

Q12) Write C++ statements(s) that accomplish the following.

a) Declare int variables x and y. Initialize x to 25 and y to 18.

ANS)

int x,y;

x = 25;

y = 18;

cout<<"x = "<<x<<endl;

cout<<"y = "<<y;

b) Declare and initialize an int variable temp to 10 and a char variable ch to 'A'.

ANS)

int temp;
char ch ;
temp = 10;
ch = 'A' ;
cout<<"temp = "<<temp<<endl;
cout<<"ch = "<<ch;

c) Update the value of an int variable x by adding 5 to it.

ANS)
int x,a;
cout<<"enter x: ";
cin>>x;
a = x + 5;
cout<<"a = "<<a;

d) Declare and initialize a double variable payRate to 12.50.

ANS)

double payRate;
payRate = 12.50;
cout<<"payRate = "<<payRate;

e ) Copy the value of an int variable firstNum into an int variable tempNum.

ANS) int firstNum,tempNum;


firstNum = 10;
cout << "firstNum= " <<firstNum<<endl;
tempNum = firstNum;
cout<<"tempNum= "<<tempNum;
return 0;

f) Swap the contents of the int variables x and y. (Declare additional variables, if necessary.)

ANS)

int x,y,temp;
cout << "enter x: " ;
cin>>x;
cout<<"enter y: ";
cin>>y;
temp = x;
x = y;
y = temp;
cout<<"x: "<<x<<endl;
cout<<"y: "<<y;

g) Suppose x and y are double variables. Output the contents of x, y, and the expression x + 12 / y -
18.

ANS)

double x,y,a;

cout << "enter x: " ;

cin>>x;

cout<<"enter y: ";

cin>>y;

a = x + 12 / y - 18;

cout<<"x + 12 / y - 18 = "<<a;

h) Declare a char variable grade and set the value of grade to 'A'.

ANS)

char grade;

grade = 'A';

cout<<"grade = "<<grade;

i) Declare int variables to store four integers.

ANS)

int a,b,c,d;

cout<<"a = ";
cin>>a;

cout<<"b = ";

cin>>b;

cout<<"c = ";

cin>>c;

cout<<"d = ";

cin>>d;

j) Copy the value of a double variable z to the nearest integer into an


int variable x.

ANS) double z ;

int x;

z = 12.34 ;

cout << "z= " <<z<<endl;

x = z;

cout<<"x= "<<x;

return 0;

Q13) Write each of the following as a C++ expression.

a) 32 times a plus b =
int a,b,c;

cout<<"a = ";

cin>>a;

cout<<"b = ";
cin>>b;

c = 32 * a + b;

cout<<"c = "<<c;

b) The character that represents 8 =

ANS)

Char a;

cout<<"a=8"<<a;

c) The string that represents the name Julie Nelson.

ANS)

string JulieNelson;

cout<<"JulieNelson"<<JulieNelson;

d) (b2 -4ac)/2a

ANS) int b,a,c,e;

cout<<"(b^2 -4*a*c)/2*a" << (b^2 -4*a*c)/2*a <<endl;

e) (a + b)/c(ef)-gh

ANS)

int b,a,c,e,g,h,f;

cout<<"(a + b) / c *(e * f)-g * h" <<(a + b) / c * (e * f) - g * h ;

f) (-b + (b2 - 4ac)) / 2a


ANS) int b,a,c;

cout<<"(-b + (b^2 (pow(b,2)) - 4*a*c)) / 2*a" <<(-b + (b^2 (pow(b,2)) - 4*a*c)) / 2*a <<endl;

Q15) Suppose x, y, and z are int variables and w and t are double variables.
What value is assigned to each of these variables after the last statement
executes?

ANS)

X=20

y=15

z=6

w=12.2

t=4.5

Q20) Give meaningful identifiers for the following variables.

a) A variable to store the first name of a student.

ANS) fName=

b) A variable to store the discounted price of an item.

ANS) disPrice=

c) A variable to store the number of juice bottles.

ANS) noJuicebottles=

d) A variable to store the number of miles traveled.

ANS) milesTraveled=

e) A variable to store the highest test score.

ANS) highscore=
Q21) Write C++ statements to do the following.

a) Declare int variable num1 and num2.

ANS) int num1,num2;

b) Prompt the user to input two numbers.

ANS) int num1,num2;

cout<<"num1= ";

cout<<"num2= ";

c) Input the first number in num1 and the second number in num2.

ANS) ) int num1,num2;

cout<<"num1= ";

cin>>num1;

cout<<"num2= ";

cin>>num2;

d) Output num1, num2, and 2 times num1 minus num2. Your output must
identify each number and the expression.

ANS)

int num1,num2,a;

cout<<"num1= ";

cin>>num1;

cout<<"num2= ";

cin>>num2;

a=2*num1+num2;

cout<<"a= "<<a;
Q30) Suppose a, b, and sum are int variables and c is a double variable. What
value is assigned to each variable after each statement executes? Suppose a = 3,
b = 5, and c = 14.1.

ANS) sum= a+b+c= 22


c /= a= 4.7

b += c – a= 16

a *= 2 * b + c= 44

Questions from programming exercise.

Q2) Write a program that produces the following output.

ANS)

int ccccccccc,cc;

cout<<"ccccccccc" <<endl;

cout<<"cc"<<endl;

cout<<"cc"<<endl;

cout<<"cc"<<endl;

cout<<"cc"<<endl;

cout<<"ccccccccc"<<endl;

Q3) Consider the following program segment

a) Write C++ statements that include the header files iostream.

ANS) #include <iostream>


int main()

int cc;

std::cout << "cc" ;

std::cout << "cc";

return 0;

b) Write a C++ statement that allows you to use cin, cout, and endl
without the prefix std::

ANS) #include <iostream>

using namespace std;

int main()

int c;

cout << "c= "<<endl ;

cin>>c;

return 0;

c) Write C++ statements that declare the following variables: num1, num2, num3, and average
of type int.

ANS) #include <iostream>


using namespace std;
int main()

{
int num1,num2,num3,average;

return 0;
}

d) Write C++ statements that store 125 into num1, 28 into num2, and
-25 into num3.

ANS) #include <iostream>


using namespace std;

int main()

{
int num1,num2,num3;
num1 = 125;
num2 = 28;
num3 = -25;

return 0;
}

e) Write a C++ statement that stores the average of num1, num2, and
num3, into average.

ANS) #include <iostream>


using namespace std;

int main()

{
int sum,num1,num2,num3,average;
num1 = 125;
num2 = 28;
num3 = -25;
sum = num1 + num2 + num3 ;
average = sum / 3;

return 0;
}

f) Write C++ statements that output the values of num1, num2, num3,
and average.

ANS) #include <iostream>


using namespace std;

int main()

{
int sum,num1,num2,num3,average;
cout<<"num1= ";
cin>>num1;
cout<<"num2= ";
cin>>num2;
cout<<"num3= ";
cin>>num3;
sum = num1 + num2 + num3 ;
average = sum / 3;
cout<<"sum= "<<sum<<endl;
cout<<"average= "<<average;

return 0;
}

g) Compile and run your program.

ANS) #include <iostream>


using namespace std;

int main()
{
int sum,num1,num2,num3,average;
cout<<"num1= ";
cin>>num1;
cout<<"num2= ";
cin>>num2;
cout<<"num3= ";
cin>>num3;
sum = num1 + num2 + num3 ;
average = sum / 3;
cout<<"sum= "<<sum<<endl;
cout<<"average= "<<average;

return 0;
}

Q5) Consider the following C++ program in which the statements are in the
incorrect order. Rearrange the statements so that it prompts the user to input
the length and width of a rectangle and output the area and perimeter of the
rectangle.

ANS) #include <iostream>


using namespace std;
int main()
{
int length,width,perimeter,area;
cout << "Enter the length: ";
cin >> length;
cout<< "Enter the width: ";
cin>>width;
area = length * width;
perimeter = 2 * (width + length);
cout << "Area = " << area << endl;
cout << "Perimeter = " << perimeter ;
return 0;

Q8) Consider the following program segment.

a) Write C++ statements that include the header files iostream and
string.

ANS) #include <iostream>


#include <string>
using namespace std;
int main()
{
cout << "" << endl;
return 0;}
b) Write a C++ statement that allows you to use cin, cout, and endl
without the prefix std::.

ANS) #include <iostream>

#include <string>

using namespace std;

int main()

{ cout << "" << endl;

return 0;

c) Write C++ statements that declare and initialize the following named constants: SECRET of
type int initialized to 11 and RATE of type double initialized to 12.50.

ANS) #include <iostream>

#include <string>

using namespace std;

int main()

int SECRET;

double RATE;

SECRET = 11;
RATE = 12.50;

cout<<"SECRET= "<<SECRET<<endl;

cout<<"RATE= "<<RATE;

return 0;

d) Write C++ statements that declare the following variables: num1, num2,
and newNum of type int; name of type string; and hoursWorked and
wages of type double.

ANS) #include <iostream>

#include <string>

using namespace std;

int main()

int num1,num2,newNum;

string name;

double hoursWorked,wages;

return 0;

e) Write C++ statements that prompt the user to input two integers and
store the first number in num1 and the second number in num2.

ANS) #include <iostream>

#include <string>

using namespace std;

int main()
{

int num1,num2;

num1=4;

num2=5;

cout<<"num1= "<<num1<<endl;

cout<<"num2= "<<num2;

return 0;

f) Write a C++ statement(s) that outputs the values of num1 and num2,
indicating which is num1 and which is num2. For example, if num1 is 8
and num2 is 5, then the output is:
The value of num1 = 8 and the value of num2 = 5.

ANS) #include <iostream>

#include <string>

using namespace std;

int main()

int num1,num2;

num1=6;

num2=4;

cout<<" num1 = "<<num1<<endl;

cout<<" num2 = "<<num2;

return 0;

}
g) Write a C++ statement that multiplies the value of num1 by 2, adds the
value of num2 to it, and then stores the result in newNum. Then, write a
C++ statement that outputs the value of newNum.

ANS) #include <iostream>

#include <string>

using namespace std;

int main()

int num1,num2,newNum;

cout<<" num1 = ";

cin>>num1;

cout<<" num2 = ";

cin>>num2;

newNum = num1 * 2 + num2;

cout<<"newNum= "<<newNum;

return 0;

h) Write a C++ statement that updates the value of newNum by adding the value of the named
constant SECRET. Then, write a C++ statement that outputs the value of newNum with an
appropriate message.

ANS) #include <iostream>

#include <cmath>

using namespace std;

int main()
{

double newNum,SECRET;

cout<<"newNum: ";

cin>>newNum;

cout<<"SECRET: ";

cin>>SECRET;

newNum += SECRET;

cout<<"new value is newNum: "<<newNum;

return 0;

i) Write C++ statements that prompt the user to enter a person’s last name
and then store the last name into the variable name.

ANS) #include <iostream>

#include <string>

using namespace std;

int main()

string lastName;

cout<<"enter lastName: ";

cin>>lastName;
return 0;

j) Write C++ statements that prompt the user to enter a decimal number
between 0 and 70 and then store the number entered into hoursWorked.

ANS) #include <iostream>

#include <math.h>

using namespace std;

int main()

double hoursWorked;

hoursWorked = 40.3;

cout<<"hoursWorked= "<<hoursWorked;

return 0;

k) Write a C++ statement that multiplies the value of the named constant
RATE with the value of hoursWorked and then stores the result into the
variable wages.

ANS) #include <iostream>

#include <cmath>

using namespace std;

int main()
{

double RATE,hoursWorked,wages;

cout<<"RATE: ";

cin>>RATE;

cout<<"hoursWorked: ";

cin>>hoursWorked;

wages = RATE * hoursWorked;

cout<<"wages: "<<wages;

return 0;

l) Write C++ statements that produce the following output:


Name: //output the value of the variable name
Pay Rate: $ //output the value of the variable rate
Hours Worked: //output the value of the variable
//hoursWorked
Salary: $ //output the value of the variable wages
For example, if the value of name is "Rainbow" and hoursWorked is
45.50, then the output is:
Name: Rainbow
Pay Rate: $12.50
Hours Worked: 45.50
Salary: $568.75

ANS) #include <iostream>

#include <math.h>

#include <string>

using namespace std;

int main()
{

double hoursWorked,payRate,salary;

string name,Rainbow;

cout<<"hoursWorked: ";

cin>>hoursWorked;

cout<<"payRate:$ ";

cin>>payRate;

cout<<"salary:$ ";

cin>>salary;

cout<<"name: ";

cin>>name;

return 0;

m) Write a C++ program that tests each of the C++ statements that you
wrote in parts a through l. Place the statements at the appropriate place
in the previous C++ program segment. Test run your program (twice)
on the following input data:

a) num1 = 13, num2 = 28; name = "Jacobson"; hoursWorked =


48.30.

ANS) #include <iostream>

#include <math.h>

#include <string>

using namespace std;

int main()

{
int num1,num2;

string name;

double hoursWorked;

num1 = 13;

num2 = 28;

name = "Jacobson";

hoursWorked = 48.30;

cout<<"num1 = "<<num1<<endl;

cout<<"num2 = "<<num2<<endl;

cout<<"name = "<<name<<endl;

cout<<"hoursWorked = "<<hoursWorked;

return 0;

b) num1 = 32, num2 = 15; name = "Crawford"; hoursWorked =


58.45.

ANS) #include <string>

using namespace std;

int main()

int num1,num2;

string name;

double hoursWorked;

num1 = 32;

num2 = 15;

name = "Crawford";
hoursWorked = 58.45 ;

cout<<"num1 = "<<num1<<endl;

cout<<"num2 = "<<num2<<endl;

cout<<"name = "<<name<<endl;

cout<<"hoursWorked = "<<hoursWorked;

return 0;

Q9) Write a program that prompts the user to enter five test scores and then prints
the average test score. (Assume that the test scores are decimal numbers.)

ANS) #include <iostream>

#include <string>

using namespace std;

int main()

double t1,t2,t3,t4,t5;

double average,sum;

cout<<"t1= ";

cin>>t1;

cout<<"t2= ";

cin>>t2;

cout<<"t3= ";

cin>>t3;

cout<<"t4= ";
cin>>t4;

cout<<"t5= ";

cin>>t5;

sum = t1 + t2 + t3 + t4 + t5;

average = sum / 5;

cout<<"average= "<<average;

return 0;

Q10) Write a program that prompts the user to input five decimal numbers. The
program should then add the five decimal numbers, convert the sum to the
nearest integer, and print the result.

ANS) #include <iostream>

#include <math.h>

using namespace std;

int main()

double n1,n2,n3,n4,n5,a;

cout<<"n1= ";

cin>>n1;

cout<<"n2= ";

cin>>n2;

cout<<"n3= ";

cin>>n3;
cout<<"n4= ";

cin>>n4;

cout<<"n5= ";

cin>>n5;

a = n1 + n2 + n3 + n4 + n5;

cout<<"a= "<<round(a);

return 0;

Q18) A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm ships
cartons of milk to a local grocery store. The cost of producing one liter of
milk is $0.38, and the profit of each carton of milk is $0.27. Write a
program that does the following:

a) Prompts the user to enter the total amount of milk produced in the
morning.

ANS) #include <iostream>

#include <math.h>

using namespace std;

int main()

double cartonHold,costofOneliter,profitofEachcarton,totalamountofMilk;

cartonHold = 3.78;

costofOneliter = 0.38;

profitofEachcarton = 0.27;

cout<<"totalamountofMilk= ";

cin>>totalamountofMilk;
return 0;

b) Outputs the number of milk cartons needed to hold milk. (Round your
answer to the nearest integer.)

ANS) #include <iostream>

#include <math.h>

using namespace std;

int main()

double cartonHold,costofOneliter,profitofEachcarton,totalamountofMilk,a;

cartonHold = 3.78;

costofOneliter = 0.38;

profitofEachcarton = 0.27;

cout<<"totalamountofMilk= ";

cin>>totalamountofMilk;

a = totalamountofMilk / cartonHold;

cout<<"number of carton= "<<round(a);

return 0;

c) Outputs the cost of producing milk.

ANS) #include <iostream>

#include <math.h>

using namespace std;


int main()

double cartonHold,costofOneliter,profitofEachcarton,totalamountofMilk,a,b;

cartonHold = 3.78;

costofOneliter = 0.38;

profitofEachcarton = 0.27;

cout<<"totalamountofMilk= ";

cin>>totalamountofMilk;

a = totalamountofMilk / cartonHold;

b = a * costofOneliter;

cout<<"number of carton= "<<a<<endl;

cout<<"cost of milk= "<<b;

return 0;

d) Outputs the profit for producing milk.

ANS) #include <iostream>

#include <math.h>

using namespace std;

int main()

double cartonHold,costofOneliter,profitofEachcarton,totalamountofMilk,a,b,c;

cartonHold = 3.78;

costofOneliter = 0.38;
profitofEachcarton = 0.27;

cout<<"totalamountofMilk= ";

cin>>totalamountofMilk;

a = totalamountofMilk / cartonHold;

b = a * costofOneliter;

c = a * profitofEachcarton;

cout<<"number of carton= "<<a<<endl;

cout<<"cost of milk= "<<b<<endl;

cout<<"profit for milk= "<<c;

return 0;

Q20) You found an exciting summer job for five weeks. It pays, say, $15.50
per hour. Suppose that the total tax you pay on your summer job
income is 14%. After paying the taxes, you spend 10% of your net
income to buy new clothes and other accessories for the next school
year and 1% to buy school supplies. After buying clothes and school
supplies, you use 25% of the remaining money to buy savings bonds.
For each dollar you spend to buy savings bonds, your parents spend $0.50 to buy additional
savings bonds for you. Write a program that prompts the user to enter the pay rate for an hour
and the number of hours you worked each week. The program then outputs them following:

a) Your income before and after taxes from your summer job.

ANS) #include <iostream>


#include <cmath>
using namespace std;
int main()

{
double payRatehour,workedNumberofhours,beforeTax,afterTax,tax;
tax = 0.14;
cout << "payRatehour: " ;
cin>>payRatehour;
cout<<"workedNumberofhours: ";
cin>>workedNumberofhours;
beforeTax = payRatehour * workedNumberofhours;
afterTax = beforeTax * tax;
cout.precision(2);
cout<<"beforeTax: "<<beforeTax<<endl;
cout<<"afterTax: "<<afterTax;

return 0;
}

b) The money you spend on clothes and other accessories.

ANS) #include <iostream>


#include <cmath>
using namespace std;
int main()

{
double
payRatehour,workedNumberofhours,clothesotherAccessories,moneySpendonClothesaccessori
es,beforeTax,afterTax,tax;
tax = 0.14;
clothesotherAccessories = 0.10;
cout << "payRatehour: " ;
cin>>payRatehour;
cout<<"workedNumberofhours: ";
cin>>workedNumberofhours;
beforeTax = payRatehour * workedNumberofhours;
afterTax = beforeTax * tax;
moneySpendonClothesaccessories = afterTax * clothesotherAccessories;
cout.precision(2);
cout<<"beforeTax: "<<beforeTax<<endl;
cout<<"afterTax: "<<afterTax<<endl;
cout<<"moneyspendoneclothesandaccessories: "<<moneySpendonClothesaccessories;

return 0;
}

c) The money you spend on school supplies.

ANS) #include <iostream>


#include <cmath>
using namespace std;
int main()

{
double
payRatehour,workedNumberofhours,clothesotherAccessories,moneySpendonSchool,moneySp
endonClothesaccessories,schoolSupplies,beforeTax,afterTax,tax;
tax = 0.14;
clothesotherAccessories = 0.10;
schoolSupplies = 0.01;
cout << "payRatehour: " ;
cin>>payRatehour;
cout<<"workedNumberofhours: ";
cin>>workedNumberofhours;
beforeTax = payRatehour * workedNumberofhours;
afterTax = beforeTax * tax;
moneySpendonClothesaccessories = afterTax * clothesotherAccessories;
moneySpendonSchool = afterTax * schoolSupplies;
cout.precision(2);
cout<<"beforeTax: "<<beforeTax<<endl;
cout<<"afterTax: "<<afterTax<<endl;
cout<<"moneyspendoneclothesandaccessories: "<<moneySpendonClothesaccessories<<endl;
cout<<"moneySpendonschool: "<<moneySpendonSchool;

return 0;
}

d) The money you spend to buy savings bonds.

ANS) #include <iostream>


#include <cmath>
using namespace std;
int main()

{
double
payRatehour,savingBonds,workedNumberofhours,clothesotherAccessories,moneySpendonSch
ool,moneySpendonClothesaccessories,schoolSupplies,beforeTax,afterTax,tax;
tax = 0.14;
clothesotherAccessories = 0.10;
schoolSupplies = 0.01;
cout << "payRatehour: " ;
cin>>payRatehour;
cout<<"workedNumberofhours: ";
cin>>workedNumberofhours;
beforeTax = payRatehour * workedNumberofhours;
afterTax = beforeTax * tax;
moneySpendonClothesaccessories = afterTax * clothesotherAccessories;
moneySpendonSchool = afterTax * schoolSupplies;
savingBonds = 0.25 * (afterTax - moneySpendonClothesaccessories - moneySpendonSchool);
cout.precision(2);
cout<<"beforeTax: "<<beforeTax<<endl;
cout<<"afterTax: "<<afterTax<<endl;
cout<<"moneyspendoneclothesandaccessories: "<<moneySpendonClothesaccessories<<endl;
cout<<"moneySpendonschool: "<<moneySpendonSchool<<endl;
cout<<"savingBonds: "<<savingBonds;

return 0;
}

e) The money your parents spend to buy additional savings bonds for
you.

ANS) #include <iostream>


#include <cmath>
using namespace std;
int main()

{
double
payRatehour,savingBonds,workedNumberofhours,clothesotherAccessories,moneySpendonSch
ool,moneySpendonClothesaccessories,schoolSupplies,beforeTax,afterTax,tax,parentsSpend,add
itionalSavingbonds;
tax = 0.14;
clothesotherAccessories = 0.10;
schoolSupplies = 0.01;
parentsSpend = 0.50;
cout << "payRatehour: " ;
cin>>payRatehour;
cout<<"workedNumberofhours: ";
cin>>workedNumberofhours;
beforeTax = payRatehour * workedNumberofhours;
afterTax = beforeTax * tax;
moneySpendonClothesaccessories = afterTax * clothesotherAccessories;
moneySpendonSchool = afterTax * schoolSupplies;
savingBonds = 0.25 * (afterTax - moneySpendonClothesaccessories - moneySpendonSchool);
additionalSavingbonds = savingBonds * parentsSpend;
cout.precision(2);
cout<<"beforeTax: "<<beforeTax<<endl;
cout<<"afterTax: "<<afterTax<<endl;
cout<<"moneyspendoneclothesandaccessories: "<<moneySpendonClothesaccessories<<endl;
cout<<"moneySpendonschool: "<<moneySpendonSchool<<endl;
cout<<"savingBonds: "<<savingBonds<<endl;
cout<<"additionalSavingbonds: "<<additionalSavingbonds;

return 0;
}

Q23) Newton’s law states that the force, F, between two bodies of masses M1 and
M2 is given by:
F = k(M1M2/d2)
__
;
in which k is the gravitational constant and d is the distance between the
bodies. The value of k is approximately 6.67_10-8 dyn. cm2/g2.
Write a program that prompts the user to input the masses of the bodies and the
distance between the bodies. The program then outputs the force between
the bodies.

ANS) #include <iostream>


#include <math.h>
using namespace std;
int main()
{
double m1,m2,distance,k,f;
cout << "enter M1: ";
cin>>m1;
cout<<"enter M2: ";
cin>>m2;
cout<<"distance: ";
cin>>distance;
k = 13.34;
f = k *((m1 * m2) / (distance * distance));
cout<<"F= "<<f;

return 0;
}

Q24) One metric ton is approximately 2205 pounds. Write a program that
prompts the user to input the amount of rice, in pounds, in a bag. The
program outputs the number of bags needed to store one metric ton of rice.
ANS) #include <iostream>

#include <cmath>

using namespace std;

int main()

double rice,oneMetricton,bags;

oneMetricton = 2205;

cout<<"rice: ";

cin>>rice;

bags = oneMetricton / rice;

cout<<"bags: "<<bags;

return 0;

You might also like