Coding Language C 1 Modify your Project 1 code to display th
Coding Language: C++
1. Modify your Project 1 code to display the number of dollars, quarters, dimes, nickels, and pennies that the customer should receive as change only if the payment amount is greater than the amount owed. Otherwise, display a descriptive error message.
2. Modify your Project 1 code that calculates the cost of the telephone bill. Now customers are charged $10 for the first 50 minutes and $.20 a minute for all minutes over 50. Use named constants for the base cost and the per minute fee.
3. Add a menu to offer the user a choice of processing a telephone bill or translating a phone word to a phone number.
Letters - PhoneNumber Digit
ABC 2
DEF 3
GHI 4
KL 5
MNO 6
PQRS 7
TUV 8
WXYZ 9
4. Validate the user’s menu choice. If the user enters any number other than 1 or 2, a descriptive error message should display. See Sample Output below for format.
5. If the user chooses to translate a phone word, your program (for now) should prompt the user for a single letter and then display the cooresponding phone number digit. If the user’s input can not be translated into a number, then a descriptive error message should display. Your program should translate both upper and lower case letters.
Bonus Pts . After completing all instructions above, add code to validate the user’s input for the phone letter. If the input contains more than one character, then your program should display a descriptive error message. Your program should only translate the user’s input into a numeric digit if it contains exactly one character. You must follow all these instructions to receive full credit.
Original coded needed to be Modified:
#include <iostream>
 using namespace std;
 int main()
 {
 string name,addr,city,state;
 int pin,min,amount,dollars,quaters,temp,sub,dimes,nickels,pennies;
  double owed;
 cout<<\"Enter the name of Customer:\";
 getline(cin,name);
 cout<<\"Enter Street Address:\";
 getline(cin,addr);
 cout<<\"Enter City:\";
 getline(cin,city);
 cout<<\"Enter state:\";
 getline(cin,state);
 cout<<\"Enter zip code:\";
 cin>>pin;
 cout<<\"Enter the number of minutes used:\";
 cin>>min;
 owed=(double)min*0.20;
 cout<<endl<<name<<\" \"<<addr<<\" \"<<city<<\",\"<<state<<\" \"<<pin<<\"Amount Owed:\"<<owed<<endl;
 cout<<\"Enter the amount received from customer:\";
 cin>>amount;
 temp=owed*100;
 sub=amount-temp;
 dollars=sub/100;
 quaters=(sub-dollars*100)/25;
 dimes=(sub-dollars*100-quaters*25)/10;
 nickels=(sub-dollars*100-quaters*25-dimes*10)/5;
 pennies=(sub-dollars*100-quaters*25-dimes*10-nickels*5);
 cout<<\"Denomination\\tNumber\ Dollars\\t\\t\\t\"<<dollars<<\"\ Quaters\\t\\t\\t\"<<quaters<<\"\ Dimes\\t\\t\\t\"<<dimes<<\"\ Nickels\\t\\t\\t\"<<nickels<<\"\ Pennies\\t\\t\\t\"<<pennies<<\"\ \";
  return 0;
 }
SAMPLE OUTPUT:
Welcome to the Cellular Telephone System
1 – Process Telephone Bill
2 – Translate Phone Word
Enter your choice: 1
Enter the name of the customer: Larry Smith
Enter street address: 122 Main Street
Enter city: Charlotte
Enter state: NC
Enter zip code: 23499
Enter the number of minutes used: 157
Larry Smith
122 Main Street
Charlotte, NC 23499
Amount Owed: $31.40
Enter the amount received from customer: 5000
Denomination Number
-------------- ---------------
Dollars 18
Quarters 2
Dimes 1
Nickels 0
Pennies 0
______________________________________
Welcome to the Cellular Telephone System
1 – Process Telephone Bill
2 – Translate Phone Word
Enter your choice: 2
Enter a single letter: A
The cooresponding phone digit is 2.
__________________________________________
Welcome to the Cellular Telephone System
1 – Process Telephone Bill
2 – Translate Phone Word
Enter your choice: 2
Enter a single letter: h
The cooresponding phone digit is 4.
__________________________________________
Welcome to the Cellular Telephone System
1 – Process Telephone Bill
2 – Translate Phone Word
Enter your choice: 8
8 is not a valid choice.
Solution
#include <iostream>
 #include <string>
 #include <algorithm>
 using namespace std;
//named constants
 const int base = 50;
 const float perMin = 0.20;
