There are many mistakes, step by step, we will fix the code and I suggest you program that way in the future.
First, the Class set up should be like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
#include <string>
using namespace std;
class Employee
{
private:
int Age, ID;
float Salary;
public:
Employee(); // constructor
void setAge(int x);
void setID(int x);
void SetSalary(int x);
int getAge();
int getID();
float getSalary();
void printEmployee(int arg1[1][2], int arg2, int arg3);
};
|
you can't leave
void printEmployee
out of the class.
after that, you can write your code inside of the functions or just outside like in this example:
1 2 3 4 5 6 7 8 9 10 11
|
class Rectangle {
int width, height;
public:
void set_values (int,int);
int area() {return width*height;}
};
void Rectangle::set_values (int x, int y) {
width = x;
height = y;
}
|
so it will be like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <string>
using namespace std;
class Employee
{
private:
int Age, ID;
float Salary;
public:
Employee(); // constructor
void setAge(int x);
void setID(int x);
void SetSalary(int x);
int getAge();
int getID();
float getSalary();
void printEmployee(int arg1[1][2], int arg2, int arg3);
};
Employee::Employee(){
Age = 0, ID = 0, Salary = 0;
}
void Employee::setAge(int x)
{
Age = x;
}
|
and so on..
2,
I think you forgot a '2' in the function parameter
void printEmployee(int arg1[2][3],int arg2,int arg3)
3,
and now when you want to loop through all values to get the average Salary you need two for loops just like you did:
1 2 3 4 5 6 7 8 9 10 11
|
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
totalAge =
totalSalary =
}
}
|
4,
in this part:
x[0][0].setAge = 30; x[0][0].setId = 111; x[0][0].setSalary= 30000;
you forgot to add () in the end of every function, setAge, setId, setSalary.
Those are functions and they're 100% of the time written with a (). You can't write a function like that.
5,
when dealing with classes , you need to declare an object inside int main() and then work on your functions based on that.
For example,
printEmployee(x,2,3)
shouldn't be like this because it's inside the class.. so we need an object so the class knows that it's his function.
1 2
|
Employee obj1
obj1.printEmployee(x,2,3)
|