|
|
Date related Programs |
|
1 |
A Program in
C++ to return the day of the week given the date
|
|
|
|
|
2 |
A C++ Program [Source Code] that computes the nth
term of the fibonacci series and also print the series upto the nth term.
|
|
3 |
A C++ Program [Source Code] that reads a numbers,
then coumputes and displays the factorial of the given number
|
|
4 |
A C++ Program [Source Code] to solve the mystery of
Towers of Hanoi
|
|
5 |
(Selection Sort) A selection sort searches an array
looking for the smallest element in the array. Then, the smallest element is
swapped with the first element of the array. The process is repeated for the
subarray beginning with the second element of the array. Each pass of the array
results in one element being placed in its proper location. This sort performs
comparably to the bubble sort—for an array of n elements, n - 1 passes must be
made, and for each subarray, n - 1 comparisons must be made to find the
smallest value. When the subarray being processed contains one element, the
array is sorted. Write recursive function selectionSort to perform this
algorithm
|
|
6 |
(Palindromes) A palindrome is a string that is
spelled the same way forwards and backwards. Some examples of palindromes are
“radar,” “able was i ere i saw elba” and (if blanks are ignored) “a man a plan
a canal panama.” Write a recursive function testPalindrome that returns true if
the string stored in the array is a palindrome, and false otherwise. The
function should ignore spaces and punctuation in the string.
|
|
7 |
(Linear Search) A Program in C/C++ to use recursive
function linearSearch to perform a linear search of the array. The function
should receive an integer array and the size of the array as arguments. If the
search key is found, return the array subscript; otherwise, return –1.
|
|
8 |
(Binary Search) A C/C++ program to use a recursive
function binarySearch to perform the binary search of the array. The function
should receive an integer array and the starting subscript and ending subscript
as arguments. If the search key is found, return the array subscript;
otherwise, return –1.
|
|
9 |
(Print an array) Write a recursive function in C/
C++ printArray that takes an array and the size of the array
as arguments and returns nothing. The function should stop processing and
return when it receives an array of size zero.
|
|
10 |
(Print a string backwards) Write a in C/C++
recursive function stringReverse that takes a character array containing a
string as an argument, prints the string backwards and returns nothing. The
function should stop processing and return when the terminating null character
is encountered
|
|
11 |
(Find the minimum value in an array) Write a recursive function
recursiveMinimum that takes an integer array and the array size as arguments
and returns the smallest element of the array. The function should stop
processing and return when it receives an array of 1 element
|
|
|
Function |
|
1 |
A C++ Program [Source Code] to illustrate the use of
parameterless function
|
|
2 |
A C++ Program [Source Code] that find the largest
integer out of three integers provided and display the largest integer. [ using
functions with no return type ]
|
|
3 |
A C++ Program [Source Code] that find the largest
integer out of three integers provided and display the largest integer. [ using
functions with return type ]
|
|
4 |
A C++ Program [Source Code] to illustrate the use of
call-by-value method in functions
|
|
5 |
A C++ Program [Source Code] to illustrate the use of
call-by-refrence method in functions
|
|
6 |
A C++ Program [Source Code] to illustrate the use of
inline functions
|
|
7 |
A C++ Program [Source Code] to illustrate the use of
default argument function
|
|
8 |
A C++ Program [Source Code] to illustrate the use of
function overloading
|
|
9 |
A C++ Program [Source Code] that find the distance
between two points in 2D and 3D space using function overloading.
|
|
10 |
A C++ Program [Source Code] to interchange the
values of two int, float and char using function overloading.
|
|
11 |
A C++ Program [Source Code] to find the value of sin
at any given angle. [ using built-in function ]
|
|
12 |
A C++ Program [Source Code] that reads two positive
numbers n and r s.t. n>r, then coumputes and displays the value of nCr.
|
|
13 |
A C++ Program [Source Code] to illustrate the use of
some builtin functions of header file "math.h".
|
|
14 |
A C++ Program [Source Code] to illustrate the
difference between the use of strcomp, strcmpi and stricmp
|
|
15 |
A C++ Program [Source Code] that differentiate b/w
the variables of the storage class Auto and Static along with global variables
|
|
16 |
A C++ Program(source code) to covert a given
decimal number into Roman Code.
|
|
17 |
A C++ program(source code) to take power of first
paramater with second parameter (power function without built
in function)
|
|
18 |
A parking garage charges a $2.00 minimum fee to park
for up to three hours. The garage charges an additional $0.50 per hour for each
hour or part thereof in excess of three hours. The maximum charge for any given
24-hour period is $10.00. Assume that no car parks for longer than 24 hours at
a time. Write a program that will calculate and print the parking charges for
each of 3 customers who parked their cars in this garage yesterday. You should
enter the hours parked for each customer. Your program should print the results
in a neat tabular format and should calculate and print the total of
yesterday's receipts. The program should use the function calculateCharges to
determine the charge for each customer
|
|
19 |
An application of function floor is rounding a value
to the nearest integer. The statement y = floor( x + .5 ); will round the
number x to the nearest integer and assign the result to y. Write a program
that reads several numbers and uses the preceding statement to round each of
these numbers to the nearest integer. For each number processed, print both the
original number and the rounded number.
|
|
19 |
Function floor can be used to round a number to a
specific decimal place. The statement y = floor( x * 10 + .5 ) / 10; rounds x
to the tenths position (the first position to the right of the decimal point).
The statement y = floor( x * 100 + .5 ) / 100; rounds x to the hundredths
position (the second position to the right of the decimal point). Write a
program that defines four functions to round a number x in various ways:
a) roundToInteger( number )
b) roundToTenths( number )
c) roundToHundredths( number )
d) roundToThousandths( number )
For each value read, your program should print the original value, the
number rounded to the nearest integer, the number rounded to the nearest tenth,
the number rounded to the nearest hundredth and the number rounded to the
nearest thousandth.
|
|
20 |
Write a function integerPower( base, exponent ) that
returns the value of base exponent
|
|
21 |
Define a function hypotenuse
that calculates the length of the hypotenuse of a right triangle when the other
two sides are given. Use this function in a program to determine the length of
the hypotenuse for each of the following triangles. The function should take
two arguments of type double and return the hypotenuse as a double.
|
|
22 |
Write a function multiple that
determines for a pair of integers whether the second integer is a multiple of
the first. The function should take two integer arguments and return true if
the second is a multiple of the first, false otherwise. Use this function in a
program that inputs a series of pairs of integers.
|
|
23 |
Write a program in c/c++
that inputs a series of integers and passes them one at a time to
function even, which uses the modulus operator to determine whether an integer
is even. The function should take an integer argument and return true if the
integer is even and false otherwise.
|
|
24 |
An integer is said to be prime
if it is divisible by only 1 and itself. For example, 2, 3, 5 and 7 are prime,
but 4, 6, 8 and 9 are not.
|
|
25 |
b) Use this function in a
program that determines and prints all the prime numbers between 1 and 10,000.
How many of these 10,000 numbers do you really have to test before being sure
that you have found all the primes?
|
|
26 |
Write a function that takes the
time as three integer arguments (for hours, minutes and seconds), and returns
the number of seconds since the last time the clock “struck 12.” Use this
function to calculate the amount of time in seconds between two times, both of
which are within one 12-hour cycle of the clock.
|
|
27 |
An integer number 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. Use this function in a program that determines and prints
all the perfect numbers between 1 and 1000. Print the factors of each perfect
number to confirm that the number is indeed perfect. Challenge the power of
your computer by testing numbers much larger than 1000.
|
|
28 |
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
|
|
29 |
The greatest common divisor
(GCD) of two integers is the largest integer that evenly divides each of the
numbers. Write a function gcd that returns the greatest common divisor of two
integers
|
|
30 |
Write a function qualityPoints
that inputs a student’s average and returns 4 if a student's average is 90–100,
3 if the average is 80–89, 2 if the average is 70–79, 1 if the average is 60–69
and 0 if the average is lower than 60.
|
|
31 |
Write a program that simulates
coin tossing. For each toss of the coin, the program should print Heads or
Tails. Let the program toss the coin 100 times and count the number of times
each side of the coin appears. Print the results. The program should call a
separate function flip that takes no arguments and returns 0 for tails and 1
for heads. Note: If the program realistically simulates the coin tossing, then
each side of the coin should appear approximately half the time.
|
|
32 |
Computers are playing an
increasing role in education. Write a program that will help an elementary
school student learn multiplication. Use rand to produce two positive one-digit
integers. It should then type a question such as:
How much is 6 times 7?
The student then types the answer. Your program checks the student's answer. If
it is correct, print "Very good!", and then ask another multiplication
question. If the answer is wrong, print "No. Please try again." and then let
the student try the same question again repeatedly until the student finally
gets it right.
|
|
33 |
The use of computers in
education is referred to as computer-assisted instruction (CAI). One problem
that develops in CAI environments is student fatigue. This can be eliminated by
varying the computer's dialogue to hold the student's attention. Modify the
program of above program so the various comments are printed for each
correct answer and each incorrect answer as follows: Responses to a correct
answer
Very good!
Excellent!
Nice work!
Keep up the good work!
Responses to an incorrect answer
No. Please try again. Wrong.
Try once more.
Don't give up! No.
Keep trying.
Use the random number generator to choose a number from 1 to 4 to select an
appropriate response to each answer. Use a switch structure to issue the
responses.
|
|
34 |
More sophisticated
computer-aided instruction systems monitor the student’s performance over a
period of time. The decision to begin a new topic is often based on the
student’s success with previous topics. Modify the above program to count
the number of correct and incorrect responses typed by the student. After the
student types 10 answers, your program should calculate the percentage of
correct responses. If the percentage is lower than 75 percent, your program
should print "Please ask your instructor for extra help" and then terminate.
|
|
35 |
Write a program that plays the game of “guess the
number” as follows: Your program chooses the number to be guessed by selecting
an integer at random in the range 1 to 1000. The program then types:
I have a number between 1 and 1000.
Can you guess my number?
Please type your first guess.
The player then types a first guess. The program responds with one of
the following:
1. Excellent! You guessed the number! Would you like to play again (y or n)?
2. Too low. Try again.
3. Too high. Try again.
If the player's guess is incorrect, your program should loop until the player
finally gets the number right. Your program should keep telling the player Too
high or Too low to help the player “zero in” on the correct answer.
|
|
36 |
Modify the above program to
count the number of guesses the player makes. If the number is 10 or fewer,
print Either you know the secret or you got lucky! If the player guesses the
number in 10 tries, then print Ahah! You know the secret! If the player makes
more than 10 guesses, then print You should be able to do better! Why should it
take no more than 10 guesses? Well, with each “good guess” the player should be
able to eliminate half of the numbers. Now show why any number from 1 to 1000
can be guessed in 10 or fewer tries.
|
|
37 |
Write a recursive function power(
base, exponent ) that, when invoked, returns base exponent For
example, power( 3, 4 ) = 3 * 3 * 3 * 3. Assume that exponent is an integer
greater than or equal to 1. Hint: The recursion step would use the relationship
base exponent = base · base exponent - 1 and the terminating condition occurs
when exponent is equal to 1 because base1 = base
|
|
38 |
The Fibonacci series 0, 1, 1,
2, 3, 5, 8, 13, 21, … begins with the terms 0 and 1 and has the property that
each succeeding term is the sum of the two preceding terms.
a) Write a nonrecursive function fibonacci( n ) that calculates the nth
Fibonacci number.
b) Determine the largest Fibonacci number that can be printed on your system.
Modify the program of part a) to use double instead of int to calculate and
return Fibonacci numbers, and use this modified program to repeat part b).
|
|
|
|
|
|
|