Assignment-03 1-1
Assignment-03 1-1
Assignment # 3
Subject: Introduction to Computing and AI Course Code: CS - 101 - I, F - 24
Class: BS DS– 1st Submission Deadline: 21/Nov/2024 - Thu (9:00 - AM)
Course Instructor: Ms. Nazia Shahzadi - Lecturer - Total Marks: 50 (Marks are divided problem-wise)
FCSE
Course TA’s: Ms. Sabahat Gul
First, read the instructions and statements of each exercise/question carefully then write the solution.
• For Handwritten/Printed Form:
o In case of multiple questions, give the heading of each question’s number or the task you are going to
solve
o Mention the page number and your roll number at the corner of each page.
o Then select all pictures in the Cam scanner application and convert them into a PDF file.
o The name of your pdf file should contain your assignment number and your roll number as shown in the
following example, For Example, if your roll number is 2024532 and you have done assignment number 2
then the name of the file should be as → 2024532_2.pdf
o Then upload that pdf file to Microsoft Teams. Remember the sequence of pages should be right.
o Also submit the same original pages/hardcopy (in printed form) in Thursday’s class (21/11/2024).
CHEATING/COPY CASE or LATE SUBMISSION even 1 minute late will be resulted into MARKS
DEDUCTION .So be on time make no excuse.
Question#1 Points-10
An integer is said to be prime if it’s divisible by only 1 and itself. For example,
2, 3, 5, and 7 are prime, but 4, 6, 8, and 9 are not.
• Write a function that determines whether a number is a prime.
• Use this function in a program that identifies and prints all the prime numbers between 2
and 10,000. How many of these numbers do you really have to test before being sure that
you’ve found all the primes?
Page 1 of 3
Question#2 Points-10
Implement a clock by writing a C++ program that asks the user to enter an hour value and a minute
value. The main () function should then pass these two values to a type void function that displays
the two values in the format shown in the following sample run:
Enter the number of hours: 9
Enter the number of minutes: 28
Time: 9:28
Question#3 Points-10
Write a function that computes the distance between two points (x1, y1) and (x2, y2). All numbers
and return values should be of type double.
Question#4 Points-10
Write a program that plays the game of “guess the number” as follows:
Your program chooses the number to be guessed by selecting an integer at random in the range 1
to 1000. The program then types:
If the player's guess is incorrect, your program should loop until the player finally gets the number
right. Your program should keep telling the player Too high or too low to help the player “zero
in” on the correct answer.
Question#5 Points-10
Page 2 of 3
a) Write a function Fibonacci (n) that calculates the nth Fibonacci number.
b) Modify the program of part a) to use double instead of int to calculate and return Fibonacci
numbers and use this modified program to repeat part b).
Page 3 of 3