You are on page 1of 7

[Year]

CP ASSIGNMENT 01
WARISHA AAMIR
02-235231-044
BSIT 1(A)
WARISHA AAMIR 02-235231-044 BSIT 1(A)
BAHRIA UNIVERSITY,
(Karachi Campus)
Assignment # 01 – Spring 2023
COURSE TITLE: COMPUTER PROGRAMMING COURSE CODE: CSC-113
CLASS: BCE-2A SHIFT: Morning
INSTRUCTOR: ENGR. DR. RIZWAN IQBAL

Question No. 1:

Write a program to print the circumference and area of a circle of radius entered by user by defining your
own function.

CODE:

//task 1
#include <iostream>
using namespace std;

const double PI = 3.14159;

int calculate_circumference_and_area(double radius, double& circumference, double& area) {


circumference = 2 * PI * radius;
area = PI * radius * radius;
}

int main() {
double radius, circumference, area;
cout << "Enter the radius of the circle: ";
cin >> radius;
calculate_circumference_and_area(radius, circumference, area);
cout << "The circumference of the circle is: " << circumference << endl;
cout << "The area of the circle is: " << area << endl;
return 0;
WARISHA AAMIR 02-235231-044 BSIT 1(A)

OUTPUT:
Question 02:
A person is elligible to vote if his/her age is greater than or equal to 18. Define a function to find out if
he/she is elligible to vote.
CODE:

//task 2

#include <iostream>1
using namespace std;

bool is_eligible_to_vote(int age) {


return age >= 18;
}
int main() {
int age;
cout << "Enter your age: ";
cin >> age;
if (is_eligible_to_vote(age)) {
cout << "You are eligible to vote!" << endl;
} else {
cout << "Sorry, you are not eligible to vote." << endl;
}
return 0;
}

OUTPUT:
WARISHA AAMIR 02-235231-044 BSIT 1(A)

Question 03:
Write a program which will ask the user to enter his/her marks (out of 100). Define a function that will
display grades according to the marks entered as below:
Marks Grade
91-100 AA
81-90 AB
71-80 BB
61-70 BC
51-60 CD
41-50 DD
<=40 Fail

CODE:
WARISHA AAMIR 02-235231-044 BSIT 1(A)
//task 3

#include <iostream>
using namespace std;

void display_grade(int marks) {


if (marks >= 91 && marks <= 100) {
cout << "Grade: AA" << endl;
} else if (marks >= 81 && marks <= 90) {
cout << "Grade: AB" << endl;
} else if (marks >= 71 && marks <= 80) {
cout << "Grade: BB" << endl;
} else if (marks >= 61 && marks <= 70) {
cout << "Grade: BC" << endl;
} else if (marks >= 51 && marks <= 60) {
cout << "Grade: CD" << endl;
} else if (marks >= 41 && marks <= 50) {
cout << "Grade: DD" << endl;
} else {
cout << "Grade: Fail" << endl;
}
}

int main() {
int marks;
cout << "Enter your marks (out of 100): ";
cin >> marks;
display_grade(marks);
return 0;
}

OUTPUT:
WARISHA AAMIR 02-235231-044 BSIT 1(A)

Question 04:
Define a function to find out if number is prime or not
CODE:

// task 4

#include <iostream>
using namespace std;

bool is_prime(int n) {
if (n <= 1) {
return false;
}
for (int i = 2; i < n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
int main() {
int n;
cout << "Enter a positive integer: ";
cin >> n;
if (is_prime(n)) {
cout << n << " is a prime number." << endl;
} else {
cout << n << " is not a prime number." << endl;
}
return 0;
}

OUTPUT:
WARISHA AAMIR 02-235231-044 BSIT 1(A)

You might also like