Question

C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you...

C PROGRAMMING

Introduction

In this part, you will solve a problem described in English. Although you may discuss ideas with your classmates, etc., everyone must write and submit their own version of the program. Do NOT use anyone else’s code, as this will result in a zero for you and the other person!

Shipping Calculator

Speedy Shipping Company will ship your package based on the weight and how far you are sending the package, which can be anywhere in the universe. They will only ship small packages up to 10 pounds. You need to have a program, which will help you determine how much they will charge.

The charges are based on each 500 miles shipped. The mileage should be in whole numbers. They are not prorated, i.e., 600 miles is the same charge as 900 miles; in other words, 600 and 900 miles is counted as 2 segments of 500 miles each.

Here is the table they gave you:

Package Weight Rate per 500 miles shipped

Charge

2 pounds or less

$1.50

More than 2 but not more than 6

$3.70

More than 6 but not more than 10

$5.25

Your code needs to validate the input completely, e.g., the weight and mile amounts must be positive. If an input is invalid, e.g., the weight is zero or less, you should display an appropriate, professional error message, e.g., Error: Weight must be greater than zero!, which should be offset and surrounded by white space, so it stands out, and repeat getting that input until valid input is received. Keep in mind, the user will find it annoying if they must enter both the miles and weight at the same time, and only one of them caused an error, or they must reenter already valid data; see the Sample Run. Only if all the input is valid, should the program calculate and display one shipping charge, and pause, but not quit, before proceeding to a new customer.

At this point for the code, you should only solve the problem using what you learned from modules 1 – 6, i.e., NO arrays, etc. Make sure you divide your program into multiple functions, i.e., each function solves one problem, and main() ties them all together. Also, make sure you follow the Code Conventions and good programming practices, e.g., appropriately initialize variables to zeros, avoid stacked if or if-else constructs unless necessary, don’t use break, continue, etc. to get out of a loop, goto, a return statement more than once at the end per function, etc. Your test cases should test the various possibilities, and the limits of the program, which means, you will need to use an appropriate loop, which will ask if you would like to process the next customer or not by asking them to enter an appropriate value. Once there are no more customers to process, the program should display Good-bye! and end.

Hints: You may need to reset any values after you display the answer and before you get the input for the next customer. Big Helpful Hint: For the number of segments formula, you may want to start with integer division, e.g., 1200 miles / 500 miles per segment = 2 segments, and then, expand on that. What do you need to do to the calculation to get the correct number of segments, e.g., > 1 to 500 is 1 segment, 501 to 1000 is 2 segments, 1001 to 1500 is 3 segments, etc. You cannot solve this one with nested if-else constructs; try, pattern analysis.

You should be able to solve this problem with only one loop. Although you can easily solve this with multiple nested loops, the challenge is to solve it using one loop; see the following Sample Run.

Sample Run

Enter the number of miles as a whole number: 0

        Error: Miles must be greater than zero!

Enter the number of miles as a whole number: 1

Enter the weight of the package in pounds: 0

        Error: Weight must be greater than zero!

Enter the weight of the package in pounds: 1

The cost to ship your package is: $1.50.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 500

Enter the weight of the package in pounds: 2

The cost to ship your package is: $1.50.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 500

Enter the weight of the package in pounds: 2.1

The cost to ship your package is: $3.70.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 500

Enter the weight of the package in pounds: 6

The cost to ship your package is: $3.70.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 500

Enter the weight of the package in pounds: 10.1

        Error: We don't ship packages over 10 pounds!

Enter the weight of the package in pounds: 10

The cost to ship your package is: $5.25.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 501

Enter the weight of the package in pounds: 3.75

The cost to ship your package is: $7.40.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 1000

Enter the weight of the package in pounds: 6.1

The cost to ship your package is: $10.50.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 12450

Enter the weight of the package in pounds: 1

The cost to ship your package is: $37.50.

Enter 1 to continue or 0 to quit: 0

Good-bye!

Press any key to continue . . .

You should make your program work and look like the above. Use the following tables to design and test your program.

Create an IPO Diagram Here

Input

Process

Output

Test Case 1

Input Data

Expected Results

Weight:               1.5 pounds

Miles:                  200 miles (This is one 500-mile segment.)

Your shipping charge is $1.50.

Test Case 2

Input Data

Expected Results

Weight:               5.6 pounds

Miles:                  1200 miles (This is three 500-mile segments.)

Your shipping charge is $11.10.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The following code perfectly works for all your test cases.

There are loops only for taking proper input and for repeating the process as long as the user clicks 1.

It works in linear time complexity only.

#include <stdio.h>
#include<math.h>
int main()
{
int m=0,ch;
double s,n,c;
float w=0;
do{
while(m<=0)
{
printf("Enter the number of miles as a whole number:");
scanf("%d",&m);
if(m<=0)
printf(" Error: Miles must be greater than zero!");
}
while(w<=0)
{
printf("Enter the weight of the package in pounds: ");
scanf("%f",&w);
if(w<=0)
printf(" Error: Weight must be greater than zero!");
}
if(m%500==0)
n=m/500;
else
n=m/500+1;
printf("%f",n);
if(w<=2.0)
{
c=n*1.50;
}
else if(w>2.0 && w<=6.0)
{
c=n*3.70;
}
else if(w>6.0 && w<=10.0)
{
c=n*5.25;
}
else
{
printf(" Error: We don't ship packages over 10 pounds!");
}
printf("The cost to ship your package is: $%.2f",c);
printf("Enter 1 to continue or 0 to quit: ");
scanf("%d",&ch);
}while(ch==1);
printf("Good bye!");
return 0;
}

