Uploaded by Ali Akbar Changezi

Assignment 3(Due December 4)

advertisement
Assignment Problems
1. Multiplication Table: Write a C++ program to print multiplication table of
any number.
Enter a number: 5
2. Palindrome: Palindrome number is such number which when reversed is
equal to the original number. For example: 121, 12321, 1001 etc. Write a
C++ program to check whether a number is palindrome or not.
3. Sum a Sequence of Integers: Write a program that sums a sequence of
integers. Assume that the first integer read with cin specifies the number of
values remaining to be entered. Your program should read only one value
each time cin is executed. A typical input sequence might be
5 100 200 300 400 500
where the 5 indicates that the subsequent five values are to be summed.
4. Calculating Weekly Pay: A company pays its employees as managers (who
receive a fixed weekly salary), hourly workers (who receive a fixed hourly
wage for up to the first 40 hours they work and “time-and-a-half”—i.e., 1.5
times their hourly wage—for overtime hours worked), commission workers
(who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers
(who receive a fixed amount of money for each of the items they produce—
each pieceworker in this company works on only one type of item). Write a
program to compute the weekly pay for each employee. You do not know
the number of employees in advance. Each type of employee has its own pay
code: Managers have paycode 1, hourly workers have code 2, commission
workers have code 3 and pieceworkers have code 4. Use a switch to
compute each employee’s pay based on that employee’s paycode. Within the
switch, prompt the user (i.e., the payroll clerk) to enter the appropriate facts
your program needs to calculate each employee’s pay based on that
employee’s paycode.
5. Computing the Derivative: A derivative of a function f(x) is given by
f  x  x   f  x 
 x 0
x
4
f ( x)  3x  4x3  9x2  8x  7
lim
Let f(x) be
Find the derivative of f(x) for x=5 for different values of  x decreasing up to
0. Your program should properly handle the division by zero.
6. Swapping two Numbers: Write a C++ program that swaps two numbers.
Your output may look like as follows:
Enter the value of numb1: 9
Enter the value of numb2: 5
Before Swapping:
Your entered value for numb1 = 9
Your entered value for numb2 = 5
After Swapping:
Value for numb1 = 5
Value for numb2 = 9
7. Area of Triangle using Heron’s formula: Write a C++ program that takes
finds the area of a triangle when three sides are given using Heron’s
formula.
Your program should ask repeatedly if the user wants to proceed further.
The program should be terminated when the user presses ‘n’ or ‘N’.
8. ASCII-Codes: All characters like small letters, capital letters, digits or
special character have ASCII codes when a key is pressed from keyboard
there is always an ASCII value behind it like if small letter 'a' is pressed its
ASCII is 97 if capital letter 'A' is pressed its ASCII value is 65 if a number
digit '0' is pressed its ASCII value is 48.
ASCII Value Ranges
For Digits 0-9
48-57
For Capital Letters A-Z 65-90
For Small Letters a-z
97-122
Special Characters
0-47, 58-64, 91-96, 123-127
On the basis of ASCII values and using operators like and operator (&&) or
Operator (||) we can differentiate the letters. Write a C++ program to check
whether the entered character is capital letter, small letter, digit or a special
character. Your program should ask the user if he wants to continue or not.
Your output may look like as follows:
Enter a character: A
The ASCII value of A is 65
You have entered a capital letter.
Do you want to continue? Y/N
9. Triangle-Printing Program: Write a program that prints the following
patterns separately. Use for loops to generate the patterns. All asterisks (*)
should be printed by a single cout statement. [Hint: The last two patterns
require that each line begin with an appropriate number of blanks.]
10.Diamond-Printing Program: Write a program that prints the following
diamond shape.
11.Computing Product: Write a C++ program using while loop that computes
the product of two numbers WITHOUT using the * operator.
12. Reverse of a Number: Write a C++ program to input a number from user
and find reverse of the given number. Your output may look like as follows
13.Describe the output produced by these while loops:
int K = 5;
int number = 4;
int I = -2;
while (number >= 0)
while (I <= K)
--number;
{
cout << number << endl;
I = I + 2;
--K;
cout << (I + K) << endl;
}
Download