943,772 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1885
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jun 8th, 2008
0

Re: C++ coding problem..

Create a Class Employee. This class holds member variables: employee number and salary. It has an array of 4 employees and includes 4 employee number and salary.
Has 2 member functions:
Get() employee detail, namely number and salary
Display() employee detail
Create main()

I'm really not sure how to do the arrays and please correct my mistakes..
--------------------------------------------------------------------
C++ Syntax (Toggle Plain Text)
  1. class Employee
  2. {
  3. private:
  4. int eNumber;
  5. double eSalary;
  6. public:
  7. Employee()
  8. {
  9. eNumber = 1;
  10. eSalary = 1000;
  11. }
  12.  
  13. double getESalary();
  14. void displayInfo();
  15. };
  16.  
  17. int Employee::getENumber()
  18. { return eNumber;
  19. }
  20. double Employee::getESalary()
  21. { return eSalary;
  22. }
  23. void Employee::displayInfo()
  24. { cout << endl << "Number : " << eNumber;
  25. cout << endl << "Salary : " << eSalary;
  26. } int getENumber();

How is the array is supposed to be inserted into the function? Can show me please, I am really at loss...
Let's say 4 employee number and salary, (a1, 100; b2, 200; c3, 300; d4, 400)
Last edited by merkuries; Jun 8th, 2008 at 10:31 am. Reason: add
Reputation Points: 10
Solved Threads: 0
Newbie Poster
merkuries is offline Offline
9 posts
since Jun 2008
Jun 8th, 2008
0

Re: C++ coding problem..

then you need something like this.you need to do this after the withdrawal has been made and not before
C++ Syntax (Toggle Plain Text)
  1. double interest=0;
  2. interest=(0.05)*deposit; //or
  3. interest=((5/100))*deposit;
  4. deposit=interest+deposit; //this will add the interest amount to the current balance
Last edited by joshmo; Jun 8th, 2008 at 10:32 am.
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007
Jun 8th, 2008
0

Re: C++ coding problem..

Class Account
Hold variables of interest rate and deposit.
Make deposit() Withdrawal() function that checks if money in the account is enough to be withdrawn.
Show output if deposit $5000 for 12 months. 5% interest rate.
Initial deposit $20000
Write main ()
----------------------------------------------------------------
I'm not sure how to do the function to count for interest rate.
----------------------------------------------------------------
C++ Syntax (Toggle Plain Text)
  1. #include <string>
  2. #include <stdio>
  3. #include <stdlib>
  4. #include <conio>
  5. #include <iostream>
  6.  
  7. class Account
  8. {
  9. private:
  10. int Interest;
  11. double Deposit;
  12. public:
  13. Account()
  14. {
  15. Interest = 0.05;
  16. Deposit = 20000;
  17. }
  18.  
  19. void makeDeposit();
  20. void withdrawal();
  21. };
  22.  
  23. void Account::makeDeposit()
  24. { double amount;
  25. cout << endl << "Deposit Amount : ";
  26. cin >> amount;
  27. Deposit = Deposit + amount;
  28. cout << endl << "Balance : " << Deposit;
  29. }
  30. void Account::withdrawal()
  31. { double amount;
  32. cout << endl << "Withdrawal Amount : ";
  33. cin >> amount;
  34. if((Deposit>=0)&&(Deposit >= amount))
  35. {Deposit = Deposit - amount;}
  36. cout << endl << "Balance : " << Deposit;
  37. }
  38.  
  39. void main()
  40. {
  41. Account theAccount;
  42. theAccount.makeDeposit();
  43. theAccount.withdrawal();
  44. }

So should I create another function after withdrawal to insert this function or how?
C++ Syntax (Toggle Plain Text)
  1. double interest=0;
  2. interest=(0.05)*deposit; //or
  3. interest=((5/100))*deposit;
  4. deposit=interest+deposit; //this will add the interest amount to the current balance
Reputation Points: 10
Solved Threads: 0
Newbie Poster
merkuries is offline Offline
9 posts
since Jun 2008
Jun 8th, 2008
0

Re: C++ coding problem..

you can insert another funcion or you can insert that after the withdrawal is made
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007
Jun 8th, 2008
0

Re: C++ coding problem..

>>I'm really not sure how to do the arrays and please correct my mistakes..

Looks like you need a 2D array. do something like this
C++ Syntax (Toggle Plain Text)
  1. int array[row][col];
  2. int i,j;
  3.  
  4. for(i=0;i<row;i++)
  5. {
  6. cout<<"Enter the employee number and salary: "; //will prompt the user for employee number and salary
  7.  
  8. for(j=0;j<col;j++)
  9.  
  10. {
  11.  
  12. cin>>array[i][j];
  13.  
  14. }
  15. }
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007
Jun 8th, 2008
0

Re: C++ coding problem..

Thanks a lot for your guidance so far... I appreciate it a lot..

but it will only contain an array of 4 and only 4... how to go about that?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
merkuries is offline Offline
9 posts
since Jun 2008
Jun 8th, 2008
0

Re: C++ coding problem..

I used 4 since you implied that only 4 data will be needed..anyway you can declare a constant size for the array that can be changed. you can put this in your program. but remember it should be a global variable
C++ Syntax (Toggle Plain Text)
  1. const int max=4;

put the varible max wherever there is number 4. If you feel it is small then you change max to another number.

However, if you want your data to keep growing then you would need a linked list but this is not required in your question..Hope this is helping and let me know if it isnt
Last edited by joshmo; Jun 8th, 2008 at 11:09 am.
Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007
Jun 8th, 2008
0

Re: C++ coding problem..

Both questions have been answered and working well...
Thanks a lot for your guides!! Couldn't be more helpful.. ^-^
Reputation Points: 10
Solved Threads: 0
Newbie Poster
merkuries is offline Offline
9 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: A good idea when to use pointers vs "reference variables"?
Next Thread in C++ Forum Timeline: n factorial: issue with anything beyond 12!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC