In C++ please! Thank you! Problem 1 Write Code to accomplish the next definition
ID: 3762227 • Letter: I
Question
In C++ please! Thank you!
Problem 1 Write Code to accomplish the next definitions:
a) Structure called employee containing:
Array of 20 characters to store the first name,
Array of 20 characters to store the last name,
Unsigned integer to store the age
Float to store hour salary
b) Instruction to define aEmployee to be a synonym for the type struct employee.
c) Instruction to Read a last name, age and hour salary from the keyboard .
d) Assign the address of array firstName to the pointer variable ptrFirstName.
e) Print the member values of element 2 of array lastName using the variable ptrLastName and the structure pointer operator to refer to the members
Problem 2 Design a program using functions to use the structure employee defined in Problem 1 a). Apply the synonym aEmployee for the structure employee, a function to capture 3 records for 3 employees as shown, and then a function to print the 3 records as shown in the next output:
Explanation / Answer
Complete Program:
#include <iostream>
#include <string>
using namespace std;
struct employee
{
char firstName[20];
char lastName[20];
unsigned int age;
float hourSalary;
};
typedef employee aEmployee;
int main()
{
aEmployee emp;
char *ptrFirstName = new char[20];
char *ptrLastName = new char[20];
unsigned int ag;
float salary;
cout << "Enter the first name: ";
cin.getline(ptrFirstName, 20);
cout << "Enter the last name: ";
cin.getline(ptrLastName, 20);
cout << "Enter the age: ";
cin >> ag;
cout << "Enter the hour salary: ";
cin >> salary;
emp.firstName = ptrFirstName;
emp.lastName = ptrLastName;
emp.age = ag;
emp.hourSalary = salary;
cout << "First name: " << emp.firstName << endl;
cout << "Last name: " << emp.lastName << endl;
cout << "Age: " << emp.age << endl;
cout << "Hour salary: " << emp.hourSalary << endl;
system("pause");
return 0;
}