MySQL代写:DBS201 HR Application

使用C++进行数据库操作,实现一个HR数据库应用程序,练习MySQL基本用法。

MySQL

Objective

In this assignment, you create a simple HR application using the C++ programming language and MySQL server. This assignment helps students learn a basic understanding of application development using C++ programming and a MySQL database.

Instruction

In this assignment, we use the same database that you use for your labs.

Connecting to a MySQL database from a C++ Program

In your function main(), create a connection to your database.

You need to implement the following functions: int menu(void);

The menu() function returns an integer value which is the selected option by the user from the menu. This function displays the following menu options:

1) Find Employee
2) Employees Report
3) Add Employee
4) Update Employee
5) Remove Employee
0) Exit

Before printing the menu, display the following title on the screen

********************* HR Menu *********************

Prompt the user to enter an option. If the user enters an incorrect option, the user is asked to enter an option again. When the user enters a correct option (0 to 5), the function returns the selected value.

If the user selects 0 (Exit), the program terminates.

1
int findEmployee(MYSQL *conn, int employeeNumber, struct Employee *emp);

This function receives a MYSQL pointer (a reference variable to a MySQL database), an integer number as the employee number, and a pointer to a variable of type Employee. The function returns 0 if the employee does not exist. It returns 1 if the employee exits.

To store the employee data from the findEmployee() function, we use a variable of type structure called Employee. The Employee structure has the following members:

1
2
3
4
5
6
7
8
9
10
11
struct Employee {
int employeeNumber;
char lastName[50];
char firstName[50];
char email[100];
char phone[50];
char extension[10];
char reportsTo[100];
char jobTitle[50];
char city[50];
};

The ReportsTo member stores the first name and the last name of the employee who is the manager of the given employee number.
If the employee exists, store the employee data into the members of an Employee variable using the third parameter in the findEmployee() function which references to that variable of type Employee.

Note: For this report, you may need to query more than one table (join).

1
void displayEmployee(MYSQL *conn, struct Employee emp);

If the user selects option 1, this function is called. First, prompt the user to enter a value for the employee number. Then, call function findEmployee() to check if the employee with the given employee number exists. If the returning value of function findEmployee() is 0, display a proper error message.
Sample error message:

Employee 1122 does not exist.

Otherwise, call the function displayEmployee() to display the employee information.
This function receives a MYSQL pointer (a reference variable to a MySQL database) and values of a variable of type Employee and displays all members of the emp parameter.

Display the employee information as follows:

employeeNumber = 1002
lastName = Murphy
firstName = Diane
email = [email protected]
phone = +1 650 219 4782
extension = x5800
reportsTo =
jobTitle = President
city = San Francisco
1
void displayAllEmployees(MYSQL *conn);

If the user selects option 2 (Employees Report), call function displayAllEmployees().
This function receives a pointer of type MYSQL (a reference variable to a MySQL database) and displays all employees’ information if exists.

Write a query to select and display the following attributes for all employees.

If the query does not return any rows, display a proper message:

There is no employees' information to be displayed.

Note: For each query in your assignment, make sure you handle the errors and display the proper message including the error_code.
Error_code is a number returned if the query execution is not successful.

submit your .cpp file including C++ program for the Database Application assignment as AS_P1_ID.cpp