c++ وماادراك ما c++ ارجو المساعده ان امكن
Q1: What is the difference between the following two statements:
1. if (n > 2) { if (n < 6) cout << “OK”; } else cout << “NG”;
2. if (n > 2) { if (n < 6) cout << “OK”; else cout << “NG” };
------------------------
Q2: Use switch statement to rewrite the following code segment:
if (num == 1)
{cout << “Alpha”; }
else if (num == 2)
{ cout << “Beta”; }
else if (num == 3)
{ cout << “Gamma”; }
else
{ cout << “Other”; }
--------------------------
Q3: A palindrome is a number or a phrase that reads the same backwards as
forwards. 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 whether it is a palindrome.
-----------------------
Q4: Write a program that reads three nonzero integers and determines and prints
whether they could be the sides of a right triangle.
----------------------
Q5: Write and run a program –using nested if- that plays the game of "rock, paper,
scissors.”
The rules are:
1. Paper dominates (wraps) rock
2. Rock dominates (breaks) scissors
3. Scissors dominate (cut) paper
Hints:
• The program must clear the screen after the first player makes his/her choice; the
second player should not know his/her choice.
• The program must clear the screen after the second player makes his/her choice,
and then print the result.
•
Output samples:
Try 1:
* Welcome to "rock, paper, scissors.” Game *
st
1 Player
Please enter your first name: Abdullah
Choose rock (0), paper (1), or scissors (2):
Abdullah: 1
* Welcome to "rock, paper, scissors.” Game *
nd
2 Player
Please enter your first name: Ahmad
Choose rock (0), paper (1), or scissors (2):
Ahmad: 0
Abdullah chose paper
Ahmad chose rock
########## Abdullah WINS ##########
------------------------------------------
6-Write and run a program that print the following table:
Monthly Sales Income
--------------------------------------------------------------------------------------------------------------------
Greater than or equal to $50,000 $375 plus 16% of sales
Less than $50,000 but greater than or equal to $40,000 $350 plus 14% of sales
Less than $40,000 but greater than or equal to $30,000 $325 plus 12% of sales
Less than $30,000 but greater than or equal to $20,000 $300 plus 9% of sales
Less than $20,000 but greater than or equal to $10,000 $250 plus 5% of sales
Less than $10,000 $200 plus 3% of sales
Then calculates the monthly income of a computer salesperson using the following
commission schedule:
Monthly Sales Income
--------------------------------------------------------------------------------------------------------------------
Greater than or equal to $50,000 $375 plus 16% of sales
Less than $50,000 but greater than or equal to $40,000 $350 plus 14% of sales
Less than $40,000 but greater than or equal to $30,000 $325 plus 12% of sales
Less than $30,000 but greater than or equal to $20,000 $300 plus 9% of sales
Less than $20,000 but greater than or equal to $10,000 $250 plus 5% of sales
Less than $10,000 $200 plus 3% of sales
--------------------------------------------------------------------------------------------------------------------
Enter the value of monthly sales: 36243.89
The income is $4674.27
|