KEMBAR78
PF Lab 2 | PDF | Computer Programming | Naming Conventions
0% found this document useful (0 votes)
23 views5 pages

PF Lab 2

The document contains a programming assignment with five tasks that involve writing C++ programs. The tasks include checking if a number is even or odd, calculating a bonus based on years of service, determining eligibility for a cricket club based on age and weight, validating a triangle based on its sides, and calculating a student's grade based on marks. Each task is accompanied by a code snippet demonstrating the solution.
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)
23 views5 pages

PF Lab 2

The document contains a programming assignment with five tasks that involve writing C++ programs. The tasks include checking if a number is even or odd, calculating a bonus based on years of service, determining eligibility for a cricket club based on age and weight, validating a triangle based on its sides, and calculating a student's grade based on marks. Each task is accompanied by a code snippet demonstrating the solution.
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/ 5

PROGRAMMING FUNDAMENTALS

ASSIGNMENT #2

NAME: Ghulam Mohi ud din ID: F2024105031


SECTION: Y1

Q.01: Write a program that takes a number as


input and checks whether it is even or odd.

#include <iostream>
using namespace std;

int main() {
int num;
cout << "Enter a number: ";
cin >> num;

if (num % 2 == 0) {
cout << num << " is even ";
} else {
cout << num << " is odd ";
}
return 0;
}
Q.02: A company gives a bonus of 15% to employees if
their years of service are more than 5 years. Write a
program to calculate the bonus if the user's basic salary
and years of service are provided.

#include <iostream>
using namespace std;

int main()
{
double bs;
int ys;
double b = 0.0;

cout << "Enter basic salary: ";


cin >> bs;

cout << "Enter years of service: ";


cin >> ys;

switch (ys > 5) {


case true:
b = bs * 0.15;
break;
case false:
b = 0.0;
break;
}
cout << "Bonus: " << b << endl;
return 0;
}

Q.03: Write a program to determine whether a person


can join a cricket club or not. Enter age and weight from
the user.

#include <iostream>
using namespace std;

int main() {
int age;
float weight;

cout << "Enter your age: ";


cin >> age;
cout << "Enter your weight: ";
cin >> weight;

if (age > 18 && weight > 50) {


cout << " Congrats you are eligible to join the cricket club.";
} else {
cout << "Sorry you are not eligible to join the cricket club.";
}

return 0;
}
Q.04: Write a program to accept three sides of a triangle
and determine whether the triangle is valid or not.

#include <iostream>
using namespace std;

int main() {
float side1, side2, side3;

cout << "Enter side 1: ";


cin >> side1;
cout << "Enter side 2: ";
cin >> side2;
cout << "Enter side 3: ";
cin >> side3;

if (side1 + side2 > side3 && side2 + side3 > side1 &&
side1 + side3 > side2) {
cout << "The triangle is valid.";
} else {
cout << "The triangle is not valid.";
}
return 0; }
Q.05: Write a program to calculate a student’s grade.

#include <iostream>
using namespace std;
int main() {
int marks;

cout << "Enter student's marks: ";


cin >> marks;

if (marks > 92) {


cout << "Grade A";
} else if (marks >= 82 && marks <= 91) {
cout << "Grade B";
} else if (marks >= 72 && marks <= 81) {
cout << "Grade C";
} else if (marks >= 61 && marks <= 71) {
cout << "Grade D";
} else {
cout <<”Fail";
}

return 0;
}

You might also like