It's my revision question. Please help...

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..

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();

Recommended Answers

All 17 Replies

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.
#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();
}

is your second post related to the first post? if not, why not finish up the first problem then move on to the next. if yes then its a little confusing and therefore you should state your problem clearly

They aren't related... the 1st Question and 2nd Question are different... Cos I am stuck at this two places :( and hope anyone can help me..

Very good, now read all the intro threads and figure out what all that "how to post code" is all about.

well to implement your arrays you need a for loop and you need to initialize the arrays. I presume you want an array of names and one for the salary. Then you may need something lilke this

string employeeArray[4];
for(i=0;i<4;i++)
{
    //prompt for the name
    cin>>employeeArray[i];
}

i hope that can help a little

Thanks for replying
is this actually legal in C++ for arrays?

employeeArray[0] = data;

for your second post, how would you expect to calculate the interest rate if you dont know how it is done i.e is it 5% of the balance per month, 5% of the balance after each withdrawal,etc..you need to specify that

Thanks for replying
is this actually legal in C++ for arrays?

employeeArray[0] = data;

No. you can do something like this

employeeArray[]="the string";

or you initialize the elements of the array to 0..this has to be in integer type or double

employeeArray[]={0};

alternatively, if you want your data to be stored in the array then you do as i suggested in one of the posts using a "for loop"

for your second post, how would you expect to calculate the interest rate if you dont know how it is done i.e is it 5% of the balance per month, 5% of the balance after each withdrawal,etc..you need to specify that

It's 5% of the balance after each withdrawal

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..
--------------------------------------------------------------------

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)

then you need something like this.you need to do this after the withdrawal has been made and not before

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

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.
----------------------------------------------------------------

#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?

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

you can insert another funcion or you can insert that after the withdrawal is made

>>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

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];

		}
	}

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?

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

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

Both questions have been answered and working well...
Thanks a lot for your guides!! Couldn't be more helpful.. ^-^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.