3 Replies - 694 Views - Last Post: 20 April 2010 - 06:02 PM Rate Topic: -----

#1 Dokkan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-January 10

Investment class help

Posted 19 April 2010 - 03:14 PM

Im not sure if Im doing this right but i need some help with this problem. I just have some of the basic stuff right now. Not sure what variables to use for calculating an investment. Thanks if anyone could help a bit.

Problem:
Create an Investment class that includes the appropriate data members for various types of investments. Write appropriate get and set functions for each data member.
Also include a data member that holds the investment’s total value. Use a parameterized constructor to receive the name of each investment in a string* pointer. Be sure to include a destructor to clean up the heap when each object is destroyed. Also include a static data member and a static member function that calculates the total worth of an investment portfolio by adding together the total value of data members for each instantiated object. Add the Investment class to a console application, and then instantiate an Investment object and initialize its data. Create two additional Investment objects by copying the original object. You will need to write a copy constructor for when you duplicate objects. Retrieve and print the data members for each object. Also print the contents of the static data member using a statement similar to “Your investments are worth a total of $100,000.”

Header File:
#include <iostream>
#include <string>
using namespace std;

class Investment
{
public:
	Investment(void);
	void Investment(string*);
	void ~Investment();
	int getInvestment();
	void setInvestement();
	
private:
	static long iNumInvestments;
};



Main:
#include <iostream>
#include "Investment.h"
using namespace std;

int main()
{
	cout << "Enter your investment: " << endl;
	cin >> iNumInvestments;
	cout << "Your investment is worth a total of " << iNumInvestments;
	
};



Implementation:
Investment::Investment()
{
	
}
void Investment::Investment(string*)
{
	
}
void ~Investment()
{

}


This post has been edited by Dokkan: 20 April 2010 - 02:01 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Investment class help

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Investment class help

Posted 19 April 2010 - 03:40 PM

Here we go...this is going to be a little harsh.

You haven't gotten too far from where you were 24 hours ago. You've got to try harder than that dude. We are not going to do your homework for you.

This assignment is not a "Hello World" task; it presumes you've actually learned something in your class. In fact, it feels to me like a "putting it all together assignment," and the concern is that if it "feels like its written in a foreign language," you're probably in some deep doo-doo at this point. Although, where I'm not an investment guy, I will admit the "includes the appropriate data members for various types of investments" assumes some knowledge of that sort of thing, and if that is the "foreign language" of which you speak, you should probably see your instructor.

Notes/Problems:
string should not be capitalized (unless, Og help you, you're learning C++/CLI instead of standard C++).
Constructors and destructors do not have return types.
You've not defined a copy constructor.

I would start with going to your book and notes and read up on constructors and destructors for starters. There is a copy constructor tutorial here, also.
Was This Post Helpful? 0
  • +
  • -

#3 Dokkan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-January 10

Re: Investment class help

Posted 19 April 2010 - 04:24 PM

View PostJackOfAllTrades, on 19 April 2010 - 02:40 PM, said:

Here we go...this is going to be a little harsh.

You haven't gotten too far from where you were 24 hours ago. You've got to try harder than that dude. We are not going to do your homework for you.

This assignment is not a "Hello World" task; it presumes you've actually learned something in your class. In fact, it feels to me like a "putting it all together assignment," and the concern is that if it "feels like its written in a foreign language," you're probably in some deep doo-doo at this point. Although, where I'm not an investment guy, I will admit the "includes the appropriate data members for various types of investments" assumes some knowledge of that sort of thing, and if that is the "foreign language" of which you speak, you should probably see your instructor.

Notes/Problems:
string should not be capitalized (unless, Og help you, you're learning C++/CLI instead of standard C++).
Constructors and destructors do not have return types.
You've not defined a copy constructor.

I would start with going to your book and notes and read up on constructors and destructors for starters. There is a copy constructor tutorial here, also.

Yep. I guess its the investment stuff I don't have a clue on. I'm not strong on coming up with the right variables for these kind of problems.
Was This Post Helpful? 0
  • +
  • -

#4 Dokkan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-January 10

Re: Investment class help

Posted 20 April 2010 - 06:02 PM

View PostDokkan, on 19 April 2010 - 02:14 PM, said:

Im not sure if Im doing this right but i need some help with this problem. I just have some of the basic stuff right now. Need help with putting everything where it needs to be. Thanks if anyone could help a bit.

Problem:
Create an Investment class that includes the appropriate data members for various types of investments. Write appropriate get and set functions for each data member.
Also include a data member that holds the investment’s total value. Use a parameterized constructor to receive the name of each investment in a string* pointer. Be sure to include a destructor to clean up the heap when each object is destroyed. Also include a static data member and a static member function that calculates the total worth of an investment portfolio by adding together the total value of data members for each instantiated object. Add the Investment class to a console application, and then instantiate an Investment object and initialize its data. Create two additional Investment objects by copying the original object. You will need to write a copy constructor for when you duplicate objects. Retrieve and print the data members for each object. Also print the contents of the static data member using a statement similar to “Your investments are worth a total of $100,000.”

Header File:
#include <iostream>
#include <string>
using namespace std;

class Investment
{
public:
	Investment();
	void Investment(string*);
	~Investment();
        string* getName();
	int getValue();
        void setValue();
	void setName(string*);
	double calcInvestment(double);
                
	
private:
	static long totalInvestment;
    int iNumInvestments;
};



Main:
#include <iostream>
#include "Investment.h"
using namespace std;

int main()
{
	
	
};



Implementation:
Investment::Investment()
{
	pName = new string;
}

void Investment::Investment(string* pName)
{
	pName = new string;
	*pName = 
}

Investment::~Investment()
{
     delete pName;
     cout << "Previous Investment deleted" << endl;
}

string* Investment::getName(void) const
{
	return *pName;
}

void Investment::setName()
{
	return pName;
}

void Investment::setValue()
{
	return sharesValue;
}

int Investment::getValue()
{
	return sharesValue;
}



EDIT: Here is what the output is supposed to be

Your investment in Cisco
based on 100 shares at $67.5
is worth $6750

Your investment in Janus Fund
based on 200 shares at $98.5
is worth $19700

Your investments are worth a total of $26450
Your investment in California Municipal Bonds
based on 500 shares at $23.5
is worth $11750

Your investments are worth a total of $38200


So I am going to need a variable to hold the shares and money per share. Then output them multiplied and add all the totals up at the end.

This post has been edited by Dokkan: 20 April 2010 - 06:07 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1