题目

Data Engineers regularly collect, process and store data. In this task you will develop a deeper understanding of how C programming language can be used for collecting, processing and storing data. In this assignment you get the opportunity to build an interactive program that can manage a list of employees in a company.

The list is stored as an array of employee_t type structures

employee_t employeelist [MAX_COMPANY_SIZE];

The employee_t is a structure typedef for struct employee. The struct employee contains the following fields

name - array of MAX_NAME_SIZE chars (string)
fte - a float between 0.0 and 1.0
level - unsigned integer between 7 and 18
birthday - a structure of date_t type as defined below.
The variable fte indicates if an employee works full-time or part-time for a company. The value fte=1.0 (or 0.5) indicates that an employee works full time (or half-time) for the company.

Note that we now have a struct nested within a struct. The birthday is a structure typedef for struct date. The struct date_t contains the following fields,

day - unsigned integer between 1 and 31 (inclusive)
month - unsigned integer between 1 and 12 (inclusive)
year - unsigned integer between 1800 and 2017
Your program interacts with the nested struct array in your memory (RAM) and simple database file in your hard disk. It should provide the following features:

  1. add employee
    Add a new employee to the employeelist through the terminal. You should collect the input by asking multiple questions from the user.

Enter name>
Enter birthday: day>
Enter birthday: month>
Enter birthday: year>
Enter FTE>
Enter level>

  1. delete last employee
    Remove the last employee from the employeelist. TIP: you cannot delete an element from an array. Instead consider using an integer to keep count of number of employees.

  2. display employee list
    Display the list of employees in the following format as shown in the sample run. Please follow the sample executable for the exact display format, including white spaces.

Name Birthday FTE Level


bee 01-01-1900 1.000 07

Pay attention to the strict formatting guide:

Name - left aligned, 10 chars at most.
Date - 2 digit day, 2 digit month, 4 digit year
FTE – 3 decimal places for the fractional part
level - 2 digits
4. save the employee list to the database file
Save the employeelist in the hard disk as a binary/text file named database. You may use your own format to save the data. You should overwrite if database file already exists.

  1. read the employee list from the database file
    Read the database file and put the data into employeelist. You may only read the data files created by your own program. You should overwrite the employeelist array you had in memory when loading from the file.

  2. exit the program
    Exit the interactive program.

The database file
It is up to you to create your own data storage format for the database file. Your program should be able to read the database that was created by itself. You can create the database as a text or binary file.

You do NOT need to be able to create a database identical to the database of the sample executable. You do NOT need to be able to read the database of the sample executable.

Your approach
First step for the assignment should be to read this specification very carefully. Then play with the sample executable. Understand how it works, try different inputs. You will only understand the task fully if you spend a reasonable time experimenting with the executable.

Breakdown the task into small measurable subtasks that can be achieved with functions, and then implement one at a time. Begin by taking small steps. Create a program that does not necessarily do all that is eventually required. Add to it slowly and methodically testing it on each occasion. Do not try to write a program that meets all the requirements in one step - this will not save you time.

TEST TEST TEST! Testing is a core part of programming. You should thoroughly test your program to make sure the behaviour is identical to the sample executable. We will provide you with test cases - think yourself. The more testing you do, higher your chances are to get a good grade for the functionality.

If your program crashes unexpectedly, or it runs but does not give the correct output, then you need to think of using a debugging strategy to determine the nature of the fault. For example, you can place printf() statements at significant points in your source code to print messages enabling you to trace execution of the program. You can also use comment delimiters to temporarily remove parts of the source code from the compilation process.

You will lose marks if you do not follow the instructions in the template file. Do NOT hard-code your solution.

When writing the code, the first step is to define the struct employee and struct date with the fields mentioned above - do NOT add extra fields. Inside the main, you can define the employeelist as an array of employee_t type - do NOT define this array as a global variable. To start with, assume all user input is perfect (within the range, correct datatype). Work on adding an employee, then on displaying the employeelist. You could then progressively work your way through other features.

Do not worry about some months not having dates 29-31 and leap years. That means 30-02-1900 is a real date, although the month of Feb does not have a day 30. Only the range conditions mentioned before apply.

All strings in C should be null-terminated i.e. the last character should always be ‘\0’. The name field in employee_t should be allocated MAX_NAME_SIZE number of chars. However because the last character is ‘\0’, the actual length of the name that can be stored is MAX_NAME_SIZE-1. Example:
Enter name>Bee1 *Jayawickrama

The employee.name field will store only the first MAX_NAME_SIZE-1 (=10, if MAX_NAME_SIZE is 11) characters including spaces and any other character: {‘B’,‘e’,‘e’,‘1’,’ ‘,’*‘,‘J’,‘a’,‘y’,‘a’,’\0’}

Note that the database file is assumed to be error free. However, your program should handle: “careless users” – a user may enter a value outside the expected range for any interactive input. Example:
Enter your choice>0
Invalid choice.

Or a careless user may try to input 365 as the month the user was born (month should be between 1 and 12). Or try to delete an employee when it is empty, etc.

I suggest initially attempt all features without worrying about careless users and having spaces in names. Then build on top of that if you still have time in hand. Note that you are expected to think yourself how a careless user could break your program - we will not provide test cases.

NOTE: Handling spaces in name is aimed for advanced students. You may need to do your own research, but more than that you may have to be creative. By using incorrect techniques you could very well introduce more bugs in your code and it could be time consuming. The special techniques required for this purpose are not examinable.

说明

Only the LAST attempt will be considered in the final marking. If you submit after the due date, but within 5 days after the due date, you will receive a notification from Ed - The assessment is due, however, Ed will receive your late submission.

Feedback on the test cases that you didn’t pass will be provided after the marking of the assignment. Functionality feedback will be provided on Ed, coding style feedback will be provided on Canvas gradebook.

The total mark of the assignment is calculated considering the functionality and the coding style. The marks shown on Ed is ONLY for the functionality. Tutors will mark the coding style manually, and enter the total mark into Canvas gradebook.

The exact test cases will not be given on Ed before the due date to prevent hard-coded programming. Please see the following hints on the test cases for reference. Please post your questions on Microsoft Teams group, and please do NOT send emails to teaching staff about questions on the assignment.

Please submit the “employeelist.c” file ONLY. If you have the database file in the workspace, please delete it before submitting. If you have other .c files that you created yourself in the workspace, please delete them before submitting.

Test 1: Basic compilation test and checks if the correct function gets called based on the user input

Test 2 - 4: Check add a student and display student functionalities

Test 4 - 6, 12: Check database functionalities, display, save, load and pick the choices in different orders

Test 7 - 10, 13-14: [Careless user] Check invalid user input (eg: date format, accessing empty databases)

Test 11: [Careless user] Check for the limit of exceeding database in storage

代码

