[PROGRAMMING TECHNIQUE] Group Assignment 6/12/2018

A group assignment was given for our group of three to develop a program with the use of recently learnt topics in programming technique.

 We decide to make a Foreign Currency Exchange converter for our group assignment.

 

//written by sorhye, with the help of wonderwall

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <iomanip>

using namespace std;

int main(){

//read input from file first baby

//read usd file
ifstream usd;
ifstream aud;
ifstream sgd;

ofstream output;
output.open("output.txt");

double table[6][30];

usd.open ("usd.txt");
aud.open ("aud.txt");
sgd.open ("sgd.txt");

if(!usd){
cout<<"Unable to read file. Program will exit.";
exit(1);
}

if(!aud){
cout<<"Unable to read file. Program will exit.";
exit(1);
}

if(!sgd){
cout<<"Unable to read file. Program will exit.";
exit(1);
}

char usdFromFile[81], audFromFile[81], sgdFromFile[81];
double usdArr[30], audArr[30],sgdArr[30], usdGrowth[30],audGrowth[30],sgdGrowth[30];
double usdMax,usdAvg,usdSum,usdGsum,usdGavg,audMax,audAvg,audSum,audGsum,audGavg,sgdMax,sgdAvg,sgdSum,sgdGsum,sgdGavg;
double usdMin=9999, audMin=9999, sgdMin=9999;

while(!usd.eof()){

for(int i=0; i<30; i++){
usd>>usdFromFile;
usdArr[i] = atof(usdFromFile);
// cout<<usdFromFile<<endl;
}

}

while(!aud.eof()){

for(int i=0; i<30; i++){


aud>>audFromFile;
audArr[i] = atof(audFromFile);
// cout<<audFromFile<<endl;

}

}

while(!sgd.eof()){

for(int i=0; i<30; i++){


sgd>>sgdFromFile;
sgdArr[i] = atof(sgdFromFile);
// cout<<usdFromFile<<endl;

}

}
//greet user

cout<<"Hi welcome to the foreign currency exchange displayer! ";
cout<<endl;
cout<<endl;


////calculate highest, lowest, and average value of usd in 30 days

// cout<<"Exchange rate for USD: "<<endl;
for(int i=0;i<30;i++){

if(i== 0){usdGrowth[i] = 0;
}else{usdGrowth[i] = ((usdArr[i] - usdArr[i-1])/(usdArr[i]))*100;
}

// cout<<"[Day "<<i+1<<"]: ";
// cout<<usdArr[i];
// cout<<" Growth: ";
// cout<<usdGrowth[i];
// cout<<endl;
usdSum = usdSum + usdArr[i];
usdGsum = usdGsum + usdGrowth[i];

if(usdArr[i] > usdMax) usdMax = usdArr[i];
if(usdArr [i] < usdMin) usdMin = usdArr[i];



}

////calculate highest, lowest, and average value of aud in 30 days

// cout<<"Exchange rate for AUD: "<<endl;
for(int i=0;i<30;i++){

if(i== 0){audGrowth[i] = 0;
}else{audGrowth[i] = ((audArr[i] - audArr[i-1])/(audArr[i]))*100;
}

// cout<<"[Day "<<i+1<<"]: ";
// cout<<audArr[i];
// cout<<" Growth: ";
// cout<<audGrowth[i];
// cout<<endl;
audSum = audSum + audArr[i];
audGsum = audGsum + audGrowth[i];

if(audArr[i] > audMax) audMax = audArr[i];
if(audArr [i] < audMin) audMin = audArr[i];
}


////calculate highest, lowest, and average value of aud in 30 days

// cout<<"Exchange rate for SGD: "<<endl;
for(int i=0;i<30;i++){

if(i== 0){sgdGrowth[i] = 0;
}else{sgdGrowth[i] = ((sgdArr[i] - sgdArr[i-1])/(sgdArr[i]))*100;
}

// cout<<"[Day "<<i+1<<"]: ";
// cout<<sgdArr[i];
// cout<<" Growth: ";
// cout<<sgdGrowth[i];
// cout<<endl;
sgdSum = sgdSum + sgdArr[i];
sgdGsum = sgdGsum + sgdGrowth[i];

if(sgdArr[i] > sgdMax) sgdMax = sgdArr[i];
if(sgdArr [i] < sgdMin) sgdMin = sgdArr[i];
}



usdAvg = usdSum / 30;
usdGavg = usdGsum /30;

// cout<<usdMax<<endl;
// cout<<usdMin<<endl;
// cout<<setprecision(4)<<fixed<<usdAvg<<endl;

audAvg = audSum / 30;
audGavg = audGsum /30;

// cout<<audMax<<endl;
// cout<<audMin<<endl;
// cout<<setprecision(4)<<fixed<<audAvg<<endl;

sgdAvg = sgdSum / 30;
sgdGavg = sgdGsum/30;

// cout<<sgdMax<<endl;
// cout<<sgdMin<<endl;
// cout<<setprecision(4)<<fixed<<sgdAvg<<endl;



cout<<setw(15)<<"Day"<<setw(19)<<"USD"<<setw(15)<<"USD growth"<<setw(15)<<"AUD"<<setw(15)<<"AUD growth"<<setw(15)<<setw(15)<<"SGD"<<setw(15)<<"SGD growth"<<endl;
for(int a=0;a<30;a++){
cout<<setw(15)<<"[Day "<<a+1<<"]: ";
cout<<setw(15)<<usdArr[a]<<setw(15)<<usdGrowth[a]<<setw(15)<<audArr[a]<<setw(15)<<audGrowth[a]<<setw(15)<<sgdArr[a]<<setw(15)<<sgdGrowth[a];
cout<<endl;
}

cout<<setw(20)<<"Average: "<<setw(15)<<usdAvg<<setw(15)<<usdGavg<<setw(15)<<audAvg<<setw(15)<<audGavg<<setw(15)<<sgdAvg<<setw(15)<<sgdGavg<<endl;

cout<<endl;
cout<<"Currency"<<" "<<"Maximum"<<" "<<"Minimum"<<endl;
cout<<"USD"<<" "<<usdMax<<" "<<usdMin<<endl;
cout<<"AUD"<<" "<<audMax<<" "<<audMin<<endl;
cout<<"SGD"<<" "<<sgdMax<<" "<<sgdMin<<endl;

//

output<<setw(15)<<"Day"<<setw(19)<<"USD"<<setw(15)<<"USD growth"<<setw(15)<<"AUD"<<setw(15)<<"AUD growth"<<setw(15)<<setw(15)<<"SGD"<<setw(15)<<"SGD growth"<<endl;
for(int a=0;a<30;a++){
output<<setw(15)<<"[Day "<<a+1<<"]: ";
output<<setw(15)<<usdArr[a]<<setw(15)<<usdGrowth[a]<<setw(15)<<audArr[a]<<setw(15)<<audGrowth[a]<<setw(15)<<sgdArr[a]<<setw(15)<<sgdGrowth[a];
output<<endl;
}

output<<setw(20)<<"Average: "<<setw(15)<<usdAvg<<setw(15)<<usdGavg<<setw(15)<<audAvg<<setw(15)<<audGavg<<setw(15)<<sgdAvg<<setw(15)<<sgdGavg;

output<<endl;
output<<endl;
output<<"Currency"<<" "<<"Maximum"<<" "<<"Minimum"<<endl;
output<<"USD"<<" "<<usdMax<<" "<<usdMin<<endl;
output<<"AUD"<<" "<<audMax<<" "<<audMin<<endl;
output<<"SGD"<<" "<<sgdMax<<" "<<sgdMin<<endl;



return 0;

}