2014 Autumn C + + 8th Week Project Branching program design

Source: Internet
Author: User

The course homepage is in http://blog.csdn.net/sxhelijian/article/details/39152703. Curriculum Resources in the Cloud Academy "teacher class" synchronized display, the use of the account number, please go to the course homepage to view.


Read and verify

Read the following two procedures to write out the output using the human brain. Then execute the program on the computer or mobile phone to reflect on the results you have written.
1.
#include <iostream>
using namespace Std;
int main ()
{
int a=1,b=2,c=3;
if (a<=c)
if (b==c)
cout<< "A=" <<a<<endl;
Else
cout<< "b=" <<b<<endl;
cout<< "c=" <<c<<endl;
return 0;
}
Your expectations: ______________
Execution Result: ______________
2.
#include <iostream>
using namespace Std;
int main ()
{
int i=10,j,m=0,n=0;
j=i%3;
Switch (j)
{
Case 0:m++;break;
Case 1:
Case 2:n++; Break
default:cout<< "i=" <<i<<endl;
}
cout<< "m=" <<m<< ", n=" <<n<<endl;
return 0;
}
Your expectations: ______________
Execution Result: ______________

On-Machine practice
"Item 1: piecewise function Evaluation" program. Calculates the value of the following function and outputs it (X takes an integral type)

Tip 1: When debugging, you should not just verify that one case is correct. Like what. A representative input can be 8 (more than 1 cases.) X=8, y should be 7), 0 (less than 1 o'clock, x=0. Y should be 1), 1 (exactly equal to 1 case, x=0, y should be-1).


Tip 2: Each project requires post-debug post, check your blog post: (1) Do you have a gaze? (2) Whether the code is done through the "Insert Code" function. Before have their own active line number, the color of the code is rich--very professional look? (3) Did you write a summary of knowledge points and learning experience? The following template. Can be saved in your convenient access to the media (USB stick or mailbox), convenient for later work.
Title: Week 8th Item 1-Finding the value of a simple piecewise function

Question and code:  /* Copyright (c) 2014, Yantai University School of Computer  * All rights reserved.  * File name: Test.cpp *: *   Completed Date: October 2014 x Day  * Version number: v1.0  *  * Description of the problem: calculate the value of the function: when X>=1, y=x-1, otherwise, y=- X+1 * Input Descriptive narrative: an integer x * program output: The corresponding y value */#include <iostream> Using namespace std; int main ()  {       //write down your code  }  
Execution Result:
Map

Summary of Knowledge points:
(Write out the knowledge learned in this program)

Learning experience:
(Here are some tips for doing this program, and inspiring yourself.) The passion for learning is how you write it. Who does not want to let their study into such a passionate rhythm? )


"Item 2: Overtime. Do you want? "Xiao He just work, according to the hours of work hour system to receive weekly wages, the wage standard is, hourly rate yuan RMB."

Work 40 hours a week, assuming you are working overtime. The excess is 1.5 times times the normal salary (the Boss is good!)

)。 This week Xiao he worked for hour hours. Please compile the program. Enter rate and hour. Output this week's salary.

"Item 3: Multi-segmented function evaluation" Enter the value of x from the keyboard (required to be a real type). Calculates and outputs the value of Y according to the following formula.

(1) Use the nesting of if~else~ statements to realize this multi-branch program;
(2) Use the switch statement to construct a multi-branch structure, complete the solution.
Hint: The following two methods for reference
Solution 1: The idea of similar example 3.9, each segment of the standard is a multiple of 2, so, the structure of the expression t= X/2, according to the value of T to determine the switch branch;
Solution 2: Constructs an expression t= (x<2) + (x<6) + (X&LT;10). Because the value of the relational expression (X<a) is 0 or 1 (true 1.) False is 0). So t can say that x exactly satisfies a few conditions. For example, when the input x is 1 o'clock, (x<2), (x<6), (x<10) are true, the logical value is added, True when 1, false is 0, so there is t= (x<2) + (x<6) + (X&LT;10) = 3, the corresponding x<2 case. Again, and the T value is 0 o'clock. (X&LT;2), (x<6), (x<10) Three relationship expressions must all be false. Corresponding x≥10. Other similar. Depending on the value of T, the switch branch can be determined.


"Item 4: Personal income Tax Calculator" Write a selection structure procedure, enter the total monthly income of the individual, calculate his tax payable this month and after-tax income (the calculation method is attached: Relevant background knowledge of personal income tax).
(1) the nested or/and switch statements of the optional if statement are programmed to complete.
(2) The following gives the basic framework of the program, due to the complexity of the rules, in order to facilitate students to write a blog with gaze, in the Cloud school shared "8th weeks of Practice source code and blog template. txt" in the blog template. Please download and use.
#include <iostream>   using namespace Std;int main () {double dsalary,dtax=0,dnetincome=0; cout<< " Please enter your total revenue for this month (yuan): "; cin>>dsalary;//the following solution should be paid to the individual and tax dtax and after-tax income dnetincomecout<<" You should pay the personal tax this month "<<dTax< < "Yuan, after-tax income is" <<dNetIncome<< "Yuan.

\;cout<< "Pay taxes according to law and share prosperity."

Thanks for using! \ n "; return 0;}

Attached: Relevant background knowledge of personal income tax
Method of calculation: personal income tax = (total income-3500) * Tax Rate-Calculator deduction
From September 1, 2011 onwards, China's personal income tax threshold base of 3500 yuan, out of the partial according to the following 7 level calculation.


Serial numberIncome RangeRateCalculator Deduction Number
1Over 0 to 15003%0
2More than $1500 to $450010%105
3More than $4500 to $900020%555
4More than $9,000 to $35,00025%1005
5More than $35,000 to $55,00030%2755
6More than $55,000 to $80,00035%5505
7More than 80,00045%13505
For example: Wang a month total income of 3600 yuan, personal income tax = (3600-3500) *3%=3 yuan;
Another example: Lee a month income of 13500 yuan, personal income tax = (13500-3500) *25%-1005=2500-1005=1495 yuan.
Many other understand calculator deduction number, please find Baidu Encyclopedia.


"Item 5: Time Deposit Interest Calculator" Enter the deposit amount and select the type of deposit. Calculate the interest (excluding interest tax) and the sum of principal and interests. A switch statement is required to determine the interest rate and post-deposit calculation based on the type of deposit selected.
Note: interest = amount X Annual interest rate x deposit period (unit: Year, 3 months is 0.25 years. 6 months for 0.5 years).
For example: 1000 yuan Deposit 6 months, interest =1000x0.033x0.5=16.5 yuan
Interest rate used July 7, 2011 Annual Interest Rate: 3 months 3.1%. 6 months 3.3%, one year 3.5%, two years 4.4%. Three years 5%, five years 5.5%.


The program implementation diagram references the following interface:


"Item 6: How many days this month?" "To compile the program. Enter the year and month. How many days is the output this month.

Select the branch statement to complete the design task.


Example Input 1:2004 2
Output result 1:29 days this month
Example Input 2:2010 4
Output result 2:30 days this month




=================== Helijian csdn Blog column =================|== It student Growth Guide Column column category folder (not regularly updated) ==| | = = C + + Classroom Online Column The course teaching link (sub-course grade) ==| | = = I wrote the book-"The reverse of the university-to the positive energy of IT students" ==|===== for it rookie runway, and students enjoy a happy and passionate university =====





2014 Autumn C + + 8th Week Project Branching program design

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.