/******************************************************************************** 48430 Fundamentals of C Programming - Assignment 2* Name:* Student ID:13126127* Date of submission:2022/10/02* A brief statement on what you could achieve (less than 50 words):* * * A brief statement on what you could NOT achieve (less than 50 words):* *
*******************************************************************************/
/******************************************************************************** List header files - do NOT use any other header files. Note that stdlib.h is* included in case you want to use any of the functions in there. However the* task can be achieved with stdio.h and string.h only.
*******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/******************************************************************************** List preprocessing directives - you may define your own.
*******************************************************************************/
#define MAX_COMPANY_SIZE 5
#define MAX_NAME_SIZE 11
/******************************************************************************** List structs - you may define struct date_time and struct flight only. Each* struct definition should have only the fields mentioned in the assignment* description.
*******************************************************************************/
typedef struct birthday{unsigned int year;unsigned int month;unsigned int day;
}birthday_t;
typedef struct employee{char name [MAX_NAME_SIZE];float fte;unsigned int level;birthday_t birthday;
}employee_t;
/******************************************************************************** Function prototypes - do NOT change the given prototypes. However you may* define your own functions if required.
*******************************************************************************/
void printMenu(void);
/******************************************************************************** Main
*******************************************************************************/
int main(void){char dbFileName[] = "database";/**/employee_t employeelist [MAX_COMPANY_SIZE];int idx=0,opt=0,i;char tmp[MAX_NAME_SIZE*100];FILE*fp;while(1){printMenu();printf("Enter your choice>\n");scanf("%d",&opt);if(opt<=0 || opt>6){printf("Invalid choice.");}else if(opt==1){if(idx==MAX_COMPANY_SIZE){printf("List is full");}else{printf("Enter name>");if(0>=scanf("%s",tmp)){aemployeelist[idx].name[0]='\0';}else{if(strlen(tmp)>10){strncpy(employeelist[idx].name,tmp,10);employeelist[idx].name[10]='\0';}else {strcpy(employeelist[idx].name,tmp);}}while(1){printf("Enter birthday: day>");scanf("%d",&employeelist[idx].birthday.day);if(0<employeelist[idx].birthday.day && employeelist[idx].birthday.day<=31){break;}else{printf("Invalid day. ");}}while(1){printf("Enter birthday: month>");scanf("%d",&employeelist[idx].birthday.month);if(0<employeelist[idx].birthday.month && employeelist[idx].birthday.month<=12){break;}else{printf("Invalid month. ");}}while(1){printf("Enter birthday: year>");scanf("%d",&employeelist[idx].birthday.year);if(1800 <= employeelist[idx].birthday.year && employeelist[idx].birthday.year<=2017 ){break;}else{printf("Invalid year. ");}}while(1){printf("Enter FTE>");scanf("%f",&employeelist[idx].fte);if(0.0 <= employeelist[idx].fte && employeelist[idx].fte<=1.0 ){break;}else{printf("Invalid FTE. ");}}while(1){printf("Enter level>");scanf("%d",&employeelist[idx].level);if(7<= employeelist[idx].level && employeelist[idx].level<=18 ){break;}else{printf("Invalid level. ");}}idx++;}}else if(opt==2){if(idx<=0){printf("List is empty");}else{idx--;}}else if(opt==3){if(idx>0){printf("Name       Birthday   FTE   Level\n");printf("---------- ---------- ----- -----\n");for(i=0;i<idx;i++){printf("%-10s %02d-%02d-%04d %.3f %02d\n"\,employeelist[i].name,employeelist[i].birthday.day\,employeelist[i].birthday.month,employeelist[i].birthday.year\,employeelist[i].fte,employeelist[i].level);}}else if(idx<=0){printf("List is empty");}}else if(opt==4){if((fp=fopen(dbFileName,"w"))!=NULL){for(i=0;i<idx;i++){fprintf(fp,"%s %d %d %d %f %d\n",\employeelist[i].name,\employeelist[i].birthday.day,\employeelist[i].birthday.month,\employeelist[i].birthday.year,\employeelist[i].fte,\employeelist[i].level);}}}else if(opt==5){if((fp=fopen(dbFileName,"r"))==NULL){printf("Read error");}else{idx=0;while(fscanf(fp,"%s %d %d %d %f %d\n",\employeelist[idx].name,\&employeelist[idx].birthday.day,\&employeelist[idx].birthday.month,\&employeelist[idx].birthday.year,\&employeelist[idx].fte,\&employeelist[idx].level)!=-1){idx++;}}}else if(opt==6){break;}}return 0;
}
/******************************************************************************** This function prints the initial menu with all instructions on how to use* this program.* inputs:* - none* outputs:* - none
*******************************************************************************/
void printMenu(void){printf("\n\n""1. add employee\n""2. delete last employee\n""3. display employee list\n""4. save the employee list to the database\n""5. read the employee list from the database\n""6. exit the program\n");
}

