0% found this document useful (0 votes)
21 views9 pages

OODP Week2

Uploaded by

kthecoder5
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)
21 views9 pages

OODP Week2

Uploaded by

kthecoder5
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/ 9

1)

#include <iostream>

#include <cmath>

using namespace std;

int main() {

double timeInSeconds;

const double acceleration = 32.0; // acceleration due to gravity in feet/second^2

cout << "Enter the time in seconds: ";

cin >> timeInSeconds;

double distance = 0.5 * acceleration * pow(timeInSeconds, 2);

cout << "The distance the object falls in freefall for " << timeInSeconds << " seconds is: " <<
distance << " feet." << endl;

return 0;

}
2)

#include <iostream>

#include <cmath>

using namespace std;

int main() {

double radius;

const double PI = 3.14;

cout << "Enter the radius of the globe: ";

cin >> radius;

double volume = (4.0 / 3.0) * PI * pow(radius, 3);

cout << "The volume of the globe is: " << volume << " cubic units." << endl;

return 0;

}
3)

#include <iostream>

using namespace std;

int main() {

double previousAnnualSalary;

const double compensationPayPercentage = 11.5;

cout << "Enter employee's previous annual salary: ";

cin >> previousAnnualSalary;

double payIncrease = previousAnnualSalary * (compensationPayPercentage / 100);

double newAnnualSalary = previousAnnualSalary + payIncrease;

double newMonthlySalary = newAnnualSalary / 12;

double oldMonthlySalary = previousAnnualSalary / 12;

cout << "Previous Annual Salary: $" << previousAnnualSalary << endl;

cout << "New Annual Salary: $" << newAnnualSalary << endl;

cout << "New Monthly Salary: $" << newMonthlySalary << endl;

cout << "Old Monthly Salary: $" << oldMonthlySalary << endl;

cout << "Compensation Pay Received: $" << payIncrease << endl;

return 0;

}
4)

#include <iostream>

using namespace std;

int main() {

double weight, height;

cout << "Enter weight in kilograms: ";

cin >> weight;

cout << "Enter height in meters: ";

cin >> height;

double BMI = weight / (height * height);

cout << "BMI is: " << BMI << endl;

return 0;

}
6)

#include <iostream>

using namespace std;

int main() {

int quantity;

const double unitCost = 100.0;

cout << "Enter the quantity: ";

cin >> quantity;

double totalCost = quantity * unitCost;

if (totalCost > 1000) {

totalCost *= 0.9; // apply 10% discount

cout << "Total cost: $" << totalCost << endl;

return 0;

}
7)

#include <iostream>

using namespace std;

int main() {

int marks;

cout << "Enter marks: ";

cin >> marks;

char grade;

if (marks < 25) {

grade = 'F';

} else if (marks < 45) {

grade = 'E';

} else if (marks < 50) {

grade = 'D';

} else if (marks < 60) {

grade = 'C';

} else if (marks < 80) {

grade = 'B';

} else {

grade = 'A';

cout << "Grade: " << grade << endl;

return 0;

}
8)

#include <iostream>

using namespace std;

int main() {

double temperature;

cout << "Enter temperature: ";

cin >> temperature;

if (temperature >= 80) {

cout << "Swimming" << endl;

} else if (temperature >= 60) {

cout << "Tennis" << endl;

} else if (temperature >= 40) {

cout << "Golf" << endl;

} else {

cout << "Skiing" << endl;

return 0;

}
9)

#include <iostream>

using namespace std;

int main() {

double currentSalary;

int performanceRating;

cout << "Enter current annual salary: ";

cin >> currentSalary;

cout << "Enter performance rating (1=excellent, 2=good, 3=poor): ";

cin >> performanceRating;

double raisePercentage;

switch (performanceRating) {

case 1:

raisePercentage = 0.06;

break;

case 2:

raisePercentage = 0.04;

break;

case 3:

raisePercentage = 0.015;

break;

default:

raisePercentage = 0.0;

double raiseAmount = currentSalary * raisePercentage;

double newSalary = currentSalary + raiseAmount;

cout << "Raise Amount: $" << raiseAmount << endl;

cout << "New Salary: $" << newSalary << endl;

return 0;}
10)

#include <iostream>

using namespace std;

int main() {

double marks;

cout << "Enter marks: ";

cin >> marks;

if (marks >= 50) {

char grade;

if (marks >= 85)

grade = 'E';

else if (marks >= 75)

grade = 'O';

else if (marks >= 65)

grade = 'G';

else

grade = 'S';

cout << "Pass. Grade: " << grade << endl;

} else {

if (marks >= 33)

cout << "Fail. Resit in exam." << endl;

else

cout << "Fail. Redo." << endl;

return 0;

You might also like