Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

If necessary, create a new project named Introductory20 Project and save it in t

ID: 3779716 • Letter: I

Question

If necessary, create a new project named Introductory20 Project and save it in the Cpp8Chap13 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.

Explanation / Answer

#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;

int main () {
   string code;
   int value;
   cout<<"Enter region code:";
   cin>>code;
   string a = code.substr (0,1);// slicing for the first char from string i.e for A or B
   string num = code.substr (1,3);// finding sub string with range i.e next two chars substring
  
   value =stoi(num);// converts string to integer
   cout<<value;
   if(a=="A"){
       cout<<"Shipping charges:"<<value*25;
   }else if(a="B"){
   cout<<"Shipping charges:"<<value*30;
   }else{
       cout<<"Region code is invalid!"
   }
   getch();
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote