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
//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;
}
Comments
Leave a comment