Assignment_2_Programming_Fundamentals
Assignment_2_Programming_Fundamentals
( Programming Fundamentals )
Important Instructions:
1. You have to submit the solution of all questions separately. Submit on the
Microsoft teams. Submission format should be Q1_Name_RollNo.cpp and
Q2_Name_RollNo.cpp etc . Do not zip your files.
2. You are not allowed to copy solutions. We will check your code for plagiarism using
plagiarism checkers. If any sort of cheating is found, zero marks would be given.
Part a) Write the algorithm of a program that calculates a car’s gas mileage. The program
should ask the user to enter the number of gallons of gas the car can hold, and the number of
miles it can be driven on a full tank. It should then display the number of miles that may be
driven per gallon of gas.
Part b) A software company sells a package that retails for $99. Quantity discounts are given
according to the following table.
Quantity Discount
10 - - - -19 20%
20 - - - - 49 30%
50 - - - - 99 40%
Write the algorithm of a program that asks for the number of units sold and computes the total
cost of the purchase.
Have you ever heard of Rock Scissors and Paper? Alright, let’s develop that game in C++ using
if and else only. In this game, two players simultaneously say (or display a hand symbol
Representing) either “rock,” “paper,” or “scissors.” The winner is the one whose choice
dominates the other.
○ You will take two numbers as input and return who is the winner.
This is Draw.
Player 1 wins
TASK 3:
When we draw money from an ATM machine it asks us to specify the total amount that we wish
to withdraw. The machine (actually the program running on a computer) then decides the
number of currency notes of each denomination that (i.e. Rs. 500, Rs. 1000, Rs 5000) that must
be given to the user in order to fulfill his request.
In this problem, you will write a program that will ask the user to enter the total amount the user
wants to withdraw and then display the number of currency notes of each denomination that will
be given to the user. Please remember that following rules must be followed while making the
decision about the number of currency notes of each denomination.
Rule No 1. There must be enough money available in his/her account. Assume that the user
also enters this value.
Rule No 2. The user must be given at least one note of Rs. 500.
Rule No 3. The machine must give a minimum number of currency notes to the user.
Rule No 4. Total amount specified by the user must be less than his maximum daily withdrawal
limit. Assume that this daily limit will be provided/specified by the user.
Rule No 5. Total amount specified by the user must be a multiple of Rs. 500
TASK 4:
While filling a check for NBP (National Bank of Pakistan) a user need to write the amount to be
withdrawn in English/Urdu. For example, to withdraw an amount of Rs. 100,000 the user must
write One Hundred Thousands only and to withdraw an amount of Rs. 75 the user must write
Seventy Five Only. This program will assist a relatively less illustrated person (i.e. a person who
can write the Basic English alphabets) write the amount correctly. The user of this program will
enter an amount in digits and the program will display the same amount written in correct format
(i.e. amount followed by the word ONLY) using the English language. For the time being you
can assume that the amount specified is always between Rs. 1 and Rs. 100. So your program
should work correctly for all numbers between 1
and 100 inclusive.
TASK 5:
You have several pictures of different sizes that you would like to frame. A local picture-framing
store offers two types of frames—regular and fancy. The frames are available in white and can
be ordered in any color the customer desires. Suppose that each frame is 1 inch wide. The cost
of coloring the frame is $0.10 per inch. The cost of a regular frame is $0.15 per inch, and the
cost of a fancy frame is $0.25 per inch. The cost of putting cardboard paper behind the picture is
$0.02 per square inch,
and the cost of putting glass on top of the picture is $0.07 per square inch. The customer can
also choose to put crowns on the corners, which costs $0.35 per crown.
Write a program that prompts the user to input the following information and then output the cost
of framing the picture:
d. If the user wants to put the crowns, then the number of crowns
TASK 6:
Write a C++ program which declares an array of size N, and asks the user to fill the array with
numbers. Your programs will then do two things:
1. First, your program will replace the duplicate elements from the array. For example, let’s
say the size of the array is 10, and the numbers user entered are 6, 8, 3, 5, 5, 0, 3, 9, 8, 3. Now
after removing the duplicate numbers, the array will become 6, 8, 3, 5, -1, 0, -1, 9, -1, -1. All
duplicate elements are replaced with -1. (Assume that the user never gives -1 as input for the
array)
2. In the second part, your program will shift all -1s toward the end of the array. i.e 6, 8, 3, 5, 0,
9, -1, -1, -1, -1.
TASK 7:
Write a C++ program that has an integer array of size N. The array contains N integers. You can
hardcode the elements of the array. Now the program will ask the user to enter an integer
number. Your program will tell whether the number given by the user is the summation of any
three numbers in the array. Also print the three numbers whose sum is equal to the given
number.
For example, if the array is: 9, 4, 54, 23, 54, -23 0, 54, 5, 8 and the number entered by the user
is 86, then your program will print 9, 54 and 23.
It is possible to have more than one triplet whose summation equals the given number. In this
case,
print all triplets. Such as, if the user enters 85, then the program will print:
a. 54, 23, and 8
b. 54, 54, and -23