PF FALL2023 Assignment3
PF FALL2023 Assignment3
SCIENCESISLAMABAD CAMPUS
Programming Fundamentals - FALL
2023
ASSIGNMENT- 3
Due Date: 31-10-2023 (11:59 PM)
Please follow the following submission instructions. Failure to submit according to the format
would result in a deduction of marks. Submissions other than Google classroom (e.g., email
etc.) will not be accepted. No late submission will be accepted. Correct and timely
submission of the assignment is the responsibility of every student; hence no relaxation
will be given to anyone.
Instructions: Total Marks: 145
Honor Policy
This assignment is a learning opportunity that will be evaluated based on your ability.
Plagiarism cases will be dealt with strictly. Plagiarism of any kind (copying from others,
copying from the internet etc.) is not allowed. If found plagiarized, both the involved parties
will be awarded zero marks in this assignment, all the remaining assignments, or even an F
grade in the course.
Submission Guidelines
1. Dear students, we will be using auto-grading tools, so failure to submit according
to the below format would result in zero marks in the relevant evaluation
instrument.
2. For each question in your assignment, make a separate .cpp file e.g., for question
1, make q1.cpp and so on. Each file that you submit must contain your name,
student-id, and assignment # on top of the file in the comments.
3. Combine all your work in one folder. The folder must contain only .cpp files (no
binaries, no exe files etc.).
4. Rename the folder as ROLL-NUM_PROGRAM_SECTION (e.g., 23i-
0001_AI/DS_B) and compress the folder as a zip file. (e.g., 23i-0001_AI_B.zip).
5. Submit the .zip file on Google Classroom within the deadline.
6. The student is solely responsible to check the final zip files for issues like corrupt
file, virus in the file, mistakenly exe sent. If we cannot download the file from
Google classroom due to any reason it will lead to zero marks in the assignment.
Note: Start early so that you can finish it on time.
Example :
Input : 8
Number : 0112358
Pattern:
Input : 5
Number : 011235
Pattern :
Input : 6
Invalid Input Number is not Fibonacci.
Note : DO IT USING WHILE LOOP ONLY
Bonus : If your code is able to print for (13) and (21) input you will get 5 numbers as
bonus.
Think about it :)
Create a simplified C++ program for a two-player Tic Tac Toe game using Loops. The game's
functionality includes:
1. Displaying a 3x3 game board with a numbered grid to help players select their moves.
2. Allowing two players to take turns, one using 'X' and the other 'O.'
3. Verifying the validity of each move (i.e., the chosen cell is within the board
boundaries).
4. Checking for a win condition or a draw after each move.
5. Prompting players to make their moves by specifying the 0-9.
6. Displaying the updated game board after each move.
7. Announcing the winner or a draw when the game ends.
8. Ending the game automatically after nine moves if no winner is determined.
9. Providing a player-friendly experience with clear prompts and messages.
Your task is to code and add the necessary logic to determine the game's outcome (win, draw,
or continue) after each move. Also, it should also print the board after every move. Ensure that
the game runs smoothly and accurately. The game should continue until a player wins or the
game ends in a draw.
Note: Arrays or Functions are not allowed
The Josephus Problem is a classic mathematical puzzle with various applications in computer
science and beyond. It involves a group of people standing in a circle, and one person is
eliminated in a sequential manner until only one remains. The challenge is to determine the
position of the last person standing, given the total number of people and a fixed counting
interval.
Scenario:
Imagine you are a computer science student working on a programming project. Your professor
assigns you the task of solving the Josephus Problem using a programming language of your
choice. The professor wants to assess your problem-solving skills and understanding of
iterative algorithms.
Objectives:
1. Write a program in C++ to find the position of the last person standing in the Josephus
Problem.
2. Implement the program using an iterative approach.
3. Handle user input for the number of people and the counting interval.
4. Ensure that the program produces the correct result and runs efficiently for reasonably
large inputs.
Outputs:
Enter the number of people (n): 10
Enter the step (k): 2
The last person is standing at position: 5
Write a C++ program that generates a prime spiral of numbers for a given positive integer N.
The prime spiral should start from 1 and go up to N^2, and for each number in the spiral
position, the function should print "P" if it's prime or "." if it's not.
For example
When N is 4, the generated prime spiral should look like this:
P P P .
P . P .
. . P .
P . . .
P P P . P .
P . . . P .
P . . . P .
P . . . P .
. . . . P .
P . . . . .
Write a program in C++ that should take user input for the value of 'x' and the number of terms
'n' to use in the Maclaurin series, and then calculate and display the approximation of sin(x)
based on the Maclaurin series formula.
Note : No built-in functions are allowed.
Requirements:
1. The program should prompt the user for a decimal number (base 10).
2. The program should prompt the user for the target base, which must be between 2 and
16 (inclusive).
3. The program should use a while loop to perform the conversion.
4. If the target base is between 2 and 10, the program should output the result as an integer.
5. If the target base is greater than 10, the program should output the result as a string
using 'A' for 10, 'B' for 11, and so on, up to 'F' for 15.
6. The program should validate user inputs and provide error messages for invalid input.
2. Generate and display the calendar for the specified month and year. The calendar
should be displayed in a grid format with the following features:
3. The month and year should be displayed at the top center of the calendar.
4. The days of the week (Sunday, Monday, Tuesday, etc.) should be displayed above
the calendar.
5. Each date in the grid should be labeled with the day of the month, and empty spaces
should be left for days that fall outside the specified month.
6. Make sure that the dates align correctly with the days of the week.
7. The program should continue running until the user chooses to exit.
Write a program in C++ to generate Pascal's Triangle of a specified number of rows. After calculating
the sum and product of all numbers in triangle.