48430 Assessment Task 2: Assignment 员工管理系统相关推荐

  1. IAB303 Data Analytics Assessment Task

    Assessment Task IAB303 Data Analytics for Business Insight Semester I 2019 Assessment 2 – Data Analy ...

  2. 狂神Spring Boot 员工管理系统 超详细完整实现教程(小白轻松上手~)

    [SpringBoot-web系列]前文: SpringBoot-web开发(一): 静态资源的导入(源码分析) SpringBoot-web开发(二): 页面和图标定制(源码分析) SpringBo ...

  3. jsp员工管理系统mysql_简单的员工管理系统(Mysql+jdbc+Servlet+JSP)

    员工管理系统 因为学业要求,需要完成一个过关检测,但是因为检测之前没有做好准备,且想到之前用mysql+jdbc+Struts2+bootstrap做成了一个ATM系统(主要有对数据的增删改查操作), ...

  4. python管理系统-员工管理系统源程序(python实现)

    """ print("helloworld") a=123 b='a' c=[1,2,3,4] print(a,b,c,sep=' ') print( ...

  5. Python程序开发——Python实现可增删改查的员工管理系统

    目录 一.分析 (一)大纲 (二)添加员工 (三)删除员工 (四)查找员工 (五)修改员工 二.实现代码 三.测试 一.分析 (一)大纲 1.首先创建一个空列表,用来存储员工信息,即employee ...

  6. python 工资管理软件_基于[Python]的员工管理系统

    基于[Python]的员工管理系统 -------------------------------- 简介 使用python语言来完成一个员工管理系统,员工信息包含:员工工号,姓名, 年龄,性别,职位 ...

  7. 基于springboot+thymeleaf+mybatis的员工管理系统 —— 增删改查

    员工管理系统 - 增删改查 entity 查询所有功能 查询所有的页面 emplist.html 保存员工 保存员工的页面 addEmp.html 删除员工 修改员工 根据id查询员工 修改员工信息 ...

  8. 基于springboot+thymeleaf+mybatis的员工管理系统 —— 登录与注册

    员工管理系统 - 登录与注册功能 创建项目 pom.xml 数据库表设计和环境准备 建表SQL application.properties 用户注册与登录功能 entity dao service ...

  9. java 管理系统 注释_员工管理系统--带注释--oracle系统--java项目

    [实例简介] 员工管理系统--带注释--oracle系统--java项目 [实例截图] [核心代码] 31a0847e-5da9-43d6-b402-f60390d0396d └── person_M ...

最新文章

  1. cisco 恢复出厂设置
  2. CentOS 7 安装Apache 2.4.39
  3. Java XML解析工具 JDOM介绍及使用实例
  4. 在命令窗口执行java文件时,提示找不到或无法加载主类
  5. 演练 多班分数录入统计优秀人数
  6. 使用JSSDK分享页面
  7. JavaScript基础函数体中的唯一var模式(002)
  8. python实现一个小程序
  9. GuessedAtParserWarning: No parser was explicitly specified,
  10. python无限弹窗代码_python弹窗程序教程(附源码解析)
  11. 黑金Xilinx FPGA学习笔记(一)verilogHDL扫盲文-(1)
  12. 秦纪三 二世皇帝下二年(癸已、前208)——摘要
  13. 生命以负熵为生:零知识证明的前世今生
  14. Last packet sent to the server was 2 ms ago 解决办法
  15. 宝宝起名取名字:渊博雅正、令人难忘的男宝宝名字
  16. Type interface com.aiit.mapper.BrandMapper is not known to the MapperRegistry.解决办法
  17. 使用计算机解决科学研究,应用计算机科学
  18. 教育培训行业如何做好私域运营
  19. Windows环境下通过SSH登录新浪云
  20. 获利 40+万,工地技术员自学开发外挂被抓

热门文章

  1. 亲自动手制作一台迷你小主机
  2. win10 修改win登录logo_win10系统优化办法,解决卡顿,轻松用机
  3. 2022年全球与中国电子制造服务(EMS)市场现状及未来发展趋势
  4. PL/SQL连接虚拟机中的oracle数据库
  5. MATLAB绘制多组数据的双轴、三轴、四轴图
  6. 618大促,线上线下联动显威力,或在线下引发更激烈竞争
  7. 对视图的对角线切割DiagonalView
  8. python樱花武汉_武汉加油!武大本科生用Python敲出樱花绽放,满屏春天太浪漫
  9. mysql关于 Incorrect date value: ‘0000-00-00‘
  10. 无人值守安装linux指定硬盘,Linux无人值守自动化安装详细配置流程!