Member Avatar for mechanicallogic

I simply cannot figure this program out (nor why I am going in debt paying professors to "teach" me). Our assignment begins with reading a data from a file and storing it in an object array and then displaying the contents of that array.

When I compile the program in MS Visual Studio I get the following error:

error C2664: 'printArray' : cannot convert parameter 1 from 'Investment [1000]' to 'Investment'
1> No constructor could take the source type, or constructor overload resolution was ambiguous

I do not understand what is causing this error or how to fix it.

Any help would be appreciated.

Investment.h code

#include <string>

using namespace std;

class Investment
{
	private:
		string lastname;
		float amount;		
		float rate;			
		int month;
		int day;
		int year;

	public:
		Investment();
		Investment(string n, float a, float r, int m, int d, int y);

		void setName(string n); 
		void setAmount(float a);
		void setRate(float r);
		void setMonth(int m);
		void setDay(int d);
		void setYear(int y);

		string getName();
		float getAmount();
		float getRate();
		int getMonth();
		int getDay();
		int getYear();
		
		float getValue(int n);
		void printDate(ostream& outf);

};

Investment.cpp code

#include "Investment.h"
#include <string>
#include <iostream>
#include <cmath>

using namespace std;

Investment::Investment()
{
	lastname="unknown";
	amount=0.0;
	rate=0.0;
	month=1;
	day=1;
	year=1900;
}

Investment::Investment(string n, float a, float r, int m, int d, int y)
{
	lastname = n;
	amount = a;
	rate = r;
	month=m;
	day=d;
	year=y;
}

void Investment::setName(string n)
{
	lastname = n;
}

void Investment::setAmount(float a)
{
	amount = a;
}

void Investment::setRate(float r)
{
	rate = r;
}

void Investment::setMonth(int m)
{
	month = m;
}

void Investment::setDay(int d)
{
	day = d;
}

void Investment::setYear(int y)
{
	year = y;
}

string Investment::getName()
{
	return lastname;
}

float Investment::getAmount()
{
	return amount;
}

float Investment::getRate()
{
	return rate;
}

int Investment::getMonth()
{
	return month;
}

int Investment::getDay()
{
	return day;
}

int Investment::getYear()
{
	return year;
}

void Investment::printDate(ostream& outf)
{
	outf << month << "/" << day << "/" << year;
}

Project2.cpp

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include "Investment.h"

using namespace std;

#define N 1000

void printArray(Investment, int);

int main()
{
	Investment InvestmentList[N];
	string filename, n, FindName;
	int NoYears, FindAmt, m, d, y;
	int noinvestors=0;
	ifstream inputdata;
	float a, r;

	cout << "Input power data file name: ";
	cin >> filename;

	inputdata.open(filename.c_str());

	if(inputdata.fail())
	{
		cerr << "Error opening input file" << endl;
		system("pause");
		exit(1);
	}

	inputdata >> n >> a >> r >> m >> d >> y;
	int i=0;

	while ( !inputdata.eof() )
	{
		InvestmentList[i].setName(n);
		InvestmentList[i].setAmount(a);
		InvestmentList[i].setRate(r);
		InvestmentList[i].setMonth(m);
		InvestmentList[i].setDay(d);
		InvestmentList[i].setYear(y);
				
		inputdata >> n >> a >> r >> m >> d >> y;

		i = i + 1;
		noinvestors=noinvestors+1;
	}

	inputdata.close();

	cout << "number of investors: " << noinvestors << endl;
	system("pause");

	printArray(InvestmentList, noinvestors);
}

void printArray(Investment x[], int no)
{
cout << "NAME" << setw(25) << "AMOUNT" << setw(15) << "RATE" << 
		setw(15) << "DATE" <<endl;
	for (int i=0; i<no; i++)
	{
		cout << x[i].getName() << setw(13) << "\t" << 
				x[i].getAmount() << setw(5) << "\t" << 
				x[i].getRate() << setw(5) << "\t"; 
		x[i].printDate(cout);
		cout << endl;
	}
}

Ok you have to make one change,

in Project2.cpp

.
.
.
using namespace std;

#define N 1000

//void printArray(Investment, int); //HERE
//make it this way
void printArray(Investment [], int);


int main()
{
.
.
.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.