Programming Fundamentals (CS 1002) Fall 2021 Assignment # 2: Due Date
Programming Fundamentals (CS 1002) Fall 2021 Assignment # 2: Due Date
Instructions
Please follow the following submission instructions. Failure to submit according to the above
format would result in deduction of 10% marks. Submissions on the email will not be
accepted.
• Combine all your work (solution folder) in one .zip file. Use proper naming convention
for your submission file. Name the .zip file as SECTION_ROLL-NUM_02.zip (e.g.
A_21i0412_02.zip). Your zip file should only contain .cpp files, each file should
correspond to its question/problem number. Submit .zip file on Google Classroom
within the deadline.
Plagiarism: Plagiarism cases will be strictly dealt with. If found plagiarized, both the involved
parties will be awarded zero marks in this assignment, all of the remaining assignments, or
even an F grade in the course. Copying from the internet is the easiest way to get caught!
Deadline: The deadline to submit the assignment is Sunday, November 14, 2021 (05:00 pm).
Late submission with marks deduction will be accepted. Correct and timely submission of the
assignment is the rresponsibility of every student; hence no relaxation will be given to anyone.
Marking criteria: Your submitted programs will be marked on the following criteria.
Functional requirements 50%
Good user interface (user friendly instructions, layout, presentation) 20%
Proper source code indentation 10%
Programming conventions followed (e.g. variable names, ) 20%
Problem 2: Write a C++ program that takes up to 10-digit integer input from user (can be 1 digit, 2
digit, and so on..); passes this to a function which reverses the digits. Finally, the reversed number
should be displayed in the main function. For example: when user enters 10-digit like 1234567890
your function will reverse it to 987654321. Be careful for big integer values. [use functions, decision
control]
• Prompts user to enter two large integer numbers (x, y). Both numbers must be more
than 4 digits and less than 10 digits (do input validation, don’t use strings). The entered
numbers could be negative or positive. For example: 820778 and -58712979 where x is
6-digit positive number and y is 8-digit negative number.
• Make a function called Karatsuba() which takes these two integers and returns the
multiplication result using Karatsuba algorithm. You might need to make another helper
function called getDigits() which will get an integer as input and returns number of digits
of that integer. getDigits() will help you find the value of m and Bm.
• Display result in the main function.
Problem 4: The information about colours is to be stored in bits of a variable called colour. The bit
number 0 to 7, each represent 8 colours of a rainbow, i.e. bit 1 represents Blue, 2 represents Green,
and so on (see table below). Write a C++ program that asks the user to enter a number and based on
this number, an eight lined rainbow (of asterisks *) is to be displayed, such that, if the bit is ON,
respective colour is displayed otherwise black line is drawn (not visible).
You will need bit masking, that is, if you want to check whether most significant bit is ON or OFF, you
will have to do bitwise AND as follows:
See help material: Google Class Room -> All PF Course Material -> Reference Material -> Bit Level
Operations.html
Problem 5: In a Military database system, IDs of the army personnel are stored in a 32-bit value
which is coded as follows:
Problem 6: Write a C++ program to perform 128-bit encryption and decryption using XOR operation.
Your program must ask for 128-bit key and plain text then perform encryption and decryption.
Problem 8: Write a lottery game application that will generate three random numbers each between
0 and 9. The user should guess three numbers and the program should compare each of the user's
guess to the three random and display an appropriate output based on whether they got:
• any one matching
• two matching
• three matching, not in order
• three matching in exact order
• or no matches at all
Problem 9: A library charges a fine for every book returned late. For first 5 days the fine is 50 rupees,
for 6-10 days fine is 100 rupees and above 10 days fine is 150 rupees. If you return the book after 30
days your membership will be cancelled. Write a program to accept the number of days the member
is late to return the book and display the fine or the appropriate message.
Problem 10: Any character is entered through the keyboard, write a program to determine whether
the character entered is a capital letter, a small case letter, a digit or a special symbol.
Problem 11: The colors red, yellow and blue are known as the primary colors because they cannot be
made by mixing other colors. When you mix two primary colors, you get a secondary color, as shown
here:
o When you mix red and blue, you get purple.
o When you mix red and yellow, you get orange.
o When you mix blue and yellow, you get green.
Write a program that prompts the user to enter the first letter of names of two primary colors to mix.
If the user enters anything other than “r,” “b,” or “y,” the program should display an error message.
Otherwise, the program should change textcolor to that color displays the name of the secondary
color that results. Implement it using if\else structure and then switch structure.
Problem 13: Write a code that takes two integers as input representing a month and day and prints
the season for that month and day. Assume that months are specified as an integer between 1 and 12
(1 for January, 2 for February, and so on) and that the day of the month is a number between 1 and
31. If the date falls between 16/12 and 15/3, you should print "Winter". If the date falls between 16/3
and 15/6, you should print "Spring". If the date falls between 16/6 and 15/9, you should print
"Summer". And if the date falls between 16/9 and 15/12, you should print "Fall".