i am doing a program for my class to calculate loan payments.
i implemented my darray, struct of variables (principal, interest, length of loan) and now i am in process of creating the loan classes.
i just need to figure out how to pass the data that's stored in the struct and use it in the class.
--heres the requirements of which i am confused about...
2. Read the data from the input file and store it in a darray of type principals, where principals is a struct. The name of the file that contains the data is listed in positional parameter argv[1].
---I already have this DONE
3. Create a darray of type pointer to loan, where each element points to a loan (amortized and simple for each line of data). Notice the type of the darray is a base class pointer.
--so i created the darray, but i dont know what "darray of type pointer to loan" means...what's a base class pointer????
thanks in advance for your help.
.h file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#ifndef LOAN_H
#define LOAN_H
#include <iostream>
struct principal
{
float principal, interest;
int length;
};
class loan:public principal
{
public:
float monthlyPayment();
};
#endif
|
cpp file
1 2 3 4 5 6 7
|
#include "loan.h"
float monthlyPayment()
{
//just testing return val..
return (principal*interest);
}
|
i get this error:
1 2 3 4
|
RRFA5-4:pa6 alexandern17$ g++ *.cpp
loan.cpp: In function ‘float monthlyPayment()’:
loan.cpp:5: error: ‘length’ was not declared in this scope
RRFA5-4:pa6 alexandern17$
|
and if here's how im reading the data and storing into darray
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include "pa6functions.h"
#include "loan.h"
#include "darray.h"
void readFile(const char* file, darray<principal>& d1)
{
std::ifstream in;
in.open(file);
loan prin;
do
{
in >> prin.principal >> prin.interest >> prin.length;
d1.insert(prin);
} while(!in.eof());
std::cout << '\n' << prin.principal << ", " << prin.interest << ", " << prin.length << std::endl;
}
|