用c语言实现社团基本信息名称,口号,宗旨,发起人,章程的增删改操作。同样实现组织机构管理中的成员的招新与退社,干部管理的选举,机构管理的社团机构的创建,修改删除查询,最后再实现赞助商基本信息的增删改和赞助商与社团关系的管理,并将其保存在硬盘中
时间: 2024-03-25 22:37:13 浏览: 12
好的,这个问题已经在之前被问到了,我可以重复之前的回答并且加入一些更多的细节。
首先,我们需要定义社团基本信息的结构体,如下所示:
```c
typedef struct {
char name[50]; // 社团名称
char slogan[100]; // 口号
char purpose[200]; // 宗旨
char founder[50]; // 发起人
char charter[500]; // 章程
} ClubInfo;
```
然后,我们可以实现相关的增删改查操作,如下所示:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义结构体
typedef struct {
char name[50]; // 社团名称
char slogan[100]; // 口号
char purpose[200]; // 宗旨
char founder[50]; // 发起人
char charter[500]; // 章程
} ClubInfo;
// 增加社团基本信息
void addClubInfo(ClubInfo info) {
FILE* fp;
fp = fopen("clubinfo.txt", "a+");
fprintf(fp, "%s,%s,%s,%s,%s\n", info.name, info.slogan, info.purpose, info.founder, info.charter);
fclose(fp);
}
// 删除社团基本信息
void deleteClubInfo(char* name) {
FILE* fp1, *fp2;
char temp[1000];
fp1 = fopen("clubinfo.txt", "r");
fp2 = fopen("temp.txt", "w");
while(fgets(temp, 1000, fp1) != NULL) {
if(strstr(temp, name) == NULL) {
fprintf(fp2, "%s", temp);
}
}
fclose(fp1);
fclose(fp2);
remove("clubinfo.txt");
rename("temp.txt", "clubinfo.txt");
}
// 修改社团基本信息
void updateClubInfo(char* name, ClubInfo info) {
FILE* fp1, *fp2;
char temp[1000];
fp1 = fopen("clubinfo.txt", "r");
fp2 = fopen("temp.txt", "w");
while(fgets(temp, 1000, fp1) != NULL) {
if(strstr(temp, name) == NULL) {
fprintf(fp2, "%s", temp);
} else {
fprintf(fp2, "%s,%s,%s,%s,%s\n", info.name, info.slogan, info.purpose, info.founder, info.charter);
}
}
fclose(fp1);
fclose(fp2);
remove("clubinfo.txt");
rename("temp.txt", "clubinfo.txt");
}
// 查询社团基本信息
ClubInfo* queryClubInfo(char* name) {
FILE* fp;
char temp[1000];
ClubInfo* info = malloc(sizeof(ClubInfo));
fp = fopen("clubinfo.txt", "r");
while(fgets(temp, 1000, fp) != NULL) {
if(strstr(temp, name) != NULL) {
char* token = strtok(temp, ",");
strcpy(info->name, token);
token = strtok(NULL, ",");
strcpy(info->slogan, token);
token = strtok(NULL, ",");
strcpy(info->purpose, token);
token = strtok(NULL, ",");
strcpy(info->founder, token);
token = strtok(NULL, "\n");
strcpy(info->charter, token);
}
}
fclose(fp);
return info;
}
```
接下来,我们需要定义组织机构管理的结构体,如下所示:
```c
typedef struct {
char name[50]; // 姓名
char gender; // 性别
int age; // 年龄
char phone[20]; // 手机号码
char email[50]; // 电子邮件
char address[100]; // 地址
} Member;
```
然后,我们可以实现相关的招新、退社、选举等操作,如下所示:
```c
// 招新
void addMember(Member member) {
FILE* fp;
fp = fopen("members.txt", "a+");
fprintf(fp, "%s,%c,%d,%s,%s,%s\n", member.name, member.gender, member.age, member.phone, member.email, member.address);
fclose(fp);
}
// 退社
void deleteMember(char* name) {
FILE* fp1, *fp2;
char temp[1000];
fp1 = fopen("members.txt", "r");
fp2 = fopen("temp.txt", "w");
while(fgets(temp, 1000, fp1) != NULL) {
if(strstr(temp, name) == NULL) {
fprintf(fp2, "%s", temp);
}
}
fclose(fp1);
fclose(fp2);
remove("members.txt");
rename("temp.txt", "members.txt");
}
// 选举干部
void electLeader(char* position, char* name) {
FILE* fp1, *fp2;
char temp[1000];
fp1 = fopen("members.txt", "r");
fp2 = fopen("temp.txt", "w");
while(fgets(temp, 1000, fp1) != NULL) {
if(strstr(temp, name) != NULL) {
char* token = strtok(temp, ",");
fprintf(fp2, "%s,%c,%d,%s,%s,%s,%s\n", token, token[0], atoi(strtok(NULL, ",")), strtok(NULL, ","), strtok(NULL, ","), strtok(NULL, "\n"), position);
} else {
fprintf(fp2, "%s", temp);
}
}
fclose(fp1);
fclose(fp2);
remove("members.txt");
rename("temp.txt", "members.txt");
}
// 创建社团机构
void createOrganization(char* name) {
FILE* fp1, *fp2;
char temp[1000];
fp1 = fopen("organizations.txt", "r");
fp2 = fopen("temp.txt", "w");
while(fgets(temp, 1000, fp1) != NULL) {
fprintf(fp2, "%s", temp);
}
fprintf(fp2, "%s\n", name);
fclose(fp1);
fclose(fp2);
remove("organizations.txt");
rename("temp.txt", "organizations.txt");
}
// 修改社团机构
void updateOrganization(char* name, char* new_name) {
FILE* fp1, *fp2;
char temp[1000];
fp1 = fopen("organizations.txt", "r");
fp2 = fopen("temp.txt", "w");
while(fgets(temp, 1000, fp1) != NULL) {
if(strstr(temp, name) != NULL) {
fprintf(fp2, "%s\n", new_name);
} else {
fprintf(fp2, "%s", temp);
}
}
fclose(fp1);
fclose(fp2);
remove("organizations.txt");
rename("temp.txt", "organizations.txt");
}
// 删除社团机构
void deleteOrganization(char* name) {
FILE* fp1, *fp2;
char temp[1000];
fp1 = fopen("organizations.txt", "r");
fp2 = fopen("temp.txt", "w");
while(fgets(temp, 1000, fp1) != NULL) {
if(strstr(temp, name) == NULL) {
fprintf(fp2, "%s", temp);
}
}
fclose(fp1);
fclose(fp2);
remove("organizations.txt");
rename("temp.txt", "organizations.txt");
}
// 查询社团机构
char* queryOrganization(char* name) {
FILE* fp;
char temp[1000];
char* org = malloc(500 * sizeof(char));
fp = fopen("organizations.txt", "r");
while(fgets(temp, 1000, fp) != NULL) {
if(strstr(temp, name) != NULL) {
strcpy(org, temp);
break;
}
}
fclose(fp);
return org;
}
```
最后,我们需要定义赞助商管理的结构体,如下所示:
```c
typedef struct {
char name[50]; // 赞助商名称
char industry[50]; // 行业
char contact[50]; // 联系人
char phone[20]; // 手机号码
char email[50]; // 电子邮件
} Sponsor;
```
然后,我们可以实现相关的增删改操作,如下所示:
```c
// 增加赞助商
void addSponsor(Sponsor sponsor) {
FILE* fp;
fp = fopen("sponsors.txt", "a+");
fprintf(fp, "%s,%s,%s,%s,%s\n", sponsor.name, sponsor.industry, sponsor.contact, sponsor.phone, sponsor.email);
fclose(fp);
}
// 删除赞助商
void deleteSponsor(char* name) {
FILE* fp1, *fp2;
char temp[1000];
fp1 = fopen("sponsors.txt", "r");
fp2 = fopen("temp.txt", "w");
while(fgets(temp, 1000, fp1) != NULL) {
if(strstr(temp, name) == NULL) {
fprintf(fp2, "%s", temp);
}
}
fclose(fp1);
fclose(fp2);
remove("sponsors.txt");
rename("temp.txt", "sponsors.txt");
}
// 修改赞助商信息
void updateSponsor(char* name, Sponsor sponsor) {
FILE* fp1, *fp2;
char temp[1000];
fp1 = fopen("sponsors.txt", "r");
fp2 = fopen("temp.txt", "w");
while(fgets(temp, 1000, fp1) != NULL) {
if(strstr(temp, name) == NULL) {
fprintf(fp2, "%s", temp);
} else {
fprintf(fp2, "%s,%s,%s,%s,%s\n", sponsor.name, sponsor.industry, sponsor.contact, sponsor.phone, sponsor.email);
}
}
fclose(fp1);
fclose(fp2);
remove("sponsors.txt");
rename("temp.txt", "sponsors.txt");
}
```
最后,我们需要将所有的数据保存在硬盘中。我们可以使用文件操作来实现数据的读写。例如,我们可以将社团基本信息保存在一个clubinfo.txt文件中,将组织机构管理的数据保存在一个members.txt文件中,将赞助商管理的数据保存在一个sponsors.txt文件中,将社团机构数据保存在一个organizations.txt文件中。
这样,我们就可以实现一个包含社团基本信息、组织机构管理和赞助商管理的系统,支持增删改查等操作,并且将数据保存在硬盘中。