当前位置:编程学习 > C/C++ >>

一个很麻烦的C语言编程,高手进来帮帮忙

1. 有一个文件存放职工的数据。每个职工的数据包括:职工号、姓名、性别、年龄和工资。编写实现如下功能的程序,每个程序可以单独运行:

① 根据用户的输入 建立 文件;

② 在文件末尾追加一个新职工记录;

③ 在用户指定的记录号之前插入一个新职工记录;

④ 根据用户输入的职工号和对应的数据修改该职工的数据;

⑤ 根据用户输入的职工号删除该职工的数据;

⑥ 根据用户输入的工资,显示大于该工资的职工的所有信息。

补充:我要完整的程序,完整编写出来的,一定好好感谢,再追加50分.
追问:额,我运行以后出现错误了,提示如下:

001.obj : error LNK2001: unresolved external symbol "bool __cdecl WriteFile(void)" (?WriteFile@@YA_NXZ)
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/jjj.exe : fatal error LNK1120: 2 unresolved externals
执行 link.exe 时出错.

这是怎么回事啊?先谢谢你了哦

答案:#include <iostream>
#include <fstream>
#include <process.h>

using namespace std;

typedef struct INFO
{
char no[11]; /* 职工号 */
char name[11]; /* 姓名 */
char 易做图[3]; /* 性别 */
int age; /* 年龄 */
float wages; /* 工资 */
} INFO;

INFO *data;

string filePath = "c:/people.dat";
int length = 0;
int maxSize = 50;
bool createFile = false;

bool ReadFile();
bool WriteFile();
bool AddItem(INFO&, bool);
bool InsertItem(INFO&, char *, bool);
bool ModifyItem(INFO&, int);
bool DeleteItem(int);
int InquiryItem(float, char *, int);

void displayMenu()
{
system("cls");
printf("|---------------------------|\n");
printf("| 输入1 建立文件 |\n");
printf("| 输入2 追加记录 |\n");
printf("| 输入3 插入记录 |\n");
printf("| 输入4 修改记录 |\n");
printf("| 输入5 删除记录 |\n");
printf("| 输入6 查询记录 |\n");
printf("| 输入7 退出 |\n");
printf("|---------------------------|\n");
}

/* 查询商品信息 */
int InquiryItem(float wages, char *no, int flag)
{
int i;
int count = 0;

if (flag == 1)
{
for (i = 0; i < length; i++)
{
if ((data + i)->wages > wages)
{

cout << "编号" << " " << "姓名" << " " << "性别" << " "
<< "年龄" << " " << "工资" << " " << endl;
cout << (data + i)->no << " " << (data + i)->name << " "
<< (data + i)->易做图 << " " << (data + i)->age
<< " " << (data + i)->wages << endl;
count++;
}
}
if (count == 0)
{
cout << "没有大于此工资的人" << endl;
}
}
else
{
for (i = 0; i < length; i++)
{
if (strcmp((data + i)->no, no) == 0)
{
return i;
}
}
}

return -1;
}

/* 重新分配内存 */
bool reAlloc()
{
int i;
INFO *newBase = NULL;

newBase = new INFO[maxSize * 2];
if (newBase == NULL) return false;
maxSize = maxSize * 2;
for (i = 0; i < maxSize/2; i++)
{
strcpy((newBase + i)->no, (data + i)->no);
strcpy((newBase + i)->name, (data + i)->name);
strcpy((newBase + i)->易做图, (data + i)->易做图);
(newBase + i)->age = (data + i)->age;
(newBase + i)->wages = (data + i)->wages;
}
delete [] data;
data = NULL;
data = newBase;

return true;
}

/* 增加商品信息 */
bool AddItem(INFO& info, bool isWrite = true)
{
if (length == maxSize)
{
reAlloc();
}

strcpy((data + length)->no, info.no);
strcpy((data + length)->name, info.name);
strcpy((data + length)->易做图, info.易做图);
(data + length)->age = info.age;
(data + length)->wages = info.wages;
length++;

if (isWrite)
return WriteFile();
else
return true;
}

/* 修改商品信息 */
bool ModifyItem(INFO& info, int pos)
{
strcpy((data + pos)->no, info.no);
strcpy((data + pos)->name, info.name);
strcpy((data + pos)->易做图, info.易做图);
(data + pos)->age = info.age;
(data + pos)->wages = info.wages;

return WriteFile();
}

真的好麻烦,去google一个交差吧。
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
int n;
int main()
{ int num[1000],wage[1000];
string name[1000],edu[1000],sec[1000],add[1000],tel[1000],age[1000];
void set(int *a,string *b,string *c,string *d,string *e,int*f,string *g,string *h);
void interview(int *a,string *b,string *c,string*d,string *e,int*f,string *g,string *h);
void check(int *a,string *b,string *c,string *d,string *e,int*f,string *g,string *h);
void sor(int *a,string *b,string *c,string *d,string *e,int*f,string *g,string *h);
void del(int *a,string *b,string *c,string *d,string *e,int*f,string *g,string *h);
void cha(int *a,string *b,string *c,string *d,string *e,int*f,string *g,string *h);
void sta(int *a,string *b,string *c,string *d,string *e,int*f,string *g,string *h);
void insert(int *a,string *b,string *c,string *d,string *e,int*f,string *g,string *h);
void read(int *a,string *b,string *c,string *d,string *e,int*f,string *g,string *h);
cout<<" ★欢迎使用职工信息管理系统★"<<endl<<endl;
cout<<"请输入本单位有多少职工:"<<endl;
cin>>n;
for(int i=1;i++;)
{
int m;
cout<<" 请选择菜单功能:"<<endl;
cout<<"输入请按1"<<endl;
cout<<"浏览请按2"<<endl;
cout<<"查询请按3"<<endl;
cout<<"排序请按4"<<endl;
cout<<"删除请按5"<<endl;
cout<<"修改请按6"<<endl;
cout<<"统计请按8"<<endl;
cout<<"添加请按7"<<endl;
cout<<"退出请按0"<<endl;cin>>m;
if(m==1)
{set(num,name,sec,age,edu,wage,add,tel);
}
if(m==2)
{
read(num,name,sec,age,edu,wage,add,tel);
interview(num,name,sec,age,edu,wage,add,tel);
}
if(m==3)
{
read(num,name,sec,age,edu,wage,add,tel);
check(num,name,sec,age,edu,wage,add,tel);
}
if(m==4)
{
read(num,name,sec,age,edu,wage,add,tel);
sor(num,name,sec,age,edu,wage,add,tel);
}
if(m==5)
{
read(num,name,sec,age,edu,wage,add,tel);
del(num,name,sec,age,edu,wage,add,tel);
}
if(m==6)
{
read(num,name,sec,age,edu,wage,add,tel);
cha(num,name,sec,age,edu,wage,add,tel);
}

if(m==8)
{
read(num,name,sec,age,edu,wage,add,tel);
sta(num,name,sec,age,edu,wage,add,tel);
}
if(m==7)
{
read(num,name,sec,age,edu,wage,add,tel);
insert(num,name,sec,age,edu,wage,add,tel);
}
if(m==0)break;
}
return 0;
}
//输入数值
void set(int *a,string *b,string *c,string *d,string *e,int *f,string *g,string *h)
{
ofstream outfile("fl.txt",ios::out);
if(! outfile)
{cerr<<"open error"<<endl;
exit(1);
}

for(int i=0;i<n;i++)
{
cout<<"请输入第"<<i+1<<"位职工的个人信息并按下面提示操作"<<endl;
cout<<"请输入第"<<i+1<<"位职工的职工号:";cin>>a[i];outfile<<a[i]<<" ";
cout<<"请输入第"<<i+1<<"位职工的姓名:";cin>>b[i];outfile<<b[i]<<" ";
cout<<"请输入第"<<i+1<<"位职工的性别:";cin>>c[i];outfile<<c[i]<<" ";
cout<<"请输入第"<<i+1<<"位职工的年龄:";cin>>d[i];outfile<<d[i]<<" ";
cout<<"请输入第"<<i+1<<"位职工的学历:";cin>>e[i];outfile<<e[i]<<" ";
cout<<"请输入第"<<i+1<<"位职工的工资:";cin>>f[i];outfile<<f[i]<<" ";
cout<<"请输入第"<<i+1<<"位职工的地址:";cin>>g[i];outfile<<g[i]<<" "; <

上一个:我想学习C语言 学它以前先用不用学什么啊?
下一个:c语言 链表是什么。书上的没看太懂

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,