Feel free to ask me if you have any further doubt on this.

I have checked the code for all the test cases provided by you and it works fine on all of them.

Let me know If I have not et any other criteria.I will make it for you.

Add a comment
Know the answer?
Add Answer to:
C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this assignment, you will develop a C++ program which calculates a shipping charge and determines...

    In this assignment, you will develop a C++ program which calculates a shipping charge and determines the “type of trip” for a freight shipping company. Ask the user to enter the distance a package is to be shipped, and use a menu and a switch statement to determine the rate based on the package’s weight. Then display the shipping charge and using the table in #7 below, display the type of trip. Below is the chart to use to calculate...

  • PSLAYER 09/27/2017 yo October 9,2017 Graduation st Monday at T2:43 AM Shipping Calculator: Global Courier Services...

    PSLAYER 09/27/2017 yo October 9,2017 Graduation st Monday at T2:43 AM Shipping Calculator: Global Courier Services will ship your package based on how much it weighs and how far you are sending the package. Packages above 50 pounds will not be shipped. You need to write a program in C that calculates the shipping charge The shipping rates are based on per 500 miles shipped. They are not pro-rated, ie, 600 miles is the same rate as 900 miles or...

  • Global Courier Services will ship your package based on how much it weighs and how far...

    Global Courier Services will ship your package based on how much it weighs and how far you are sending the package. (visual studio or dev c) You need to write a design tool and a program in C that calculates the shipping charge based on weight and distance and the total cost. The shipping rates are as follows: BASED ON WEIGHT Charge 10 dollars for all package weighing 10 pounds or less Charge an additional 2 dollars per pound for...

  • C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for...

    C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for shipping subject to the following restrictions: Shipping requirements The package weight must not exceed 50 pounds. The package must not exceed 3 feet in length, width, or height. The girth of the package must not exceed 5 feet. The girth is the circumference around the two smallest sides of the package. If side1, side2, and side3 are the lengths of the three sides, and...

  • write a program for C++ to use on Putty . C++ not Java The Fast Freight...

    write a program for C++ to use on Putty . C++ not Java The Fast Freight Company provides three kinds of shipping services for packages: regular, priority and overnight. They charge the following rates: Regular Priority Overnight <= 2 Kg $1.00 per Kg $3.50 per Kg $11.50 per Kg > 2 Kg but <=6 Kg $1.50 per Kg $5.50 per Kg $16.50 per Kg > 6 Kg but <=10 Kg $2.00 per Kg $7.50 per Kg $21.50 per Kg >...

  • In C using (printf and scanf) Write a program to ask the user for the weight...

    In C using (printf and scanf) Write a program to ask the user for the weight of a package, and display the shipping charges for the package. If the weight of the package is less than or equal to 0 pounds, inform the user and exit the program. The shipping charges are: Weight of Package Shipping Charge 2 pounds or less $1.25 Over 2 pounds but not more than 6 pounds $2.50 Over 6 pounds but not more than 10...

  • My program works fine with if else conditions but when it is not working when I...

    My program works fine with if else conditions but when it is not working when I try to implement it using a for loop. Can you fix my for loop and please show me how to do this using loops? I would appreciate if you could explain the loop that you are using. /* Programming Challenge: Shipping Charges The Fast Freight Shipping Company charges the following rates: Weight of Package (in Kilograms) Rate per 500 Miles Shipped 2 kg or...

  • Can someone complete this program for me in c programming language? Thank you! The Send-Ex Shipping...

    Can someone complete this program for me in c programming language? Thank you! The Send-Ex Shipping Company charges the following rates: Weight of Package 2 lbs or less Over 2 lbs but no more than 6 lbs Over 6 lbs but no more than 10 lbs Over 10 lbs Rate per Pound $1.10 $2.20 $3.70 $4.10 Write a program that asks the user to enter the weight of a package and then displays the total shipping charge. Reserve Point Opportunity/...

  • Intro to C++ For this program, again use Program 4-18 in the text as an example....

    Intro to C++ For this program, again use Program 4-18 in the text as an example. Assume you're writing this menu-driven program for a shipping company. There are two types of shipments: normal and expedited. a. As shown in Program 4-18, please declare constants for the types of shipments. Please write the names of constants in ALL CAPS. b. Show the menu in a clear form, and prompt the user for the type of shipment; the rest of the program...

  • ***USING JAVA. MUST USE A SWITCH STATEMENT. THANK YOU. Fall 2019 - Homework #3: Shipping Rates...

    ***USING JAVA. MUST USE A SWITCH STATEMENT. THANK YOU. Fall 2019 - Homework #3: Shipping Rates A client has hired your firm to implement their shipping rate rules as a Java program they can easily run. They have provided the following business rules to you. For each category, a cost and shipping time is added, as noted: Box Volume Categories: Category 1: 0.0 to 0.5 cubic feet, adds $5 to cost. Category 2: 0.5 to 2.0 cubic feet, adds $10...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT