用C语言编程,设有若干个人员的数据,其中有学生和教师。学生的数据中包括:姓名、号码、性别、职业、班级。教师的数据包括:姓名、号码、性别、职业、职务。要求输入人员的数据,然后再输出。

时间: 2023-07-10 18:04:26 浏览: 81
以下是用C语言编写的示例代码: ```c #include <stdio.h> #include <stdlib.h> #define MAX_NAME_LEN 20 #define MAX_NUM_LEN 10 #define MAX_OCCUPATION_LEN 20 #define MAX_CLASS_LEN 10 #define MAX_POSITION_LEN 20 typedef struct { char name[MAX_NAME_LEN]; char num[MAX_NUM_LEN]; char gender; char occupation[MAX_OCCUPATION_LEN]; char class[MAX_CLASS_LEN]; } Student; typedef struct { char name[MAX_NAME_LEN]; char num[MAX_NUM_LEN]; char gender; char occupation[MAX_OCCUPATION_LEN]; char position[MAX_POSITION_LEN]; } Teacher; void input_student(Student* student); void input_teacher(Teacher* teacher); void output_student(const Student* student); void output_teacher(const Teacher* teacher); int main() { int n; printf("Enter the number of people: "); scanf("%d", &n); Student* students = (Student*) malloc(n * sizeof(Student)); Teacher* teachers = (Teacher*) malloc(n * sizeof(Teacher)); printf("Enter the data of %d students:\n", n); for (int i = 0; i < n; i++) { input_student(&students[i]); } printf("Enter the data of %d teachers:\n", n); for (int i = 0; i < n; i++) { input_teacher(&teachers[i]); } printf("The data of %d students:\n", n); for (int i = 0; i < n; i++) { output_student(&students[i]); } printf("The data of %d teachers:\n", n); for (int i = 0; i < n; i++) { output_teacher(&teachers[i]); } free(students); free(teachers); return 0; } void input_student(Student* student) { printf("Enter the name of the student: "); scanf("%s", student->name); printf("Enter the number of the student: "); scanf("%s", student->num); printf("Enter the gender of the student (M or F): "); scanf(" %c", &student->gender); printf("Enter the occupation of the student: "); scanf("%s", student->occupation); printf("Enter the class of the student: "); scanf("%s", student->class); } void input_teacher(Teacher* teacher) { printf("Enter the name of the teacher: "); scanf("%s", teacher->name); printf("Enter the number of the teacher: "); scanf("%s", teacher->num); printf("Enter the gender of the teacher (M or F): "); scanf(" %c", &teacher->gender); printf("Enter the occupation of the teacher: "); scanf("%s", teacher->occupation); printf("Enter the position of the teacher: "); scanf("%s", teacher->position); } void output_student(const Student* student) { printf("Name: %s\n", student->name); printf("Number: %s\n", student->num); printf("Gender: %c\n", student->gender); printf("Occupation: %s\n", student->occupation); printf("Class: %s\n", student->class); } void output_teacher(const Teacher* teacher) { printf("Name: %s\n", teacher->name); printf("Number: %s\n", teacher->num); printf("Gender: %c\n", teacher->gender); printf("Occupation: %s\n", teacher->occupation); printf("Position: %s\n", teacher->position); } ``` 运行示例: ``` Enter the number of people: 2 Enter the data of 2 students: Enter the name of the student: Alice Enter the number of the student: 1001 Enter the gender of the student (M or F): F Enter the occupation of the student: Student Enter the class of the student: ClassA Enter the name of the student: Bob Enter the number of the student: 1002 Enter the gender of the student (M or F): M Enter the occupation of the student: Student Enter the class of the student: ClassB Enter the data of 2 teachers: Enter the name of the teacher: Carol Enter the number of the teacher: T1001 Enter the gender of the teacher (M or F): F Enter the occupation of the teacher: Teacher Enter the position of the teacher: Principal Enter the name of the teacher: Dave Enter the number of the teacher: T1002 Enter the gender of the teacher (M or F): M Enter the occupation of the teacher: Teacher Enter the position of the teacher: Vice Principal The data of 2 students: Name: Alice Number: 1001 Gender: F Occupation: Student Class: ClassA Name: Bob Number: 1002 Gender: M Occupation: Student Class: ClassB The data of 2 teachers: Name: Carol Number: T1001 Gender: F Occupation: Teacher Position: Principal Name: Dave Number: T1002 Gender: M Occupation: Teacher Position: Vice Principal ```

