Question

C++ If necessary, create a new project named Introductory20 Project and save it in the Cpp8\Chap13...

C++

If necessary, create a new project named Introductory20 Project and save it in the Cpp8\Chap13 folder. Also create a new source file named Introductory20.cpp. Write a program that displays the appropriate shipping charge based on the region code entered by the user. To be valid, the region code must contain exactly three characters: a letter (either A or B) followed by two numbers. The shipping charge for region A is $25. The shipping charge for region B is $30. Display an appropriate message if the region code is invalid. Use a sentinel value to end the program. Save and then run the program. Test the program using the following region codes: A11, B34, C7, D2A, A3N, C45, and 74TV.

Homework Answers

Answer #1

Hi. Below is the code that i had compiled in visual studio for C++.

***************************************************************************

#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
   char code[10];
   char ch;
   int length;
   int flag;
   do
   {
       cout << "\nenter the region code :";
       cin >> code;
       length = 0;
       flag = 0;

       if (code[0] != 'A' && code[0] != 'B')
       {
           flag = 1;
       }

       for (int i = 0; code[i] != '\0'; i++)
       {
           length++;
           if (length > 3)
           {
               flag = 1;
               break;
           }
           int ascii = code[i];
           if (i > 0 && !(ascii >= 48 && ascii <= 57)) //ascii value of digits 0-9 is 48 to 57
           {
               flag = 1;
               break;
           }
       }
       if (length < 3)
       {
           flag = 1;
       }
      

       if (flag == 0)
       {
           int charge = (code[0] == 'A') ? 25 : 30;
           cout << "\n\nThe shipping charge is : $" << charge;
       }
       else
       {
           cout << "\nInvalid region code!!!";
       }
       cout << "\n\twant to enter more (y/n)?";
       cin >> ch;
   } while (ch != 'n');

   return 0;
}

********************************************************************

output :

feel free to ask if you have any doubt :)

Know the answer?
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
Similar Questions
Color. Write a program that displays the color of the camera whose item number is entered...
Color. Write a program that displays the color of the camera whose item number is entered by the user. All item numbers contain exactly seven characters. All items are available in four colors: black, green, red, and white. The fourth character in the item number indicates the item’s color, as follows: a B or b indicates Black, a G or g indicates Green, an R or r indicates Red, and a W or w indicates White. If the item number...
C# Programming Using the Example provided in this Week Folder,Create a Console application that solve the...
C# Programming Using the Example provided in this Week Folder,Create a Console application that solve the following problem: The heating system in a school should be switched on if the average temperature is less than 17 degrees Celsius. The average temperature is found from the temperatures in the Math, English and IT departments. You are required to write a program that allows the user to input 3 temperatures. The program calculates and displays the average temperature and then displays "heating...
Create and use an enumeration create an enumeration and use it in a test application. 1....
Create and use an enumeration create an enumeration and use it in a test application. 1. Import the project named ch13 ex 2 Enumeration that's in the ex starts folder, 2. Create an enumeration named CustomerType. This enumeration should contain constants that represent three types of customers: retail. trade, and college. Use an enumeration 3. open the Customer Type App class. Then, add a method to this class that returns a discount percent C10 for retail. 30 for trade. and.20...
PLEASE USING C# TO SOLVE THIS PROBLEM. THANK YOU SO MUCH! a. Create a project with...
PLEASE USING C# TO SOLVE THIS PROBLEM. THANK YOU SO MUCH! a. Create a project with a Program class and write the following two methods (headers provided) as described below: - A Method, public static int InputValue(int min, int max), to input an integer number that is between (inclusive) the range of a lower bound and an upper bound. The method should accept the lower bound and the upper bound as two parameters and allow users to re-enter the number...
Create a new file named quiz_loops.py. b. Write your name and date in a comment. c....
Create a new file named quiz_loops.py. b. Write your name and date in a comment. c. Write a for loop which will display this set of values 2,4,6,8,10,12,14,16. d. Write a while which will display this set of values 16,13,10,7,4,1,-2. e. Write a for loop which will print ‘Loops are fun’ three times. f. Write a while loop that will prompt you for four numbers. Convert the number to an integer. Compute the power as power = power ** number....
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
A local artist creates and sales large unique art figures based on 3 different shapes: a...
A local artist creates and sales large unique art figures based on 3 different shapes: a cube, a torus, and an ellipsoid. The customers pick the shape and pattern for the art piece. The artist needs a program to calculate the handling fee and shipping charge based on the volume of the shape and the total processing charges to create an invoice for her customers. a) The user will enter the desired art shape via a menu option, the name...
Create a class named MyTriangle that contains the following three methods: public static boolean isValid(double sidea,...
Create a class named MyTriangle that contains the following three methods: public static boolean isValid(double sidea, double sideb, double sidec) public static double area(double sidea, double sideb, double sidec) public static String triangletType(double a, double b, double c) The isValid method returns true if the sum of the two shorter sides is greater than the longest side. The lengths of the 3 sides of the triangle are sent to this method but you may NOT assume that they are sent...
This problem is from Microsoft Visual C#: An Introduction to Object Oriented Programming (7th Edition) by...
This problem is from Microsoft Visual C#: An Introduction to Object Oriented Programming (7th Edition) by Joyce Farrell. This problem relies on the generation of a random number. You can create a random number that is at least min but less than max using the following statements: Random ranNumberGenerator = new Random(); int randomNumber; randomNumber = ranNumberGenerator.Next(min, max); Create a game similar to Hangman named GuessAWord in which a player guesses letters to try to replicate a hidden word. Store...
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to...
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. // A tic-tac-toe board looks like a table of three rows and three columns partially or completely filled with the characters X and O. // At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT