Answer to Question #330052 in C++ for weneed your help

Question #330052

Write a program using standard wtring functions that accepts a price of an item and display its coded value. The base of key is:

X C 0 M P U T E R S

0 1 2 3 4 5 6 7 8 9


Sample Input/output Dialogue:

Enter Price: 489.50

Coded Value: PRS: UX


1
Expert's answer
2022-04-18T15:19:59-0400



//Program
#include <iostream>
#include <string>
#include  <cstdint>
#include  <cctype>
using std::cout;
using std::cin;
int main() {


  //Use Map -asosiative array
  char ms[10];
  std::string d="XCOMPUTERS";
  for(size_t i=0;i<d.length();i++)
    {
      ms[i]=d[i];
    }
  std::string price;//Price
  cout<<"Enter price: ";
  cin>>price;
  cout<<"Code value: ";
  for(size_t i=0;i<price.length();i++)
    {
      if(std::isdigit(price[i]))
        cout<<ms[price[i]-'0'];
      else 
        cout<<":";
    }
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS