This program is due by 11:59 PM on Thursday, March 2. Class on that day is optio
ID: 3842359 • Letter: T
Question
This program is due by 11:59 PM on Thursday, March 2. Class on that day is optional and can be used for working on this will be available in class if you need any assistance A quiz will be posted as soon as Canvas is restored and will be due at the time of class on Tuesday, March 7. Construct a program to convert currency of different types to US dollars. use the conversion rates below (from htt www.xe.com. Add a currency XE Live Exchange Rates 24 USD EUR NR AUD CAD ZAR NZD JPY 1 USD 1.00000 0.94279 0.80561 666896 1.30330 1.32803 13.1133 1.38501 112.038 Inverse 1.00000 1.06068 1.24130 0.01499 0.76728 0.75299 0.07626 0.72202 o 1 EUR 1.06068 1.00000 0.85449 70.7362 1.38238 1 40861 13.9089 1 46905 118 836 Inverse 0.94279 1.00000 1.17029 0.01414 0.72339 0.70992 0.07190 071 o 1 GBP 1.24130 1.17029 1.00000 82.7818 1 61778 1.64848 1 27 75 171 921 1 39 072 Inverse 0.80561 0.85449 1.00000 0.01208 0.61813 0.60662 0.06143 0.58166 0.00719 Mid-market rates 2017-02-28 1821 UTC Your program must do the following: 1. Use constants or an enumeration type to represent each of the countries. const int EUR 1; const int GBP const int INR 3 2. Create a function that uses a switch statement to convert from the constant or enumeration type to a string representation. string convertToName (int country); (Test your function before proceeding.)Explanation / Answer
#include <iostream>
using namespace std;
string convertToName(int no) // for converting constant into string
{
string a;
switch (no)
{
case 1:
a="Europe";
break;
case 2:
a="Britain";
break;
case 3:
a="India";
break;
case 4:
a="Australia";
break;
case 5:
a="Canada";
break;
case 6:
a="ZAR";
break;
case 7:
a="New Zealand";
break;
case 8:
a="Japan";
break;
default:
cout<<"Invalid country no";
break;
}
return a;
}
int showmenu() // to show the countries
{
int b;
cout<<"1.Europe ";
cout<<"2.Britain ";
cout<<"3.India ";
cout<<"4.Australia ";
cout<<"5.Canada ";
cout<<"6.ZAR ";
cout<<"7.New Zealand ";
cout<<"8.Japan ";
cout<<"Enter the country no ";
cin>>b;
return b;
}
double convertToUSdollars(int a,int amt) // for converting amount into US dollars
{
float amount;
switch(a)
{
case 1:
amount=amt*1.06068;
break;
case 2:
amount=amt*1.24130;
break;
case 3:
amount=amt*0.01499;
break;
case 4:
amount=amt*0.76728;
break;
case 5:
amount=amt*0.75299;
break;
case 6:
amount=amt*0.07626;
break;
case 7:
amount=amt*0.72202;
break;
case 8:
amount=amt*0.00893;
break;
default:
cout<<"Invalid country";
break;
}
return amount;
}
int main()
{
const int EUR=1; // declaring constants
const int GBP=2;
const int INR=3;
const int ADU=4;
const int CAD=5;
const int ZAR=6;
const int NZD=7;
const int JPY=8;
int no,a;
float amt,amount;
char ch;
string name;
cout<<"Converting constant to string ";
cout<<"1.Europe ";
cout<<"2.Britain ";
cout<<"3.India ";
cout<<"4.Australia ";
cout<<"5.Canada ";
cout<<"6.ZAR ";
cout<<"7.New Zealand ";
cout<<"8.Japan ";
cout<<"Enter the country no ";
cin>>no;
name=convertToName(no);
cout<<"Entered country is "<<name;
do // for repeated conversion
{
cout<<" Converting currency into dollars ";
a=showmenu();
cout<<"Enter the amount to be converted ";
cin>>amt;
amount=convertToUSdollars(a,amt);
cout<<"Equivalent US dollars ="<<amount;
cout<<" Want to convert more (y|n) ";
cin>>ch;
}while(ch=='y'||ch=='Y');
return 0;
}
output
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Converting constant to string
1.Europe
2.Britain
3.India
4.Australia
5.Canada
6.ZAR
7.New Zealand
8.Japan
Enter the country no
2
Entered country is Britain
Converting currency into dollars
1.Europe
2.Britain
3.India
4.Australia
5.Canada
6.ZAR
7.New Zealand
8.Japan
Enter the country no
3
Enter the amount to be converted
100
Equivalent US dollars =1.499
Want to convert more (y|n)
y Converting currency into dollars
1.Europe
2.Britain
3.India
4.Australia
5.Canada
6.ZAR
7.New Zealand
8.Japan
Enter the country no
6
Enter the amount to be converted
100
Equivalent US dollars =7.626
Want to convert more (y|n)
n
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.