int main()
 {
    std::string name,addr,city,state, letter;
    int pin,min,amount,dollars,quaters,temp,sub,dimes,nickels,pennies;
     double owed;
    int ch;
    //menu options
    std::cout<<\"Welcome to the Cellular Telephone System\"<<endl<<endl;
    std::cout<<\"1- Process Telephone Bill\"<<endl;
    std::cout<<\"2- Translate Phone Word\"<<endl<<endl;
    std::cout<<\"Enter your choice:\\t\";
    std::cin>>ch;
    cin.ignore();
    switch(ch){
        case 1:
        std::cout<<\"Enter the name of Customer:\\t\";
        std::getline(std::cin,name);
        cin.clear();
        std::cout<<\"Enter Street Address:\\t\";
        std::getline(std::cin,addr);
        cin.clear();
        std::cout<<\"Enter City:\\t\";
        std::getline(std::cin,city);
        cin.clear();
        std::cout<<\"Enter state:\\t\";
        std::getline(std::cin,state);
        cin.clear();
        std::cout<<\"Enter zip code:\\t\";
        std::cin>>pin;
        std::cout<<\"Enter the number of minutes used:\\t\";
        std::cin>>min;
        //new rates
        if(min<50){
            owed = base;
        }
        else{
            owed = base;
            min= min -50;
            owed+=(double)min*perMin;
        }
        // owed=(double)min*0.20;
        std::cout<<endl<<name<<\"\ \"<<addr<<\"\ \"<<city<<\",\"<<state<<\"\ \"<<pin<<endl<<\"Amount Owed:\"<<owed<<endl;
        std::cout<<\"Enter the amount received from customer:\\t\";
        std::cin>>amount;
        temp=owed*100;
        //check if customer paid more
        if(amount>temp){
            sub=amount-temp;
            dollars=sub/100;
            quaters=(sub-dollars*100)/25;
            dimes=(sub-dollars*100-quaters*25)/10;
            nickels=(sub-dollars*100-quaters*25-dimes*10)/5;
            pennies=(sub-dollars*100-quaters*25-dimes*10-nickels*5);
            std::cout<<\"Denomination\\tNumber\ Dollars\\t\\t\\t\"<<dollars<<\"\ Quaters\\t\\t\\t\"<<quaters<<\"\ Dimes\\t\\t\\t\"<<dimes<<\"\ Nickels\\t\\t\\t\"<<nickels<<\"\ Pennies\\t\\t\\t\"<<pennies<<\"\ \";
         }
        else if(amount<temp)
            std::cout<<\"Customer owes more.\"<<endl;
        else
            std::cout<<\"No change to be returned. Exact amount paid.\"<<endl;
        break;
        case 2:
        //get letter
        std::cout<<\"Enter a single letter:\\t\";
        std::getline(std::cin,letter);
        //check length
        if(letter.length()==1){
            //convert to uppercase
            transform(letter.begin(), letter.end(), letter.begin(), ::toupper);
            if(letter.compare(\"A\")==1 || letter.compare(\"B\")==1 || letter.compare(\"C\")==1)
                std::cout<<\"The corresponding phone digit is \"<<2<<endl;
            else if(letter.compare(\"D\")==1 || letter.compare(\"E\")==1 || letter.compare(\"F\")==1)
                std::cout<<\"The corresponding phone digit is \"<<3<<endl;
            else if(letter.compare(\"G\")==1 || letter.compare(\"H\")==1 || letter.compare(\"I\")==1)
                std::cout<<\"The corresponding phone digit is \"<<4<<endl;
            else if(letter.compare(\"K\")==1 || letter.compare(\"L\")==1)
                std::cout<<\"The corresponding phone digit is \"<<5<<endl;
            else if(letter.compare(\"M\")==1 || letter.compare(\"N\")==1 || letter.compare(\"O\")==1)
                std::cout<<\"The corresponding phone digit is \"<<6<<endl;
            else if(letter.compare(\"P\")==1 || letter.compare(\"Q\")==1 || letter.compare(\"R\")==1 || letter.compare(\"S\")==1)
                std::cout<<\"The corresponding phone digit is \"<<7<<endl;
            else if(letter.compare(\"T\")==1 || letter.compare(\"U\")==1 || letter.compare(\"V\")==1)
                std::cout<<\"The corresponding phone digit is \"<<8<<endl;
            else if(letter.compare(\"W\")==1 || letter.compare(\"X\")==1 || letter.compare(\"Y\")==1 || letter.compare(\"Z\")==1)
                std::cout<<\"The corresponding phone digit is \"<<9<<endl;
            else
                std::cout<<\"Invalid character entered.\"<<endl;
        }
        else
            std::cout<<\"Too many characters entered.\"<<endl;
        break;
        default:
        std::cout<<\"Invalid choice given.\";
    }
   
    return 0;
 }





