Write a program using standard string functions that
accepts a price of an item and display its coded value. The
base of the key is:
X C O M P U T E R S
0 1 2 3 4 5 6 7 8 9
#include <iostream>
#include <string>
#include  <cstdint>
#include  <cctype>
using std::cout;
using std::cin;
int main() {
 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;
}
Comments