create an input/output function(istream&)

May 10, 2011 at 18:12:27
Specs: Windows 7
i need to create and imput function(istream$)
and output function (ostream&)


#include <iostream>
#include <fstream>
#include <cstdlib>
int main ()
{
CDaccount myCD = CDaccount();
ERRORS *****istream& enterStream = cin;***** ERRORS
ERRORS *****ostream& outStream = cout;***** ERRORS


myCD.enterCdParamaters(enterStream);
//get_data(myCD);
myCD.getBalanceAtMaturity();
myCD.getCdParamaters(outStream);

return 0;
}


class CDaccount
{
private :
double balance;
double interest_rate;
int term; //months unitl maturity

public :

CDaccount (double, double, int);
double getBalance();
double getBalanceAtMaturity();

double getInterestRate();
int getTerm();
void enterCdParamaters(istream& myIStream);
void getCdParamaters(ostream& myIStream);

};


CDaccount::CDaccount(double bal = 0.0, double int_rate = 0.0, int myTerm = 0)
{
balance = bal;
interest_rate = int_rate;
term = myTerm;
}

double CDaccount::getBalance()
{
return balance;

}

double CDaccount::getInterestRate()
{
return interest_rate;
}

int CDaccount::getTerm()
{
return term;
}


double CDaccount::getBalanceAtMaturity()
{
double rate_fraction = 0.0;
double interest = 0.0;
rate_fraction = (interest_rate/100.0);
interest = ((balance * rate_fraction) * (term/12.0));
return balance = balance + interest;

}

void CDaccount::enterCdParamaters(istream& myIStream)
{
float bal, intr_rate;
int trm;
cout << "Enter Balance :" <<endl;
myIStream >> balance;
cout << "Enter Interest Rate :" <<endl;
myIStream >> interest_rate;
cout << "Enter Term :" <<endl;
myIStream>> term;
}

void CDaccount::getCdParamaters(ostream& oStream)
{
oStream.setf(ios::fixed);
oStream.setf(ios::showpoint);
oStream.precision(2);
//oStream <<"when your CD matures in "<< term << " months,\n"<< "at interest rate of " << interest_rate,\n" << "it will have a balance of $"<<balance << endl;
oStream << "When your CD matures in "<< term << " months, \n" << "it will have a balance of $" << balance << endl;

}


void get_data(CDaccount& the_account)
{
cout << "Initial Balance = " << the_account.getBalance() <<endl;
cout << "Term = " << the_account.getTerm() <<endl;
cout << "InterestRate = " << the_account.getInterestRate() <<endl;
cout << "Balance at maturity = " << the_account.getBalanceAtMaturity() <<endl;

}

why am i getting errors with
ERRORS *****istream& enterStream = cin;***** ERRORS
ERRORS *****ostream& outStream = cout;***** ERRORS



See More: create an input/output function(istream&)

Report •


#1
May 10, 2011 at 18:34:04
NvM i forgot to put in the line "using namespace std;" :(

Report •
Related Solutions


Ask Question