Professional Documents
Culture Documents
Assignment 1 CP
Assignment 1 CP
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;
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;
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;
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)