Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Introduction to Computing

Assignment 7
Conditional statement IFELSE

Session: FALL 2012

Faculty of Information Technology UCP Lahore Pakistan

Objectives
1. Learn IF-ELSE conditional statement. 2. Learn to evaluate logical expressions. 3. To be able to write programs using logical and relational operators

Instructions:
Write programs for all the problem statements provided below. Your source code should be well commented. Your source code and output screen should be like as shown below:

Example Solution:
# include<iostream.h> void main() { cout<<"Hello World"<<endl; } Output Screen:

Problem 1:
Write C++ programs for the following problems. You can use logical operators where needed. 1. Find absolute value of difference of two numbers 2. Find smaller/larger of two numbers 3. Find whether a numbers is negative or not 4. Find whether two numbers are equal or not 5. Multiply two numbers if their difference is greater than 0 6. Find whether the sum of two numbers is greater than 50 7. Find whether the sum of two numbers is greater than the third number 8. Divide a number by another if and only if the second number is not equal to 0 9. Divide two numbers if their difference is greater than 10, otherwise multiply them. 10. Determine whether the average of two numbers is negative or not. 11. Multiply two numbers if their sum is greater than 100, otherwise divide them. 12. Determine whether the Product of two numbers is negative or not. 13. Subtract two numbers if their sum is greater than 100, otherwise divide them. 14. Determine whether the average of three numbers is negative or not. 15. Find sum of two numbers (If second number is equal to 0 add 5 to it) 16. Determine whether the average of three numbers is negative or not. 17. Find sum of two numbers (If second number is equal to 0 add 5 to it) 18. Divide a number by another if second number is between 0 and 10 19. Add two numbers if either of them is 0 20. Determine status of a student from marks of two of his subjects for following: a. If marks for both the subjects are greater than 40, hes passed b. If marks for either of the subjects are greater than 40, hes passed

Problem 2:
(Salary Calculator)Write a program that will determine the gross pay for an employee. The company pays straight time for the first 40 hours worked by each employee and pays timeand-a-half for all hours worked in excess of 40 hours. Youre being provided, the number of hours employee worked last week and the hourly rate of employee. Your application should input this information for employee, and should deter-mine and display the employee's gross pay.

Problem 3:
(Palindrome Tester) A palindrome is a number or a text phrase that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321,55555, 45554 and 11611. Write a program that reads in a five-digit integer and determines whetheror not its a palindrome. *Hint: Use the division and remainder operators to separate the number into its individual digits.]

Problem 4:
(Printing the Decimal Equivalent of a Binary Number) Input an integer containing only 0s and 1s (i.e., a binary integer) and print its decimal equivalent. *Hint: Use the remainder and division operators to pick off the binary numbers digits one at a time from right to left. Just as in the decimal number system, in which the rightmost digit has a positional value of 1, and the nextdigit left has a positional value of 10, then 100, then 1000, and so on, in the binary number system the rightmost digit has a positional value of 1, the next digit left has a positional value of 2, then 4, then 8, and so on. Thus the decimal number 234 can be interpreted as 4 * 1 + 3 * 10 + 2 * 100. The decimal equivalent of binary 1101 is 1 * 1 + 0 * 2 + 1 * 4 + 1 * 8 or 1 + 0 + 4 + 8 or 13.

Problem 5:
Given the length and breadth of a rectangle, write a program tofind whether the area of the rectangle is greater than itsperimeter. For example, the area of the rectangle with length = 5 and breadth = 4 is greater than its perimeter.

Problem6:
(Salary Calculator) Develop a program that will determine the gross pay for each of several employees. The company pays straight time for the first 40 hours worked by each employee and pays time-and-a-half for all hours worked in excess of 40 hours. Youre given a list of the employees of the company, the number of hours each employee worked last week and the hourly rate of each employee. Your program should input this information for each employee, and should determine and display the employee's gross pay.

Problem 7:
(Sides of a Triangle) Write a program that reads three nonzero float values and determines and prints if they could represent the sides of a triangle.

Problem 8:
(Sides of a Right Triangle) Write a program that reads three nonzero integers and determines and prints if they could be the sides of a right triangle.

Problem 9:
The current year and the year in which theemployee joined the organization are entered through thekeyboard. If the number of years for which the employee hasserved the organization is greater than 3 then a bonus of Rs. 2500/-is given to the employee. If the years of service are not greaterthan 3, then the program should do nothing.

Problem 10:
In a company an employee is paid as under:If his basic salary is less than Rs. 1500, then HRA = 10% of basicsalary and DA = 90% of basic salary. If his salary is either equal to or above Rs.1500, then HRA = Rs. 500 and DA = 98% of basicsalary. If the employee's salary is input through the keyboard writea program to find his gross salary.

Problem 11:
Draw a flowchart which reads in two values from the user Manufacturing cost of product Selling price of product.

And determines and prints whether a profit or a loss is made. If profit is greater than 10% calculate and Display a Bonus of 1% from profit to the employee. Expected Output: Enter Manufacturing cost of product: 700 Enter selling price of product: 1100 Profit = 400 36% Profit is made from this product. Bonus = 4

You might also like