Need to add an array to this code

I need help with this code to :

a. Creating an array of employees
b. Asking the user how many employees records does he want to enter.
c. Modifying the input_data function to take the data of all employees and fill them in the array
d. Modifying the output_data function to display the records of all employees.


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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <string>
using namespace std;
void output_data(struct database*data_ptr);
void input_data(struct database*data_ptr);
struct database {
int id_number;
int age;
float salary;
string name;
};
int main()
{
struct database employee;
struct database* sp;
sp = &employee;
input_data(sp);
output_data(sp);
return 0 ;
}
void output_data(struct database*data_ptr)
{
cout << "*********************************\n";
cout << "name = " << data_ptr->name << "\n";
cout << "id_num = " << data_ptr->id_number << "\n";
cout << "age = " << data_ptr->age << "\n";
cout << "salary = " << data_ptr->salary << "\n";
cout << "*********************************\n";
}
void input_data(struct database*data_ptr)
{
int i_tmp;
float f_tmp;
string s_tmp;
cout<<"enter name:";
cin >>s_tmp;data_ptr->name = s_tmp;
cout << "enter id_number :";
cin >> i_tmp;data_ptr->id_number = i_tmp;
cout << "enter age :";
cin >> i_tmp;data_ptr->age = i_tmp;
cout << "enter salary:";
cin >> f_tmp;data_ptr->salary = f_tmp;;
cout<<endl;
}
If you need a user-sized array, I suggest you dinamic allocation or a standard container, not a fixed array
Topic archived. No new replies allowed.