最新推荐

recommend-type

学生成绩管理系统(数据结构)实验报告.docx

期末实践周必备(数据结构)学生成绩管理系统,基于C语言完成的,百分百作者原创,资源保证!
recommend-type

用C语言实现从文本文件中读取数据后进行排序的功能

是一个十分可靠的程序,这个程序的查错能力非常强悍。程序包含了文件操作,归并排序和字符串输入等多种技术。对大家学习C语言很有帮助,有需要的一起来看看。
recommend-type

C语言程序设计实现学生成绩记录簿

通过编写c语言《学生成绩记录簿系统》让我知道所学的编程语言是需要多练多编写代码锻炼出来的。 1)C语言课程设计的主要目的是培养学生综合运用C语言程序设计课程所学到的知识,编写C程序解决实际问题的能力,以及...
recommend-type

C语言数组实现学生信息管理系统设计

主要为大家详细介绍了C语言数组实现学生信息管理系统设计,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

c语言实现把文件中数据读取并存到数组中

下面小编就为大家带来一篇c语言实现把文件中数据读取并存到数组中。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
recommend-type

CIC Compiler v4.0 LogiCORE IP Product Guide

CIC Compiler v4.0 LogiCORE IP Product Guide是Xilinx Vivado Design Suite的一部分,专注于Vivado工具中的CIC(Cascaded Integrator-Comb滤波器)逻辑内核的设计、实现和调试。这份指南涵盖了从设计流程概述、产品规格、核心设计指导到实际设计步骤的详细内容。 1. **产品概述**: - CIC Compiler v4.0是一款针对FPGA设计的专业IP核,用于实现连续积分-组合(CIC)滤波器,常用于信号处理应用中的滤波、下采样和频率变换等任务。 - Navigating Content by Design Process部分引导用户按照设计流程的顺序来理解和操作IP核。 2. **产品规格**: - 该指南提供了Port Descriptions章节,详述了IP核与外设之间的接口,包括输入输出数据流以及可能的控制信号,这对于接口配置至关重要。 3. **设计流程**: - General Design Guidelines强调了在使用CIC Compiler时的基本原则,如选择合适的滤波器阶数、确定时钟配置和复位策略。 - Clocking和Resets章节讨论了时钟管理以及确保系统稳定性的关键性复位机制。 - Protocol Description部分介绍了IP核与其他模块如何通过协议进行通信,以确保正确的数据传输。 4. **设计流程步骤**: - Customizing and Generating the Core讲述了如何定制CIC Compiler的参数,以及如何将其集成到Vivado Design Suite的设计流程中。 - Constraining the Core部分涉及如何在设计约束文件中正确设置IP核的行为,以满足具体的应用需求。 - Simulation、Synthesis and Implementation章节详细介绍了使用Vivado工具进行功能仿真、逻辑综合和实施的过程。 5. **测试与升级**: - Test Bench部分提供了一个演示性的测试平台,帮助用户验证IP核的功能。 - Migrating to the Vivado Design Suite和Upgrading in the Vivado Design Suite指导用户如何在新版本的Vivado工具中更新和迁移CIC Compiler IP。 6. **支持与资源**: - Documentation Navigator and Design Hubs链接了更多Xilinx官方文档和社区资源,便于用户查找更多信息和解决问题。 - Revision History记录了IP核的版本变化和更新历史,确保用户了解最新的改进和兼容性信息。 7. **法律责任**: - 重要Legal Notices部分包含了版权声明、许可条款和其他法律注意事项,确保用户在使用过程中遵循相关规定。 CIC Compiler v4.0 LogiCORE IP Product Guide是FPGA开发人员在使用Vivado工具设计CIC滤波器时的重要参考资料,提供了完整的IP核设计流程、功能细节及技术支持路径。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB矩阵奇异值分解(SVD)应用指南:从降维到图像处理,5个实用案例

