Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include using namespace std; int main ( ) { double Us _ Dollars; string Foreign _ Currency; / / ask how much you

#include
#include
#include
using namespace std;
int main(){
double Us_Dollars;
string Foreign_Currency;
//ask how much you want
cout "how much currency would you like to convert? ";
cin >> Us_Dollars;
//giving exampples
cout "whats the abbreviation for the currency you want to convert to?" endl;
cout "like this" endl;
cout "\tBRL\t\tBrazilian Real
";
cout "\tEUR\t\tEuro
";
cout "\tMXN\t\tMexican Peso
" endl;
cout "Please use all uppercase for your abbreviations! ";
cin >> Foreign_Currency;
//opening rates file
ifstream input("rates.txt");
if(!input.is_open()){
cout "Cant open rates.txt file";
return 1;
}
string Currency_Type;
double Exchange_Rate;
//match currency type
bool matched = false;
while (input.eof() && !matched){
input >> Currency_Type >> Exchange_Rate;
if (Currency_Type == Foreign_Currency){
matched = true;
}
}
if (matched){
const int WIDTH =15;
cout left fixed setprecision(2);
cout setw(WIDTH)"Us_Dollars" Foreign_Currency endl;
}else
cout "We cannot covert to that currency yet";
input.close();
return 0;
}
This lab provides more practice with files, stream manipulators, functions, and array-related
tasks.
You shall create a program to process a file of currency exchange transactions from different
foreign currencies to US Dollars. Each line of the "transactions.csv" file represents one
exchange transaction using the following format:
currency_abbreviation, currency_name, amount
For example, the following sample "transactions.csv" file contains four transactions. The first
one requests to exchange 150 Canadian Dollars to US Dollars. The second one requests to
exchange 125 Brazilian Real to US Dollars. And so on. Not all currencies in the
"transactions.csv" file have their matching exchange rates in the "rates.txt" file.
CAD, Canadian Dollar, 150
BRL,Brazilian Real, 125
MXN, Mexican Peso, 350
CUP, Cuban Peso, 199
Your program shall process the transactions and display the results in a nice columned format
using parametric parameters, as illustrated in the following sample output. You don't need to
match the exact number of spaces for each column. But there needs to be 2 digits after the
decimal space for each currency amount.
The following two function prototypes have been created in the "library. h" file. You are require
to implement these two functions in the "library.cpp" file and call these functions in the main
function.
double find_rate(string abbreviation);
This function is to take the abbreviation of a currency and look up the "rates.txt" file to return
the corresponding exchange rate. The function shall return 0 if no matching currency is found.
Note that the "rates.txt" file stores the exchange rates from US dollars to different foreign
currencies.
void convert(double foreign, double rate, double& dollars);
This function is to calculate and store the resulting US dollar amount in the third parameter
using the values of the first two parameters.
When you are ready to submit your work, capture the screenshot of the sample run of your
program. Upload the screenshot to your
Repl.it project. The lab instructor may ask you to
explain your problem-solving process and the code. When evaluating your code on
Repl.it, the
lab instructor may modify the content of the "rates.txt" and "transactions.csv" file.
///Library.cpp file
#include
#include
#include
#include
#include "library.h"
using namespace std;
double find_rate(string abbreviation);
double convert(double amount, string abbreviation_from, string abbreviation_to);
// Implement the functions here
double find_rate(string abbreviation){
double rate;
if(abbreviation == "USD")
rate =1.0;
else if(abbreviation == "EUR")
rate =0.89;
else if(abbreviation =="BRL")
rate =5.05;
else if(abbreviation =="MXN")
rate =22.26;
else if(abbreviation == "ARS")
rate =69.38;
else if(abbreviation =="HKD")
rate =7.75;
else if(abbreviation == "COP")
rate =3776.50;
else if(abbreviation == "RUB")
rate =69.74;
else{
rate =-1;
}
return rate;
}
///library.h I have so far
#include
using namespace std;
/*
This function takes one parameter as the currency abbreviation. It shall use currency abbreviation to search up the "rates.txt" file and return the corresponding exchange rate. If the currency abbreviation does not match any of those in rates.txt, the function shall return 0.
*/
double find_rate(string abbreviation);
/*
This function takes three parameters.
The first one is the amount of US Dollars.
The second one is the exchange rate from US Dollar to a foreign currency.
The third one is the corresponding amount of foreign_currency that would be determined by the function.
*/
void convert(double dollars, do
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 27th International Conference Dasfaa 2022 Virtual Event April 11 14 2022 Proceedings Part 2 Lncs 13246

Authors: Arnab Bhattacharya ,Janice Lee Mong Li ,Divyakant Agrawal ,P. Krishna Reddy ,Mukesh Mohania ,Anirban Mondal ,Vikram Goyal ,Rage Uday Kiran

1st Edition

3031001257, 978-3031001253

More Books

Students also viewed these Databases questions

Question

Write a short note on rancidity and corrosiveness.

Answered: 1 week ago