Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Muhammad Labeeb

F2023376073

Problem 2
Pseudo code:
input=inches Execution=inches*2.54
output cm
Steps
1take input in inches from the user
2.declare value of cm=2.54 and store in it
3 multiply inches with 2.54 to get cm
4. print cm

C++ code:
#include <iostream>
using namespace std;
int main() { float
inches=0;
cout << "enter the length In inches"; cin>>inches; float
cm=inches*2.54; cout<<cm<<"cm"; cout<<cm<<"cm";
return 0;
}
Problem 3
Pseudo code:
1. Input the radius (r) of the sphere
2. Calculate the area (area) using the formula: area = 4 * 3.14 * r^2
3. Calculate the volume (volume) using the formula: volume = (4/3) * 3.14 * r^3
4. Print the area and volume
C++ CODE :
#include <iostream> using namespace
std; int main()
{
float radius=0; float area=0; float
volume=0;
cout<<"enter the radius: ";
cin>> radius;
area=(4*3.142*(radius * radius));
volume=((4/3)*(3.142* radius* radius*radius));
cout<<"area is:"<<area<<endl;
cout<<"volume is:"<<volume;
return 0;
}
Muhammad Labeeb
F2023376073

Problem 4
Pseudo code:
1. Declare variables int :area, radius, h, volume, pi
2. Input The int radius From the user
3. Input int h from the user
4. Calculate area = 2 * pi * radius * radius + 2 * pi * radius * h
5. Display area
6. Calculate volume = pi * radius * radius * h print volume
C++ CODE:
#include <iostream>
using namespace std;
int main()
{
int area; int radius; int h; float volume; float pi=3.14;
cout<<"Enter radius";
cin>>radius;
cout<<"Enter h";
cin>>h;
area = 2*3.14* radius *radius +2*3.14*radius*h;
cout << area <<endl;
volume= 3.14*radius*radius*h;
cout<< volume<<endl;
return 0;
}

Problem 5
Pseudo code:
1. Initialize the gravitational constant 'k' with the value 6.67E-8.
2. Input the value of float M1 from the user.
3. Input the value of float M2 from the user.
4. Input the value of float d (distance between the two bodies) from the user.
5. Calculate the force using the formula: force = (k * M1 * M2) / (d * d).
6. print the calculated force between the two bodies.

CODE C++:
#include <iostream>
using namespace std;
int main()
{
Muhammad Labeeb
F2023376073

float k=6.67E-8; float M1; float M2; float d;


float force;
cout<<"Enter M1";
cin>> M1;
cout<<"Enter M2";
cin>>M1;
cout<<"Enter d";
cin>>d;
force=(k *M1*M2)/(d*d);
cout<< "the force between two bodies";
return 0;
}

Problem 6
PSEUDO CODE:
1. input int number from the user
2. Calculate int digit1 = number % 10
3. Calculate int digit2 = (number / 10) % 10
4. Calculate int digit3 = number / 100
5. Calculate int sum = digit1 + digit2 + digit3
6. Calculate int reversedNumber = digit1 * 100 + digit2 * 10 + digit3
7. Print "Sum of digit: " + sum
8. Print"Reverse of given number: " + reversedNumber

C++ CODE:
#include <iostream>
using namespace std;
int main()
{
int number;
cout << "Enter the three digits Number: ";
cin >> number;
int digit1 = number % 10;
int digit2 = (number / 10) % 10;
int digit3 = number / 100;
int sum = digit1 + digit2 + digit3;
int reversedNumber = digit1 * 100 + digit2 * 10 + digit3;
cout << "Sum of digit: " << sum << endl;
cout << "Reverse of given number: " << reversedNumber << endl;
return 0;
}
Muhammad Labeeb
F2023376073

Problem 7
Pseudo code:
1. Declare variables a, b, c, q, r, m, and z as float type.
2. Prompt the user to enter all values using cout statement and read them using cin statement.
3. Calculate the value of z using the given formula:
- Multiply 8.8 and add a and b, then divide by c.
- Add 0.5 to the result.
- Multiply 2a and divide by (q+r). Then, multiply the result by (1/m).
4. Display the value of z using cout statement.
5. Return 0 to indicate successful execution of the program.
C++ CODE:
#include <iostream>
using namespace std;
int main()
{
float a,b,c,q,r,m; float z=0;
cout<<"enter all values:";
cin>>a>>b>>c>>q>>r>>m;
z=8.8*(a+b)*2/c - 0.5+2*a/(q+r)/(a+b)*(1/m);
cout<<"print z:"<<z;
return 0;
}
Problem 8
Pseudo code:
1. Input basic salary in float from the user.
2. Initialize variables for dearness allowance, house rent allowance, gross salary, and annual salary.
3. Calculate dearness allowance (37% of basic salary).
4. Calculate house rent allowance (25% of basic salary).
5. Calculate gross salary (basic salary + dearness allowance + house rent allowance).
6. Calculate annual salary (12 times the gross salary).
7. Print gross salary and annual salary.
C++ Code:
#include <iostream>
using namespace std;
int main()
{
float basicSalary;
cout << "Enter Khursheed's basic salary: ";
cin >> basicSalary;
Muhammad Labeeb
F2023376073

float dearnessAllowance;
float houseRentAllowance;
float grossSalary;
float annualSalary;
dearnessAllowance = 0.37 * basicSalary;
houseRentAllowance = 0.25 * basicSalary;
grossSalary = basicSalary + dearnessAllowance + houseRentAllowance;
annualSalary = 12 * grossSalary;
cout << "\nKhursheed's Gross Salary: " << grossSalary << endl;
cout << "Khursheed's Annual Salary: " << annualSalary << endl;
return 0;
}

Problem 9
Pseudo code:
1. Declare variables for marks in English, Calculus, and PF as floating-point numbers.
2. Input from the user to enter float marks in English 4. Input from user to enter float marks in
Calculus.
3. Input from the user to enter float marks in PF.
4. Calculate the total marks as the sum of marks in English, Calculus, and PF.
5. Calculate the average marks as the total marks divided by the number of subjects (3).
6. Declare a constant variable for the maximum marks per subject as 100.0. 11. Calculate the
percentage as (total marks / (3 * maximum marks per subject)) * 100.
7. 12. Print the average marks and percentage.
C++ CODE:
#include <iostream>
using namespace std;
int main()
{
float marksEnglish; float marksCalculus; float marksPF;
cout << "Enter the Marks in English: ";
cin >> marksEnglish;
cout << "Enter the Marks in Calculus: ";
cin >> marksCalculus;
cout << "Enter the Marks in PF: ";
cin >> marksPF;
float totalMarks = marksEnglish + marksCalculus + marksPF;
float averageMarks = totalMarks / 3;
const float maxMarksPerSubject = 100.0;
float percentage = (totalMarks / (3 * maxMarksPerSubject)) * 100;
cout << "Average of Marks: " << averageMarks << endl;
Muhammad Labeeb
F2023376073

cout << "Percentage of Marks: " << percentage << endl;


return 0;
}

You might also like