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

Source: Internet
Author: User

Course Homepage in http://blog.csdn.net/sxhelijian/article/details/39152703, the course 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, use the "human brain" run write output results, and then run the program on the computer or mobile phone, compare their own results, to reflect on.
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: ______________
Running 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: ______________
Running Result: ______________

On-Machine practice
"Item 1: piecewise function Evaluation" program, calculate the value of the following function and output (x to take the integer type)

Tip 1: When debugging, you should not only verify that one case is correct. For example, a representative input can be 8 (greater than 1, x=8, y should be 7), 0 (less than 1 o'clock, x=0, y should be 1), 1 (exactly equal to 1, x=0, y should be-1).
Tip 2: Each project requires post-debug post, check your blog post: (1) is there a comment? (2) Whether the code is done through the "Insert Code" function, the previous automatic line number, the color of the code 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  *: *   Completion Date: October 2014 x Day  * Version number: v1.0  *  * Problem Description: Calculate the value of the function: when X>=1, y=x-1, otherwise, y=-x +1 * Input Description: An integer x * program output: The corresponding y value */#include <iostream> Using namespace std; int main ()  {       //write down your code  }  
Operation Result:
Map

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

Learning experience:
(Here are some tips on how to do this and encourage yourself, and the passion for learning is what you write.) Who doesn't want to get into this passionate rhythm of their studies? )


"Item 2: Overtime, do you want it?" "Xiao He just work, according to the hours of work hour system to receive weekly wages, the wage standard is, hourly rate yuan RMB." 40 hours a week, if you have to work overtime, more than 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, the output of the salary of Xiao he this week.

"Item 3: Multi-segmented function evaluation" Enter the value of x from the keyboard (required to be real), and the value of Y is computed and output 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 the multi-branch structure and complete the solution.
Hint: The following two solutions for reference
Solution 1: Similar to the idea of 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 determines 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), T can represent how many conditions the X satisfies. 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, corresponding to the case of x<2; and the T-value is 0 o'clock, (x<2), (x<6), (x<10) Three relationship expressions must all be false, corresponding to x≥10, and 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 complete the program design;
(2) The following gives the basic framework of the program, due to the complexity of the rules, in order to facilitate the students to write a blog post with comments, in the cloud School sharing "the 8th week of Practice source code and blog post template," the blog template, please download the 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;//below to solve the payable personal and tax dtax and after-tax income dnetincomecout<<" You should pay 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 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.
Learn more about Calculator deduction, please find Baidu Encyclopedia.


"Item 5: Time Deposit Interest Calculator" Enter the deposit amount and select the type of deposit to 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 is 0.5 years).
For example: 1000 yuan Deposit 6 months, interest =1000x0.033x0.5=16.5 yuan
Interest rate use the annual interest rate published July 7, 2011: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 run diagram references the following interface:


"Item 6: How many days this month?" "Compile the program, enter the year and month, and output how many days this month." Select the branch statement to complete the design task.
Sample Input 1:2004 2
Output result 1:29 days this month
Sample Input 2:2010 4
Output result 2:30 days this month




=================== Helijian csdn Blog column =================|== It student Growth Guide Column column categories (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.