473,416 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Problem with function

I have written this program for an assignment that requires a static member
function to set a static data member, but I can't figure out how to get it
to change the value once set. Would someone point me in the right direction.
I'll post all of my code, but what I need help with is the static member
function. Thanks in advance.

// prevent multiple inclusions of header file

#ifndef SAVINGSACCOUNT_H

#define SAVINGSACCOUNT_H

// SavingsAccount class definition

class SavingsAccount

{

public:

SavingsAccount( double ); //constructor

void setSavingsBalance(double);

double getSavingsBalance();

double calculateMonthlyInterest();
//static member function

static double modifyInterestRate();

private:

double savingsBalance;

//static data member

static double annualInterestRate;

}; // end class SavingsAccount

#endif

// SavingsAccount member-function definitions. This file contains

// implementations of the member functions prototyped in 10-8.h.

#include <iostream>

using std::cout;

using std::endl;

#include "10-8.h" // include definition of class SavingsAccount

//define and initialize static data member at file scope

double SavingsAccount::annualInterestRate = .03;

//define static member function

double SavingsAccount::modifyInterestRate()

{

return annualInterestRate;

} //end static function

// initializing constructor

SavingsAccount::SavingsAccount( double n )

{

setSavingsBalance( n ); // call set function to initialize SavingsBalance

} // end SavingsAccount constructors

// function to set the SavingsBalance

void SavingsAccount::setSavingsBalance( double n )

{

savingsBalance = n; // store the SavingsBalance in the object

} // end function setSavingsBalance

// function to get the SavingsBalance

double SavingsAccount::getSavingsBalance()

{

return savingsBalance; // return object's Savings Balance

} // end function getSavingsBalance

// member function that calculates the monthly doubleerest

double SavingsAccount::calculateMonthlyInterest()

{

double balance = 0;

double n1 = savingsBalance;

double n2 = annualInterestRate;
balance = ((n1 * n2) / 12) + n1;

return balance;

} // end function calculateMonthlyInterest

// solution.cpp

// Including class SavingsAccount from 10-8.h for use in main.

#include <iostream>

using std::cout;

using std::endl;

#include "10-8.h" // include definition of class Rational

// function main begins program execution

int main()

{

// create SavingsAccount object
SavingsAccount saver1 =(2000.00);

SavingsAccount saver2(3000.00);

cout << " The balance for Saver1 is\n " << "$" <<
saver1.calculateMonthlyInterest() << endl;

cout << " The balance for Saver2 is\n " << "$" <<
saver2.calculateMonthlyInterest() << endl;
return 0; // indicate successful termination

} // end main
Jul 20 '06 #1
4 1555
B. Williams wrote:
I have written this program for an assignment that requires a static
member function to set a static data member, but I can't figure out
how to get it to change the value once set. Would someone point me in
the right direction. I'll post all of my code, but what I need help
with is the static member function. Thanks in advance.

// prevent multiple inclusions of header file

#ifndef SAVINGSACCOUNT_H

#define SAVINGSACCOUNT_H

// SavingsAccount class definition

class SavingsAccount

{

public:

SavingsAccount( double ); //constructor

void setSavingsBalance(double);

double getSavingsBalance();

double calculateMonthlyInterest();
//static member function

static double modifyInterestRate();
I think the point of the exercise is to create a function similar to
'setSavingsBalance' that will *set* the 'annualInterestRate' member
to the value passed as the argument (similar to 'setSavingsBalance'),
don't you think?
private:

double savingsBalance;

//static data member

static double annualInterestRate;

}; // end class SavingsAccount

#endif

[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 20 '06 #2

"Victor Bazarov" <v.********@comAcast.netwrote in message
news:e9**********@news.datemas.de...
B. Williams wrote:
>I have written this program for an assignment that requires a static
member function to set a static data member, but I can't figure out
how to get it to change the value once set. Would someone point me in
the right direction. I'll post all of my code, but what I need help
with is the static member function. Thanks in advance.

// prevent multiple inclusions of header file

#ifndef SAVINGSACCOUNT_H

#define SAVINGSACCOUNT_H

// SavingsAccount class definition

class SavingsAccount

{

public:

SavingsAccount( double ); //constructor

void setSavingsBalance(double);

double getSavingsBalance();

double calculateMonthlyInterest();
//static member function

static double modifyInterestRate();

I think the point of the exercise is to create a function similar to
'setSavingsBalance' that will *set* the 'annualInterestRate' member
to the value passed as the argument (similar to 'setSavingsBalance'),
don't you think?
>private:

double savingsBalance;

//static data member

static double annualInterestRate;

}; // end class SavingsAccount

#endif

[..]

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Victor,
That is how I interpreted it. I can write the function to set the
annualInterestRate as I did, but I would like the function to have the
ability to change the intertest rate.
Jul 20 '06 #3
B. Williams wrote:
"Victor Bazarov" <v.********@comAcast.netwrote in message
news:e9**********@news.datemas.de...
>B. Williams wrote:
>>I have written this program for an assignment that requires a static
member function to set a static data member, but I can't figure out
how to get it to change the value once set. Would someone point me
in the right direction. I'll post all of my code, but what I need
help with is the static member function. Thanks in advance.
[...]

I think the point of the exercise is to create a function similar to
'setSavingsBalance' that will *set* the 'annualInterestRate' member
to the value passed as the argument (similar to 'setSavingsBalance'),
don't you think?
[...]
Victor,
That is how I interpreted it. I can write the function to set the
annualInterestRate as I did, but I would like the function to have the
ability to change the intertest rate.
I am sorry. You can write the function to set *as you did*? You *did*
that already? I don't see the difference between "to set" or "to change".

You initialised your static data member to 0.03, but there is no function
that *sets* or *changes* that data member. If you need clarification,
I suggest you speak to your teacher/instructor/coach.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 20 '06 #4

"Victor Bazarov" <v.********@comAcast.netwrote in message
news:e9**********@news.datemas.de...
B. Williams wrote:
>"Victor Bazarov" <v.********@comAcast.netwrote in message
news:e9**********@news.datemas.de...
>>B. Williams wrote:
I have written this program for an assignment that requires a static
member function to set a static data member, but I can't figure out
how to get it to change the value once set. Would someone point me
in the right direction. I'll post all of my code, but what I need
help with is the static member function. Thanks in advance.
[...]

I think the point of the exercise is to create a function similar to
'setSavingsBalance' that will *set* the 'annualInterestRate' member
to the value passed as the argument (similar to 'setSavingsBalance'),
don't you think?
[...]
>Victor,
That is how I interpreted it. I can write the function to set the
annualInterestRate as I did, but I would like the function to have the
ability to change the intertest rate.

I am sorry. You can write the function to set *as you did*? You *did*
that already? I don't see the difference between "to set" or "to change".

You initialised your static data member to 0.03, but there is no function
that *sets* or *changes* that data member. If you need clarification,
I suggest you speak to your teacher/instructor/coach.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I understand what you are talking about, I think.

I have created some additional functional to set and get the interest rates.

// function to set the Old interest rate

void SavingsAccount::setInterestRateOld( double n )

{

n = .03;

interestRateOld = n; // store the old interest rate in the object

} // end function setInterestRateOld

// function to get the Old interest rate

double SavingsAccount::getInterestRateOld()

{

return interestRateOld; // return object's Old interest rate

} // end function getInterestRateOld

// function to set the New interest rate

void SavingsAccount::setInterestRateNew( double n )

{

n = .04;

interestRateNew = n; // store the new interest rate in the object

} // end function setInterestRateNew

// function to get the New interest rate

double SavingsAccount::getInterestRateNew()

{

return interestRateNew; // return object's New interest rate

} // end function getInterestRateNew

I wish it was as easy as speaking to an instructor. This is the 4th week of
class (online) and we haven't even received feedback from week two
assignments. I utilize you guys as my adjuct instructor.
Jul 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
7
by: Emanuel Ziegler | last post by:
Hello, I want to do some mathematics with functions. In my case the function classes are very complex, but this simple example has the same problems. To allow calculations that begin with a...
117
by: Peter Olcott | last post by:
www.halting-problem.com
1
by: Mohamed Fysal | last post by:
I have written a Regular DLL with many Export Functions and one CALLBACK fun ction . The callback function declared in the .cpp file of the Regular DLL is as fol lows: typedef BOOL...
4
by: Andy_Khosravi | last post by:
Hello, I'm having a problem with the MID function within Access 97. I have been trying to build a function to check to make sure that a field on a form does not have any spaces or dashes. This...
0
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone...
78
by: Josiah Manson | last post by:
I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only...
5
by: jbenner | last post by:
I have opened a PMR for this with IBM, and am not asking for advice from the DB2 DBA community. I am posting this as an FYI that DB2 Health Monitor, even at the latest version of DB2, still can cause...
2
by: Ravikiranreddy | last post by:
Hi every one, Am pasting the error code returned in log please help me in fixing it--- ERROR:An error occurred during the execution of the command "/opt/IBM/db2/V8.1/instance/dascrt -u...
6
by: pauldepstein | last post by:
Let double NR( double x, double(*)(const double&) f ) be the signature of a Newton-Raphson function NR. Here, f is a function which returns a double and accepts a const double&. The aim of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.