0% found this document useful (0 votes)
7 views8 pages

Application of ICT Lab10

Uploaded by

umeralam006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Application of ICT Lab10

Uploaded by

umeralam006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Application of ICT Lab

(CL1009)
LABORATORY MANUAL
Fall 2024

LAB: 10
Basic Programs in C++

____M.Umer Alam____________________________________ __6199________ __A_


_
STUDENT NAME ROLL NO SEC

______________________________________

LAB ENGINEER'S SIGNATURE & DATE


Engr. Fasih Ahmed
Engr. Sana Saleh
Engr. Nimra Fatima

MARKS AWARDED: /10


Task # 1:

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:

Test # Input by user BMI Calculated by formula BMI displayed by program


1 Weight=55 22.03 22.03
Height=1.58

2 Weight=68 21.95 21.95


Height=1.76

3 Weight=40 16.64 16.64


Height=1.55

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;

const double PI = 3.14;

int main() {

double radius, volume;


cout << "Enter the radius of the sphere: ";
cin >> radius;
volume = (4.0 / 3.0) * PI * (3*3 *3);

return 0;
}
Test # Input by user Volume Calculated by Volume displayed by program
formula
1 Radius=5 523.33 523.3

2 Radius=6.5 1149.763 1149.7

3 Radius=100.5 42497 4249.1

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;

cout << "Enter the applied force (F) in Newtons: ";


cin >> F;
cout << "Enter the original length (L) in mm: ";
cin >> L;
cout << "Enter the cross-sectional area (A) in mm²: ";
cin >> A;
cout << "Enter the Young's modulus (E) in N/mm²: ";
cin >> E;

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;
}

slope = (y2 - y1) / (x2 - x1);


cout << "The slope of the line: " << slope << endl;

return 0;
}
Output:

You might also like