C++ coding problem..

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2008
Posts: 9
Reputation: merkuries is an unknown quantity at this point 
Solved Threads: 0
merkuries merkuries is offline Offline
Newbie Poster

Re: C++ coding problem..

 
0
  #11
Jun 8th, 2008
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..
--------------------------------------------------------------------
  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: C++ coding problem..

 
0
  #12
Jun 8th, 2008
then you need something like this.you need to do this after the withdrawal has been made and not before
  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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 9
Reputation: merkuries is an unknown quantity at this point 
Solved Threads: 0
merkuries merkuries is offline Offline
Newbie Poster

Re: C++ coding problem..

 
0
  #13
Jun 8th, 2008
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.
----------------------------------------------------------------
  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?
  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: C++ coding problem..

 
0
  #14
Jun 8th, 2008
you can insert another funcion or you can insert that after the withdrawal is made
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: C++ coding problem..

 
0
  #15
Jun 8th, 2008
>>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
  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. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 9
Reputation: merkuries is an unknown quantity at this point 
Solved Threads: 0
merkuries merkuries is offline Offline
Newbie Poster

Re: C++ coding problem..

 
0
  #16
Jun 8th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: C++ coding problem..

 
0
  #17
Jun 8th, 2008
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
  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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 9
Reputation: merkuries is an unknown quantity at this point 
Solved Threads: 0
merkuries merkuries is offline Offline
Newbie Poster

Re: C++ coding problem..

 
0
  #18
Jun 8th, 2008
Both questions have been answered and working well...
Thanks a lot for your guides!! Couldn't be more helpful.. ^-^
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC