八月二日作业

#include "test6.h"
int main(int argc, const char *argv[])
{
	class c.count=fun();
    struct Yuan *p1=grade(class c.count);
	ru(p1,class c.count);
	chu(p1,class c.count);
	nt ret = find(p1,i,j);
	if(ret == 1)
	{
		printf("有这个人\n");
	}
	else
	{
		printf("没这个人\n");	
	}

	myfree(p1);
	p1=NULL;
	return 0;
} 

 

#include "test6.h"

int fun()
{
	int a=0;
	scanf("%d",&a);
	return a;
}

struct Yuan *grade(int n)
{
	struct Class *p=(struct Yuan*)malloc(sizeof(struct Yuan)*n);
	if(NULL==p)
	{
		printf("申请失败\n");
		return NULL;
	}
	else if(NULL!=p)
	{
		printf("申请成功\n");
		return p;
	}
}

void ru(struct Yuan *P,int n)
{
	if(NULL!=p)
	{
		for(int i=0;iname);
			printf("请输这位位学员的性别: ");
			scanf("%s",(p+i)->sex);
			printf("请输入这位学员的职业: ");
			scanf("%s",(p+i)->zy);
			if((p+i)->zy=="老师")
			{
				printf("请输入这位老师所带课程: ");
				scanf("%s",p[i].a.course)
			}
			if((p+i)->zy=="学生")
			{
				printf("请输入这位学生的分数: ");
				scanf("%lf"&p[i].a.score);
			}
		}
	}
}

void chu(struct Yuan *p,int num)
{
	if(NULL == s)
	{
		printf("不合法\n");
		return;
	}
	int i = 0;
	if(p-> zy== "老师")
	{
		printf("姓名\t性别\t职业\t课程\n");
		for(i = 0; i < num; i++)
		{
			printf("%s\t%s\t%s\t%s\n",p[i].name,p[i].sex,p[i].zy, p[i].a.course);
		}
	}
	else if(p-> zy== "学生")
	{
		printf("姓名\t性别\t职业\t分数\n");
		for(i = 0; i < num; i++)
		{
			printf("%s\t%s\t%s\t%d\n",p[i].name,p[i].sex,p[i].zy, p[i].a.score);
		}
	}
}
 
 
int find(struct Yuan *p,int num,char *p1)
{
	int i = 0;
	for(i = 0; i < num; i++)
	{
		if(s[i].name ==  *p1)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
}


void myfree(struct Yuan *p)
{
	if(NULL!=p)
	{
		free p;
	}
}
#ifndef __TEST6_H__
#define __TEST6_H__
#include
#include
#include

typedef union job
{
   double score;    
   char course[100];    
}a;

struct Yuan
{
	char name[100];   
	char sex[10];         
	char zy[100];          
	union job occ;
};

typedef struct Class
{
	struct Yuan y[];
	int count;
}class;

struct Yuan *grade(int n);
void ru(struct Yuan *p,int n);
void chu(struct Yuan *p,int n);
void myfree(struct Yuan *p)
int find(struct Yuan *p,int num,char *p1)


#endif

你可能感兴趣的:(算法,c语言)