1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <iostream>
#include <fstream>
#include <iomanip>
#define N 10
#define CARVALUE 10000
using namespace std;
void printStock (float [], int);
float sales (float [], int);
int findautoid (float [], int , int);
int main(){
ifstream myfile;
ifstream myfile2;
myfile.open("/Users/Soul/Documents/School/CISC/Assignment6/file.txt");
myfile2.open("/Users/Soul/Documents/School/CISC/Assignment6/file2.txt");
float inv[N], cmt;
int autoid[N];
for(int n = 0; n<N; n++){
myfile2 >> autoid[n];
}
int acct, type;
int temp;
printStock(inv,N);
myfile>>type>>acct>>cmt;
while(myfile){
if (type == 2){
inv[acct] += cmt;
autoid[acct] += cmt;
cout << "Deposit of auto " << findautoid(invl,N,autoid[acct]) << ": " << cmt << endl;
}
if (type == 1)
if (inv[acct] < cmt)
cout << "ERROR: Not enough on stock" << endl;
else{
inv[acct] -= cmt;
cout << "Withdrawal of auto " << acct << ": " << cmt << endl;
}
if (type != 2 && type !=1)
cout << "ERROR: Invalid Transation number" << endl;
myfile>>type>>acct>>cmt;
cout << endl;
}
myfile.close();
printStock(inv,N);
cout << "Total Income: $" << setprecision(100) << sales(inv,N) << endl;
return 0;
}
void printStock(float inv[], int nelts){
cout << "Car#" << setw(10) << "On Stock" << endl;
for (int n = 0; n<nelts; n++)
cout << setw(0) << n << setw(9) << inv[n] << endl;
cout << endl << endl;
return;
}
float sales(float inv[], int nelts){
float sum = 0;
for (int n = 0; n<nelts; n++)
sum += inv[n];
sum *= CARVALUE;
return sum;
}
int findautoid (float numb[], int n, int newnumber){
for(int position = 0; position < n; position++)
if(numb[position] == newnumber){
return position;
}
return -1;
}
|