| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1729 人关注过本帖
标题:本人新手,这道结构体的题目不会做,望大神告知,谢谢!!!
只看楼主 加入收藏
公子降临1
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-6-29
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
本人新手,这道结构体的题目不会做,望大神告知,谢谢!!!
使用结构体类型数组编写一个程序用来输入并显示教师的基本情况信息。教师的基本情况信息包括:姓名、性别、出生年月日、住址、电话、月收入。要求使用嵌套的结构体类型表示出生年月日,模拟输如下列两个教师的信息,并按下列格式输出在屏幕上。
    姓名     性别    出生日期         住址            电话        月收入
 1. 李四           1965年5月8日   莲花小区6号    7432156     1200.00
 2. 王五           1972年8月9日   和平里12号     8654367     950.00


[此贴子已经被作者于2016-6-29 16:22编辑过]

搜索更多相关主题的帖子: 和平里 出生日期 莲花小区 出生年月日 结构体 
2016-06-29 16:17
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:20 
打印的空格你自己调整下。

程序代码:
#include<stdio.h>
#include<string.h>

struct data
{
    int year;
    int month;
    int day;
};


struct techer//结构体变量
{
    char name[20];//姓名
    char sex[4];//性别
    struct data birthday;//出生日期
    char addr[100];
    int tel;
    float revenue;
}techers[100];

int main()
{
    char in;
    int count = 0,i = 0;

    while (1)
    {
        printf("请输入教师信息,确认按y,取消按n:");
        scanf(" %c",&in);
        if ((in == 'y') || (in == 'Y'))
        {
            printf("请输入教师姓名:");
            scanf(" %s", techers[count].name);
            printf("请输入教师性别:");
            scanf(" %s", techers[count].sex);
            printf("请输入教师出生日期(格式:xxxx.xx.xx):");
            scanf("%d.%d.%d", &techers[count].birthday.year, &techers[count].birthday.month, &techers[count].birthday.day);
            printf("请输入教师住址:");
            scanf(" %s", techers[count].addr);
            printf("请输入教师电话:");
            scanf("%d", &techers[count].tel);
            printf("请输入教师收入:");
            scanf("%f", &techers[count].revenue);
            count++;
        }
        else
        {
            break;
        }
    }
    printf("  姓名\t性别\t出生日期\t住址\t\t电话\t  月收入\n");
    for (i = 0; i < count; i++)
    {
        printf("%d. %s\t%s\t%d年%d月%d日\t%s\t%d\t  %.2f\n"
            ,i+1 ,techers[i].name, techers[i].sex
            , techers[i].birthday.year, techers[i].birthday.month, techers[i].birthday.day
            , techers[i].addr, techers[i].tel, techers[i].revenue);
    }
}
2016-06-29 17:18
公子降临1
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-6-29
收藏
得分:0 
回复 2楼 grmmylbs
谢谢
2016-06-29 17:40
快速回复:本人新手,这道结构体的题目不会做,望大神告知,谢谢!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012124 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved