Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Jul 2017 |
Last Sign in: | 214 Weeks Ago |
Questions Answered: | 15833 |
Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
USING MULTIPLE FILES I HAVE TO COMPILE THIS IN PUTTY. BUT I AM GETTING ERROR. SO IF ANYONE CAN HELP ME COMPILING THIS THROUGH MULTIPLE FILES IN PUTTY AND ALSO TELLING ME WHY AM I GETTING ERROR AND WHERE ! THANK YOU (ASAP)
#include <iostream>Â
using namespace std;
Â
class savingsAcct
{
friend istream& operator>>(istream&, savingsAcct&);
friend ostream& operator<<(ostream&, const savingsAcct&);
public:
savingsAcct();
savingsAcct(string acctNum, double amt);
// Postcondition: balance is set to the value passed to parameter amt
static double * getAddressOfVar_annulRate();
// Postcondition: return the address of static variable annualRate (should be the same for all objects!)
static double getAnnualRate();
// Postcondition: returns annual interest rate
static void setAnnualRate(double rate); // change the annual interest rate
// Postcondition: annualRate has been changed to the value passed to parameter rate
void computeInterest();
// Interest is computed at the end of each month using monthly interest rate (i.e.,annualRate/12)
// Postcondition: interest is computed at the end of the month using the current balance
private:
string acctNo; // e.g., A1234
double balance;
static double annualRate; // classwide; store in a memory location shared by all objects
double interest; // monthly interest
};
Â
//initializing of the first scope
double savingsAcct::annualRate = 0.0;
Â
savingsAcct::savingsAcct()Â
 {
  acctNo = "";
  balance = 0.0;
  interest = 0.00;Â
 }
Â
savingsAcct::savingsAcct(string acctNum, double amt)
{
acctNo = acctNum;
balance = amt;
}
Â
double* savingsAcct::getAddressOfVar_annulRate()
{
return &annualRate;
}
Â
double savingsAcct::getAnnualRate()
{
return annualRate;
}
Â
void savingsAcct::setAnnualRate(double rate)
{
annualRate = rate;
}
Â
Â
void savingsAcct::computeInterest()
{
interest = (annualRate * balance)/12 ;Â
}
Â
  istream& operator>>(istream& input, savingsAcct& sobj)
  {
      cout << "Enter account number and balance:" << endl;
      cin >> sobj.acctNo >> sobj.balance;
      return input;
     Â
  }
  ostream& operator<<(ostream& output, const savingsAcct& sobj)
  {
      cout << "Account Number:t" << sobj.acctNo << endl;
      cout << "Balance:t" << sobj.balance << endl;
      cout << "Interest:t" << sobj.interest << endl;
      return output;
  }
Â
Â
Â
int main()
{
cout << "As of now, no object has been declared.n";
cout << "However, static data members exist before any object is declared:" << endl;
cout << "Â The address of its storage location: "Â
<< int(savingsAcct::getAddressOfVar_annulRate()) << endl;
cout << "Â Â Â Â Â Â Â Â Â Annual interest rate: " << savingsAcct::getAnnualRate() * 100Â
<< "%" << endl << endl;
Â
cout << "Still no object has declared, we now set the interest rate to 1.5%." << endl;
savingsAcct::setAnnualRate(0.015);
cout << "Â Â Now, the annual interest rate is: " << savingsAcct::getAnnualRate() * 100Â
<< "%" << endl << endl;
Â
cout << "We now declare and initialize 2 savingAcct objects." << endl;
cout << "We also compute interest at the end of 1st month and display their contents:nn";
savingsAcct s1("A1234", 5000), s2("A9876", 8000);
s1.computeInterest();
s2.computeInterest();
cout << s1 << endl << endl;
cout << s2 << endl << endl;
cout << "We now display the address of static variable annualRate" << endl;
cout << "Â by calling "getAddressOfVar_annulRate()" member function" << endl << endl;
Â
cout << "Via s1: the address of "annualRate" is " << int(s1.getAddressOfVar_annulRate()) << endl;
cout << "Via s2: the address of "annualRate" is " << int(s2.getAddressOfVar_annulRate()) << endl;
cout << "Via s1: the address of "annualRate" is " << int(savingsAcct::getAddressOfVar_annulRate()) << endl;
cout << "nIt should be quite clear that static members are indeed "class-wide!!!"" << endl;
cout << "Note: calling a static member function, "this" pointer is not involved!!!nn";
system ("pause");
    return 0;
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly