| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 421 人关注过本帖
标题:请问大家一下这个C++程序改成C是什么样的...
只看楼主 加入收藏
Muya
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-9-19
收藏
 问题点数:0 回复次数:1 
请问大家一下这个C++程序改成C是什么样的...

#include <iostream>
#include <fstream>
#define FILENAME "data.txt"
using namespace std;

struct Teacher
{
char no[11]; /*编号*/
char name[15]; /*姓名*/
char sex[5]; /*性别*/
char profess[10]; /*职称*/
char dept[15]; /*部门*/
char leason[15]; /*课程*/
float workload; /*工作量*/
float lessonf;/*代课费*/
Teacher *next; /*指向后续结点的指针*/
};

Teacher *f, *l;

void printMenu();
void addNode();
void searchNode();
void deleteNode();
void listNode();
void printNode(Teacher *no);
void saveNode();
void loadNode();

void main()
{
int job;
bool cirFlag = true;
f = l = NULL;
loadNode();
while (cirFlag)
{
printMenu();
cin>>job;
cout<<"---------------"<<endl;
switch (job)
{
case 1:
addNode();
break;
case 2:
searchNode();
break;
case 3:
deleteNode();
break;
case 4:
listNode();
break;
case 5:
saveNode();
break;
case 6:
cirFlag = false;
break;
}
}
}

void printMenu()
{
cout<<"1. 创建"<<endl
<<"2. 查找"<<endl
<<"3. 删除"<<endl
<<"4. 显示所有"<<endl
<<"5. 保存"<<endl
<<"6. 退出"<<endl
<<"选择:";
}

void addNode()
{
Teacher *no;
no = new Teacher;
cout<<"编号:";
cin>>no->no;
cout<<"姓名:";
cin>>no->name;
cout<<"性别:";
cin>>no->sex;
cout<<"职称:";
cin>>no->profess;
cout<<"部门:";
cin>>no->dept;
cout<<"课程:";
cin>>no->leason;
cout<<"工作量:";
cin>>no->workload;
cout<<"代课费:";
cin>>no->lessonf;
no->next = NULL;
if (f)
{
l = l->next = no;
} else f = l = no;
}

void searchNode()
{
Teacher *no;
char sno[11];
int count = 5;
bool searchFlag = false;
cout<<"请输入要查找的教师编号:";
cin>>sno;
no = f;
while (no)
{
if (strcmp(no->no, sno) == 0)
{
searchFlag = true;
printNode(no);
count--;
if (!count)
{
system("pause");
count = 5;
cout<<"---------------"<<endl;
}
}
no = no->next;
}
if (!searchFlag)
cout<<"没有找到记录"<<endl;
}

void deleteNode()
{
Teacher *no, *pre;
char sno[11];
int count = 0;
cout<<"请输入要删除的教师编号:";
cin>>sno;
no = pre = f;
while (no)
{
if (strcmp(no->no, sno) == 0)
{
if (no == f)
f = no->next;
pre->next = no->next;
count++;
}
pre = no;
no = no->next;
}
cout<<"共删除 "<<count<<" 条记录"<<endl;
}

void listNode()
{
if (!f)
{
cout<<"没有找到记录。"<<endl;
return;
}
int count = 5;
Teacher *no;
no = f;
while (no)
{
printNode(no);
count--;
if (!count)
{
system("pause");
count = 5;
cout<<"---------------"<<endl;
}
no = no->next;
}
}

void printNode(Teacher *no)
{
cout<<"编号:"<<no->no<<endl
<<"姓名:"<<no->name<<endl
<<"性别:"<<no->sex<<endl
<<"职称:"<<no->profess<<endl
<<"部门:"<<no->dept<<endl
<<"课程:"<<no->leason<<endl
<<"工作量:"<<no->workload<<endl
<<"代课费:"<<no->lessonf<<endl
<<"---------------"<<endl;
}

void saveNode()
{
fstream fs(FILENAME, ios::out);
Teacher *no;
no = f;
while (no)
{
fs<<no->no<<endl
<<no->name<<endl
<<no->sex<<endl
<<no->profess<<endl
<<no->dept<<endl
<<no->leason<<endl
<<no->workload<<endl
<<no->lessonf<<endl;
no = no->next;
}
fs.close();
}

void loadNode()
{
fstream fs(FILENAME, ios::in);
Teacher *no;
int count = 0;
no = new Teacher;
while (fs>>no->no)
{
count++;
fs>>no->name
>>no->sex
>>no->profess
>>no->dept
>>no->leason
>>no->workload
>>no->lessonf;
no->next = NULL;
if (f)
{
l = l->next = no;
} else f = l = no;
no = new Teacher;
}
delete no;
fs.close();
cout<<"共加载 "<<count<<" 条记录"<<endl
<<"---------------"<<endl;
}

搜索更多相关主题的帖子: void Teacher float 
2007-09-20 19:35
夜火
Rank: 1
等 级:新手上路
帖 子:149
专家分:0
注 册:2007-5-30
收藏
得分:0 
又是来做 作业 的 ?

2007-09-20 19:41
快速回复:请问大家一下这个C++程序改成C是什么样的...
数据加载中...
 
   



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

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