![MATLAB矩阵奇异值分解(SVD)应用指南:从降维到图像处理,5个实用案例](https://img-blog.csdnimg.cn/20200302213423127.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDEzMjAzNQ==,size_16,color_FFFFFF,t_70) # 1. 矩阵奇异值分解(SVD)简介** 矩阵奇异值分解(SVD)是一种强大的线性代数技术,用于将矩阵分解为三个
recommend-type

HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_0); HAL_Delay(200);是什么意思

这段代码是针对STM32F4xx系列的GPIO库函数,用于控制GPIOC的0号引脚的电平状态。具体来说,HAL_GPIO_TogglePin函数用于翻转GPIO引脚的电平状态,即如果该引脚原来是高电平,则变为低电平,反之亦然。而HAL_Delay函数则是用于延时200毫秒。因此,这段代码的作用是每200毫秒翻转一次GPIOC的0号引脚的电平状态。
recommend-type

G989.pdf

"这篇文档是关于ITU-T G.989.3标准,详细规定了40千兆位无源光网络(NG-PON2)的传输汇聚层规范,适用于住宅、商业、移动回程等多种应用场景的光接入网络。NG-PON2系统采用多波长技术,具有高度的容量扩展性,可适应未来100Gbit/s或更高的带宽需求。" 本文档主要涵盖了以下几个关键知识点: 1. **无源光网络(PON)技术**:无源光网络是一种光纤接入技术,其中光分配网络不包含任何需要电源的有源电子设备,从而降低了维护成本和能耗。40G NG-PON2是PON技术的一个重要发展,显著提升了带宽能力。 2. **40千兆位能力**:G.989.3标准定义的40G NG-PON2系统提供了40Gbps的传输速率,为用户提供超高速的数据传输服务,满足高带宽需求的应用,如高清视频流、云服务和大规模企业网络。 3. **多波长信道**:NG-PON2支持多个独立的波长信道,每个信道可以承载不同的服务,提高了频谱效率和网络利用率。这种多波长技术允许在同一个光纤上同时传输多个数据流,显著增加了系统的总容量。 4. **时分和波分复用(TWDM)**:TWDM允许在不同时间间隔内分配不同波长,为每个用户分配专用的时隙,从而实现多个用户共享同一光纤资源的同时传输。 5. **点对点波分复用(WDMPtP)**:与TWDM相比,WDMPtP提供了一种更直接的波长分配方式,每个波长直接连接到特定的用户或设备,减少了信道之间的干扰,增强了网络性能和稳定性。 6. **容量扩展性**:NG-PON2设计时考虑了未来的容量需求,系统能够灵活地增加波长数量或提高每个波长的速率,以适应不断增长的带宽需求,例如提升至100Gbit/s或更高。 7. **应用场景**:40G NG-PON2不仅用于住宅宽带服务,还广泛应用于商业环境中的数据中心互联、企业网络以及移动通信基站的回传,为各种业务提供了高性能的接入解决方案。 8. **ITU-T标准**:作为国际电信联盟电信标准化部门(ITU-T)的一部分,G.989.3建议书为全球的电信运营商和设备制造商提供了一套统一的技术规范,确保不同厂商的产品和服务之间的兼容性和互操作性。 9. **光接入网络**:G.989.3标准是接入网络技术的一个重要组成部分,它与光纤到户(FTTH)、光纤到楼(FTTB)等光接入方案相结合,构建了高效、可靠的宽带接入基础设施。 ITU-T G.989.3标准详细规定了40G NG-PON2系统的传输汇聚层,为现代高速网络接入提供了强大的技术支持,推动了光通信技术的持续进步。