京东金立手机专卖店:about C++

来源:百度文库 编辑:高校问答 时间:2024/04/29 00:58:08
write an simple programme about C++

5. Draw a flowchart based on the following psuedocode:

Begin
Initialize Count to 0
DoWhile Count is less than 10
Input Rate and Time
If Rate is greater than or equal to 60
Distance is equal to Rate * Time
Output the Rate, Time, and Distance
EndIf
Add 1 to Count
End Do
End

6. Based on the flowchart in the previous question, the program design is not good at all. For instance, if the user inputs negative values of Time, the program will display negative distance, which is not logical at all. Try to improve the design so that:
• the program will display appropriate error messages on screen when the user inputs wrong values of Rate and/or Time.
• the program will ask the user to continue calculating distance or not after each output is displayed on screen instead of calculating distance for exactly 10 times.

Write a C program (with comments) based on your improved design and use several sets of test data to test your solution. Print out the source program, the test data and the corresponding output.

void dis5()
{
int count=0;//init count;
float rate, time; //define speed, time (s)

while(count<=10)
{
printf("Input the rate and time\n");
scanf("%f%f",&rate,&time);
printf("Rate:%f,time:%f,distance:%f",rate,time,rate*time)
}
}

void dis6()
{
int count=0;//init count;
float rate, time; //define speed, time (s)

while(count<=10)
{
printf("Input the rate and time\n");
scanf("%f%f",&rate,&time);
if(rate<=0||time<0)
printf("Wrong data");
break;
printf("Rate:%f,time:%f",rate,time)
printf("Do you wanna to print the distance?")
char ch=getchar();
if(ch=='y'||ch=='Y')
printf(",%f",rate*time)
}
}

All rights reserved.(c)版权所有,严禁拷贝!