Вы находитесь на странице: 1из 3

# Computer Programming

Assignment

## Due Date: 09 May 2016

1. Write a program that prints the numbers between 1and 25 along with their square roots in a
tabular form.
2. Define a function that takes two integer arguments, if second argument is greater than first the
function returns the sum of the arguments otherwise their product is returned.
3. Write a function integerPower (base, exponent) that returns the value of
base exponent
For example, integerPower( 3, 4 ) = 3 * 3 * 3 * 3. Assume that exponent is a positive, nonzero
integer and that base is an integer. The function integerPower should use for or while to control
the calculation. Do not use any math library functions.
4. Define a function calcTax that takes the value of a product as a double value. It then return the
sale value after adding tax to it @ 15%.
5. Write a function that displays at the left margin of the screen a solid square of asterisks whose
side is specified in integer parameter side. For example, if side is 4, the function displays the
following:
****
****
****
****
6. Modify the function created in Ex # 4 to form the square out of whatever character is contained
in character parameter fillCharacter. Thus, if side is 4 and fillCharacter is #, then this function
should print the following:
####
####
####
####
7.

An integer is said to be a perfect number if the sum of its factors, including 1 (but not the
number itself), is equal to the number. For example, 6 is a perfect number, because 6 = 1 + 2 +
3. Write a function perfect that determines whether parameter number is a perfect number.

8. One of the most popular games of chance is a dice game known as "craps" which is played in
casinos and back alley worldwide. The rules of the game are straight
forward:

A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5 and 6 spots.
After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If
the sum is 7 or 11 on the first roll, the player wins. If the sum is 2, 3 or 12 on the first roll
(called "craps"), the player loses (i.e., the "house" wins). If the sum is 4, 5, 6, 8, 9 or 10 on the
first roll, then that sum becomes the player's "point." To win, you must continue rolling the
dice until you "make your point." The player loses by rolling a 7 before making the point.
9. Write a function that takes an integer value and returns the number with its digits reversed. For
example, given the number 7631, the function should return 1367. Make sure that the number
entered is a 4 digit number. If not, re-prompt the user to enter it again.
10. Simulate the rolling of dice. Roll the dice 1000 times and draw the results in the
histogram as given below.
No.
1
2
3
4
5
6

form of a

Frequency
+++**************
++****************
+*************************
+***************
++********************
********************

## Where + represents 100 and * represents 1.

11. Write a program that declares an integer array of 10 elements. Initialize the array using an
initializer list. The program then prints the elements of the array in a tabular form.
12. Write a program that declares an integer array of size 10 and scans the values of array elements
from user. It then calculates the sum of all the elements of the array.
13. Write a program that declares a float array of size 10 and scans the values of array elements
from user. It then adds a value of 5.5 to even indexed elements and prints the array on screen.
14. Use an integer array to solve the following problem. Read in 10 numbers, each of which is
between 10 and 100, inclusive. As each number is read, validate it and store it in the array only
if it is not a duplicate of a number already read. After reading all the values, display only the
unique values that the user entered.
15. Write a program that declares an integer array of size 10. Initialize the array elements with
random numbers in the range 1-20 and graph the information as a histogram as shown:
Element Value Histogram
0
3
***
1
5
*****

2
3
...

8
11

********
***********

Note:
Plagiarism is strictly prohibited in this assignment; Copy of even a single question will
lead to rejection of whole assignment and will result in 0 marks.
This assignment should be sent via email, Email id is waqasdocument@gmail.com. Email
Subject should be Computer Programming Assignment 3 Reg# Otherwise your
assignment will not be considered for grading.