Académique Documents
Professionnel Documents
Culture Documents
Step 1: Write the C++ program to do the following. Save your project name Lab2.cpp.
Tasks
1) write the following comments:
An application to find the sum
and average of three numbers.
Codes
/*An application to find the sum and
the average of three numbers*/
Int no1=0;
Int no2=0;
Int no3=0;
Int sumNum=0;
Double avgNum=0;
3) Input three numbers into variable no1, no2 and Cout<<please enter first
no3
number<<endl;
Cin>>no1;
Cout<<please enter second
number<<endl;
Cin>>no2;
Cout<<please enter third
4) Assign the total of no1, no2 and no3 to sumNum = no1+no2+no3;
variable sumNum
avgNum = sumNum/3
6) Display message The sum of ?, ? and Cout<< the sum of three number
is<<sumNum<<endl;
? is ?. The value of ? should be replaced
with the appropriate values from variables no1,
no2, no3 and sum
7) Display message The average of ?, ?
and ? is ?. The value of ? should be
replaced with the appropriate values from
variables no1, no2, no3 and avg
Step 3:
Test the program with data 15, 20, 30. Show the output of the program.
Step 4:
Explain the logical error that occurs in the application. Explain how to solve the
problem. Step 5:
Step 6:
Test the program with data 2, 3, 3. Show the output of the program.
Explain how to display the average of these numbers in two decimal points.
Writi
ng a C++ program
Step 1:
complete the following C++ program, which is used to convert a value from yard into
its equivalent value in the meter. Note 1 yard = ? meter
/**************************************************************
**
An application to convert a value from yard to meter
**************************************************************/
#include <iostream.h>;
void main()
{
double yard, meter;
//input yard
Coding iomanip.h
Write a program in below and display the output.
ASSIGNMENT
1. Write a program that takes as input a given length expressed in feet and inches. It then converts
and outputs the length in centimeters.
a. Input: Length in feet and inches.
b. Output: Equivalent length in centimeters.
c. The lengths are given in feet and inches
d. The program will need to find the equivalent length in centimeters
e. One inch is equal to 2.54 centimeters
2. Write a program that prompts the user for:
Cost per item
Number of item purchased
Discount rate
The program should then calculate and display the:
total cost
Total cost after discount
Tax due
Amount due
Assume Tax rate is
6% Use the formulas:
Total cost = number of items * cost per item
Total cost after discount = total cost (discount rate * total cost)
Tax due = total cost after discount *tax rate
Amount due = total cost after discount + tax due