Application of ICT Lab10
Application of ICT Lab10
(CL1009)
LABORATORY MANUAL
Fall 2024
LAB: 10
Basic Programs in C++
______________________________________
a. Create a C++ program that calculates and displays the BMI of the user. Take input for
weight in kilograms and height in meters.
CODE:
#include <iostream>
using namespace std;
int main()
{
double weight,height,bmi;
cout<<"Enter your weight in kilograms";
cin>>weight;
cout<<"Enter your height in meters";
cin>>height;
if (height>0)
{
bmi=weight/ (height*height);
cout<<"Your bmi is";
}
else{
cout<<"Invalid value";
}
return 0;
}
FlowChart:
Values:
a. Test your program and fill in the given table:
Task # 2:
a. Design, write, compile, and run a C++ program to calculate the volume of a sphere with
a radius, r. The volume is given by this formula:
(Use the symbolic constant PI in your code)
CODE:
#include <iostream>
using namespace std;
int main() {
return 0;
}
Test # Input by user Volume Calculated by Volume displayed by program
formula
1 Radius=5 523.33 523.3
FLOWCHART:
Task # 3:
The increase in length of a rectangular slab of metal that’s fixed at one end and pulled by a
force at its other end is given by this formula:
Code:
#include <iostream>
using namespace std;
int main() {
double F,L,A,E,deltaL;
deltaL = (F * L) / (A * E);
cout << "The increase in length (ΔL) is: " << deltaL << " mm" << endl;
return 0;
}
Input from user Output calculated by hand Output calculated by program
Length=3mm 2.9411 0.0294118
Width=4mm
Depth=2mm
Force=4 N
Ɛ(Aluminium)=68,950N/mm2
Task # 4:
Write a C++ program to calculate and display the value of the slope of the line connecting two
points. Use the fact that the slope between two points at the coordinates (x1,y1) and (x2,y2) is
slope = (y2 - y1) / (x2 - x1). Verify your answer.
Code:
#include <iostream>
using namespace std;
int main() {
double x1, y1, x2, y2, slope;
cout << "Enter the coordinates of the first point (x1, y1): ";
cin >> x1 >> y1;
cout << "Enter the coordinates of the second point (x2, y2): ";
cin >> x2 >> y2;
if (x2 == x1) {
cout << "Error: The x-coordinates cannot be the same." << endl;
return 1;
}
return 0;
}
Output: