| | |
C++ coding problem..
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jun 2008
Posts: 9
Reputation:
Solved Threads: 0
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..
--------------------------------------------------------------------
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)
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)
class Employee { private: int eNumber; double eSalary; public: Employee() { eNumber = 1; eSalary = 1000; } double getESalary(); void displayInfo(); }; int Employee::getENumber() { return eNumber; } double Employee::getESalary() { return eSalary; } void Employee::displayInfo() { cout << endl << "Number : " << eNumber; cout << endl << "Salary : " << eSalary; } 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
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
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)
double interest=0; interest=(0.05)*deposit; //or interest=((5/100))*deposit; deposit=interest+deposit; //this will add the interest amount to the current balance
Last edited by joshmo; Jun 8th, 2008 at 10:32 am.
•
•
Join Date: Jun 2008
Posts: 9
Reputation:
Solved Threads: 0
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.
----------------------------------------------------------------
So should I create another function after withdrawal to insert this function or how?
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)
#include <string> #include <stdio> #include <stdlib> #include <conio> #include <iostream> class Account { private: int Interest; double Deposit; public: Account() { Interest = 0.05; Deposit = 20000; } void makeDeposit(); void withdrawal(); }; void Account::makeDeposit() { double amount; cout << endl << "Deposit Amount : "; cin >> amount; Deposit = Deposit + amount; cout << endl << "Balance : " << Deposit; } void Account::withdrawal() { double amount; cout << endl << "Withdrawal Amount : "; cin >> amount; if((Deposit>=0)&&(Deposit >= amount)) {Deposit = Deposit - amount;} cout << endl << "Balance : " << Deposit; } void main() { Account theAccount; theAccount.makeDeposit(); theAccount.withdrawal(); }
So should I create another function after withdrawal to insert this function or how?
C++ Syntax (Toggle Plain Text)
double interest=0; interest=(0.05)*deposit; //or interest=((5/100))*deposit; deposit=interest+deposit; //this will add the interest amount to the current balance
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
>>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
Looks like you need a 2D array. do something like this
C++ Syntax (Toggle Plain Text)
int array[row][col]; int i,j; for(i=0;i<row;i++) { cout<<"Enter the employee number and salary: "; //will prompt the user for employee number and salary for(j=0;j<col;j++) { cin>>array[i][j]; } }
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
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
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
C++ Syntax (Toggle Plain Text)
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.
![]() |
Similar Threads
- Convert XML data to sql table through coding in ASP.Net2.0 (IT Professionals' Lounge)
- chinese post man problem (IT Professionals' Lounge)
- Novell 6.0 Active Connection Problem (Novell)
- WINXP reinstall...code problem (Windows NT / 2000 / XP)
- Passing arrays of objects to functions (C++)
- 'times' coding problem? (C)
- Simple problem regardingform elements (ASP)
- php coding (PHP)
Other Threads in the C++ Forum
- Previous Thread: A good idea when to use pointers vs "reference variables"?
- Next Thread: n factorial: issue with anything beyond 12!
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





