Need help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Portfolio - Chapter 8
	
#include<iostream>
using namespace std;

class BankAccount
{
   private:
      int acctNum;
      double acctBal;
	  double balance;
      double annualRate;
   public:
      BankAccount(int, double = 0.0, double = 0.0);
      void enterAccountData();
      void computeInterest(int);
      void displayAccount();
      double getBal();
};
BankAccount::BankAccount(int acct, double bal, double rate)
{
   // provide definition
}
void BankAccount::enterAccountData()
{
    int account;
	double balance;
	cout<<"Please enter the account number :";
	cin>>account;
	cout<<endl;
	while(account< 1000 || account > 9999)
{
	cout<<"Error: Invalid account number,please try again. :"<<endl;
	cin>>account;
}
//Allows user to enter a balance that cannot benegative
	cout<<"Please enter the balance for "<<account << " : ";
	cin>>balance;
	cout << endl;
	while(balance < 0)
{
	cout<<"Error: Invalid balance, cannot have a negative balance, please check and try again"<<endl;
	cin>>balance;
}
	acctNum = account;
		acctBal = balance;
}
void BankAccount::computeInterest(int years)
{
	for(int i=0; i<years; i++);
{
	int interest = static_cast<int> (acctBal*0.03);
	acctBal = acctBal + interest;
	displayAccount();
}
}
void BankAccount::displayAccount()
{
	cout << "Account #" << acctNum << " ";
	cout << "Account Balance :" << acctBal << endl;
}
double BankAccount::getBal()
{
     return acctBal;
}
class Portfolio
{
   private:
     int clientNum;
     BankAccount checking;
     BankAccount savings;
     double stockMarketVal;
     double realEstateVal;
     void balancePortfolio();
  public:
     Portfolio(int, int, double, int, double, double, double, double);
     void display();
};
Portfolio::Portfolio(int client, int cNum, double cBal, int sNum,
	double sBal, double sRate, double stockVal,
	double realVal) : checking(cNum, cBal), savings(sNum, sBal, sRate)
{
    //provide definition
}
void Portfolio::balancePortfolio()
{
   //provide definition
}
void Portfolio::display()
{
   //provide definition
}
int main()
{
   //provide definition
}


b. Parkville Investment Consulting keeps track of clients’ asset portfolios. Create a class named
Portfoliothat contains a client number and two BankAccountobjects—one for checking
and one for savings. Include two other double fields for stock market holdings total value
and real estate holdings total value. The Portfolioconstructor requires checking account
data (account number and balance), savings account data (account number, balance, and
interest rate), and the value of stock market and real estate holdings. The constructor calls
a function named balancePortfolio()that determines the relative percentage of the client’s holdings in each of the four investment types. If any investment type’s value is more
than 40% of the client’s total holdings, an appropriate message displays warning that the
client’s portfolio might be out of balance. Also create a display function for the Portfolio
class to display all the details. Add any additional functions you need to the classes.
Write a main()function that continues to prompt a user for Portfoliodata until a negative
value is entered for the client account number. Create each Portfolioobject and display its
values, including the possible out-of-balance warning message.
Save the file as Portfolio.cpp.

I have no clue how to start the Portfolio part.
Okay, so Portfolio::Portfolio(//lots of variables.....) is called the constructor function. When you declare a Portfolio variable in int main() , that Portfolio variable declares all the variables inside it. But there is no value assigned to them. So int clientNum, BankAccount checking, etc.... all have junk as their value. But you don't want that. You want int clientNum , and every other variable, to start at a certain value. That's why you pass in values into Portfolio::Portfolio . So int client is the value that you want int clientNum to be at the start. Hint...sort of: clientNum = client.

For balancePortfolio() , you find their total worth first. That means adding up the balance in their checking and saving, the realestate, and the stockmarket values. if any of those four are greater than 40% of the total worth, you should cout a message saying so.

For display() , you just cout all the variables appropriately, and neatly, of course. Example, cout << "Client Number: " << clientNum << endl; .
Topic archived. No new replies allowed.