tutorial#4

7
CSC103 # 2 2012 – 2013 University of Bahrain College of Information Technology Department of Computer Science CSC 103 Tutorial#4 1. The 1988 United States Federal Tax Schedule was the simplest in recent times. It had four categories, and each category has two rates. Here is a summary; dollar amounts are taxable income. Category Tax Single 15% of first $17,850 plus 28% of excess Head of Household 15% of first $23,900 plus 28% of excess Married, Joint 15% of first $29,750 plus 28% of excess Married, Separate 15% of first $14,875 plus 28% of excess For example, a single wage earner with a taxable income of $20,000 dollars owes 0.15 x $17,850 + 0.28 x ($20,000 - $17,850). Write a program that lets the user enter the tax category and the taxable income then calculates and prints the tax . Sample input/output Enter the category : S Enter taxable income : 20000 Tax = 3279. 2. Write C++ program to calculate and output the net price of a pizza based on two user inputs: size (S for small, M for medium ,or L for large) and number of toppings. The net price of pizza is the sum of the follows: Base price of the pizza is $8.50 for small, $10.50 for medium, and $12.50 for large. The first topping is free; the second and subsequent topping is an addition $0.50 for each. Sales tax is an additional 7% of the total price. Course Coordinator :Aysha Bin Dayna

Upload: ayesha-khan

Post on 11-Apr-2015

17 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Tutorial#4

CSC103 # 2 2012 – 2013

University of BahrainCollege of Information TechnologyDepartment of Computer Science

CSC 103

Tutorial#4

1. The 1988 United States Federal Tax Schedule was the simplest in recent times. It had four categories, and each category has two rates. Here is a summary; dollar amounts are taxable income.

Category Tax

Single15% of first $17,850 plus 28% of excess

Head of Household15% of first $23,900 plus 28% of excess

Married, Joint15% of first $29,750 plus 28% of excess

Married, Separate15% of first $14,875 plus 28% of excess

For example, a single wage earner with a taxable income of $20,000 dollars owes 0.15 x $17,850 + 0.28 x ($20,000 - $17,850). Write a program that lets the user enter the tax category and the taxable income then calculates and prints the tax .

Sample input/output Enter the category : S

Enter taxable income : 20000 Tax = 3279.

2. Write C++ program to calculate and output the net price of a pizza based on two user inputs: size (S for small, M for medium ,or L for large) and number of toppings. The net price of pizza is the sum of the follows:

Base price of the pizza is $8.50 for small, $10.50 for medium, and $12.50 for large.

The first topping is free; the second and subsequent topping is an addition $0.50 for each.

Sales tax is an additional 7% of the total price.

3. Write a C++ program that accepts the salary of the employee, then deducts the income tax from the salary on the following basis :

30% income tax if the salary is above or equal $15000.20% income tax if the salary is between $7000 and $15000.10% income tax if the salary is below or equal $7000.

Your program then should output the salary, income tax and the net salary.

Course Coordinator :Aysha Bin Dayna

Page 2: Tutorial#4

CSC103 # 2 2012 – 2013

4. Write a C++ program that asks the user to enter ID number and GPA of 50 students. The program should output into a new file RESULT.DAT the ID, the GPA with 2 decimal places and the result (either PASS or FAIL) separated by space, each student record in a new line. The result is PASS if GPA is greater than or equal to 2.0, FAIL otherwise.

i.e if the first two input is 20071122 1.8 and 20072233 3.7 then the first two lines in the file should be

20071122 1.8 FAIL20072233 3.7 PASS

5. ABC department store offers a prize if the person’s purchases exceed 150 dinars. The prize will be given based on age range. Draw a flowchart that read a purchase and age. The program should display the corresponding prize based on age range according to the table below.

Age Prize receivedBetween 14 and 25 Cell phoneBetween 26 and 40 Voucher with 40 BDBetween 41 and 55 Coffee machine

55 and above Microwave machine

6. Write a C++ program that calculates and displays the ideal weight based on the user’s age and height. The formula is as follows.

Note that the weight given by the formula is in kilograms.

AGE GROUP IDEAL WEIGHT FORMULApersons up to and including age 18 (height - 36 / )2persons between age 19 years and 55 inclusive ((height - 36 / )2(( + )age - 18 / )7)persons between 56 years and 75 inclusive ((height - 36 / )2(( + )37 / 7(( - )age - 55 / )4))persons over the age of 76 years same as for those of 18 years or younger

Sample Input/Output

Enter your height and age: 175 35Ideal weight for that person = 71.9286

Course Coordinator :Aysha Bin Dayna

Page 3: Tutorial#4

CSC103 # 2 2012 – 2013

7. What is the output of the following code?

int a, b;a = 5;b = 3;switch ( a + b ) {case 1: case 2:cout<<"Option 1";break;case 3:cout<<"Option 2";break;default:cout<<"Option 3\n;"

} cout<<"Option 2;"

8. What is the output of the following code?

int x, y;x = 3;y = x + 5;if ( ( x == y ) || ( y < x ) ){ cout<<"Expression is true\n;"

}else{ cout<< "Expression is false\n}; "

9. Suppose that the input is 0. What is output of the following code?

cin >> angle;if (angle > 5)

angle = angle + 5;else if (angle > 2)

angle = angle + 10; cout << angle;

10. What is the output of the following C++ code?

int y = 5, x = 55;switch (x % 7){case 0:

case 1: y;++case 2:case 3: y = y + 2;

break;case 5:case 6: y = y – 3;}cout << y << endl;

Course Coordinator :Aysha Bin Dayna

Page 4: Tutorial#4

CSC103 # 2 2012 – 2013

11. What is the output of the following code fragment if the input value is 20?

cin >> someInt;if (someInt > 30)

cout << "Mo;" cout << "Larry;"

cout << "Curly;"

12. What would the value of Enter be after execution of this code if the value input for Enter was 4?

int Enter; cin >> Enter;switch (Enter) {case 1: Enter = -4;case 2: Enter = -6;case 4: break;case 6: Enter = -8;

break;default: Enter = -1;}

Course Coordinator :Aysha Bin Dayna

Page 5: Tutorial#4

CSC103 # 2 2012 – 2013

Course Coordinator :Aysha Bin Dayna