Generic programing/ no vector but array

i made this code for an excercise but its not goed yet because i must not use vector yet just array or make extra variable.
i need help to make this correction.

code:

#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream mainFile,
previousDay,
presentDay;

vector<string> company;
vector<double> sharePrices, sharesPresent, sharesPrevious;

int companyTotal;
string str1;
double aexPresent,
aexPrevious;



/*
This program should :
- read data from 3 files AEX2009.txt,AEX-10jan-2009.txt and
AEX-12jan-2009.txt.
(readAEXindexComp();readPresShares();readPrevShares())

- calculate the AEX index for 12th of january
(calculate())

- write for each company the absolute and relative change of its shares
price.(printAexAndChanges())

- determine the top riser and top faller company (printTopRiser/Faller())

*/

int readAEXindexComp(ifstream& file)
{
int count = 0;
double tmpPrice;
while(!file.eof())
{
getline(file,str1,':');
company.push_back(str1);
file.get();
file >> tmpPrice;
sharePrices.push_back(tmpPrice);
count += 1;
}
return count;
}

int readPresShares(ifstream& file)
{
int count = 0;
double tmpShare;
while(!file.eof())
{
getline(file,str1,':');
file.get();
file >> tmpShare;
sharesPresent.push_back(tmpShare);
count += 1;
}
return count - 1;
}

int readPrevShares(ifstream& file)
{
int count = 0;
double tmpShare;
while(!file.eof())
{
getline(file,str1,':');
file.get();
file >> tmpShare;
sharesPrevious.push_back(tmpShare);
count += 1;
}
return count-1;
}

double calculate(vector<double> shares)
{
double result = 0;
for (int i = 0; i < company.size(); i++)
{
result += shares.at(i)*sharePrices.at(i);
}
result = result/100;
return result;
}
void printAexAndChanges()
{
double result = 0;
result = ((aexPrevious - aexPresent)/aexPrevious);
cout << "AEX for 12 january = "
<< aexPresent
<< " "
<< result << " %\n"
<< endl
<< "COMPANY \t\t"
<< "ABSOLUTE CHANGE \t"
<< "RELATIVE CHANGE \n"
<< endl;

for (int i= 0; i < company.size() ; i++)
{
cout << company.at(i);

if(company[i].length() < 9)
{
cout << "\t\t\t\t";
}else {
cout << "\t\t\t";
}

cout << sharesPrevious.at(i) - sharesPresent.at(i)
<< "\t\t"
<< (sharesPrevious.at(i) - sharesPresent.at(i))/sharesPrevious.at(i)
<< " %"
<< endl;
}
cout << endl;
}

void printTopRiser()
{
double topRiser = 0;
double result = 0;
int index = 0;

for (int i = 0; i < company.size(); i++)
{
result = (sharesPrevious.at(i) - sharesPresent.at(i))/sharesPrevious.at(i);
if(result > topRiser) {
topRiser = result;
index = i;
}
}
cout << "Top Riser Company:" << company.at(index)
<< endl;
}
void printTopFaller()
{
double topFaller = 0;
double result = 0;
int index = 0;

for (int i = 0; i < company.size(); i++)
{
result = (sharesPrevious.at(i) - sharesPresent.at(i))/sharesPrevious.at(i);
if(result < topFaller) {
topFaller = result;
index = i;
}
}
cout << endl
<< "Top Faller Company:"
<< company.at(index)
<< endl;
}


int main()
{
mainFile.open("AEX2009.txt");
previousDay.open("AEX-10jan-2009.txt");
presentDay.open("AEX-12jan-2009.txt");

if(mainFile.fail())
{
cout << "Can't open AEX2009.txt for reading" << endl;
exit(1);
}
if(previousDay.fail())
{
cout << "Can't open AEX-10jan-2009.txt for reading" << endl;
exit(1);
}

if(presentDay.fail())
{
cout << "Can't open AEX-12jan-2009.txt for reading" << endl;
exit(1);
}

companyTotal = readAEXindexComp(mainFile);
readPresShares(presentDay);
readPrevShares(previousDay);
aexPresent = calculate(sharesPresent);
aexPrevious = calculate(sharesPrevious);
printAexAndChanges();
printTopRiser();
printTopFaller();

mainFile.close();
presentDay.close();
previousDay.close();
return 0;
}
Topic archived. No new replies allowed.