Programming Fundamentals (CS 1002)
Problem 1:
Your Task is to write a C++ Program which inputs a CNIC number, and a string Name of the
student. Your Program will separate the relevant info and prints the information in the following
manner.
Enter Name of Student: Hamza
Enter ID of Student: 6110166903075
Gender of Hamza is: Male
Province of Hamza is: Islamabad
Division of Hamza is: Islamabad-1
District of Hamza is: Islamabad-1
Tehsil of Hamza is: Islamabad-1
Union Council of Hamza is: Islamabad-1
Family Tree of Hamza is: 6690307
Problem 2: Implement a game of hi-lo. First, your program should pick a random integer between
1 and 100. Your solution should handle invalid guesses (e.g. ‘x’), out of bounds guesses (e.g. 0 or
101), or valid guesses that have extraneous characters (e.g. 69x). The user is given 5 tries to guess
the number.
If the user does not guess the correct number, the program should tell them whether they guessed
too high or too low. If the user guesses the right number, the program should tell them they won.
If they run out of guesses, the program should tell them they lost, and what the correct number is.
Problem 3: You were orphaned at an early age. To make ends meet, you sought work in a local
toy car workshop in your city, and your job is to build toy cars from a collection of parts. Each toy
car needs 4 wheels, 1 car body, and 2 figures of people to be placed inside. You notice that
sometimes, you’ll get orders of the number of cars to make, but you won’t have the total required
parts available. To prevent this, you want to find out how many complete toy cars can you make,
given the total number of wheels, car bodies and figures available at hand currently.
Problem 4: A shape with four vertices and sides is known as a quadrilateral. Square, rectangle,
kite, rhombus, trapezium, and parallelogram are all quadrilaterals. Write a C++ program for
guessing the type of the quadrilateral. Your program should guess correctly, in case of incorrect
input, display appropriate message. Phrase all questions in a way that user must enter some boolean
value Y/N as an answer. Both Y/y are treated as ‘Yes’.
Example:
Think of a quadrilateral from square, rectangle, kite, rhombus, trapezium and parallelogram and I
will guess it....
Let’s start
[Optional: you can place counter here like display 3, 2, 1....]
Q1. Are all sides equal? (Y or N) Y Q2. Are
all angles 90 degrees? (Y or N) Y
I got it! It’s a SQUARE.
Problem 5: Imagine your developing software that requires the user to enter the password. Your
software requires that user’s password meet the following criteria.
a. The password should be at least six characters long.
b. The password should contain at least one uppercase and at least one lower case letter.
c. The password should have at least one digit.
Write a program that ask for the password and then verifies that it meets the stated criteria.
Problem 6: Check whether a given number is the power of 2 or not using bitwise operator.
Remember a binary number that is a power of 2 has only 1 bit = 1 in their binary representation.
e.g. 2 = 0010, 4 = 0100, 8 = 1000, 16 = 10000, 32 = 100000, 64 = 1000000.
Problem 7: Check whether a number is even or odd WITHOUT using loops, arithmetic operators,
and comparison operators.
Problem 8: You are working at an embedded systems software. Your primary goal is speed, and
you are researching on ways to optimize the overall speed and responsiveness of the system. You
notice that whenever you perform multiplication or division, your program takes a longer than
desired time to do it. You are researching on ways to increase this speed, as a core functionality of
your program is computing the average of numbers. Your goal is to find the average of two numbers
WITHOUT using arithmetic operators.
Problem 9: Write a C++ program that gives the largest number using ternary operator among:
1. Three Numbers that is if three numbers are taken as input form user.
2. Four Numbers that is if four numbers are taken as input form user.
Problem 10: Attempt the following by writing C++ code and using conditional operators
determine:
a. Whether the character entered through the keyboard is a lower-case alphabet or not.
b. Whether a character entered through the keyboard is a special symbol or not.
c. Write a program using conditional operators to determine whether a year entered through
the keyboard is a leap year or not.
***Good Luck***