用c语言程序写一个班级添加的程序

用C语言写一个班级添加的程序_百度知道
用C语言写一个班级添加的程序
已经设置过变量了void addclass() {
int i,f=0;
char pname[20];
printf(&请输入新班级名:&);
scanf(&%s&,pname);
for(i=0;i&x;i++)
if (strcmp(cla[i].bianhao, pname)==0)
printf(&已有此班级!&);
system(&pause&);
system(&cls&);
strcpy(cla[x].bianhao,pname);
cla[x].renshu = 0;
if ((fpp = fopen(&banji.txt&,&a+&)) == NULL)
printf(&打开文件错订处斥肺俪镀筹僧船吉误!&);
fwrite(&cla[x], sizeof(struct Class), 1, fp);
printf(&增加班级%s班成功!\n&, pname);
printf(&目前班级数:%d\n&, x);
fclose(fpp);
system(&pause&);
system(&cls&);
提问者采纳
程序写错了,调整如下:void addclass() {
int i,f=0;
char pname[20];
printf(&请输入新班级名:&);
scanf(&%s&,pname);
for(i=0;i&x;i++)//循环判断是否有重复项
if (strcmp(cla[i].bianhao, pname)==0)
printf(&已有此班级!&);
system(&pause&订处斥肺俪镀筹僧船吉);
system(&cls&);
//正常退出循环才表示新增班级为不重复班级,此时i==x
strcpy(cla[x].bianhao,pname);
cla[x].renshu = 0;
if ((fpp = fopen(&banji.txt&,&a+&)) == NULL)
printf(&打开文件错误!&);
fwrite(&cla[x], sizeof(struct Class), 1, fp);
printf(&增加班级%s班成功!\n&, pname);
printf(&目前班级数:%d\n&, x);
fclose(fpp);
system(&pause&);
system(&cls&);
提问者评价
来自团队:
其他类似问题
为您推荐:
c语言的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁做了一个班级相册的桌面程序_c语言吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:320,239贴子:
做了一个班级相册的桌面程序收藏
目前正在测试中,还有很多功能未完善
我也想做这么一个,是纯C吗???
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或无法显示此页
无法显示此页
您要访问的页面存在问题,因此无法显示。
请尝试以下操作:
请与网站管理员联系,通知他们此 URL 地址出现了该错误。
按钮或者梢候再试。
主页,然后查找与所需信息相关的链接。
如果本错误不是您有意造成的,并且多次刷新网页后仍如此
  请报告,联系电话:
HTTP 500.100 - 内部服务器错误:ASP 错误。Internet 信息服务编写一个c语言程序,统计一个班(最多50人)的学生成绩(在vc下编写)
[问题点数:20分,无满意结帖,结帖人weivs929]
编写一个c语言程序,统计一个班(最多50人)的学生成绩(在vc下编写)
[问题点数:20分,无满意结帖,结帖人weivs929]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2008年6月 C/C++大版内专家分月排行榜第二
2008年9月 C/C++大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。求C语言的程序设计,班级通讯录的设计与实现?
求C语言的程序设计,班级通讯录的设计与实现?
09-10-19 & 发布
这个不用发信响了,能放下,已经编译运行确认了:#include&conio.h& #include&stdio.h&
#include &iostream&#include &string&#include &iomanip&#include &fstream&#include &cstdlib&class book{public:    book();//默认构造函数    char inter_face();//首页    void add_person();//添加联系人    void del_person();//删除联系人    void show_all();//显示所有联系人    void alter();//修改信息    void select();//查询联系人    void save_new();//保存新增加的联系人private:    //姓名    //地址    //电话号码    //邮编    //QQ号};struct record{    //双向链表中的数据域是是一个记录类    record *//指向前躯    record *//指向后继};book::book(){    name = &\0&;    address = &\0&;    number = &\0&;    post = &\0&;    qq = &\0&;}//首页char book::inter_face(){    system(&cls&);        cout &&    cout&&&\t\t★★★★★★★★★★★★★★★★★★★★★★★★★★& &&endl        &&&\t\t※                                                ※& &&endl        &&&\t\t※             班  级  通  迅   录                ※& &&endl
       &&&\t\t※                                                ※& &&endl        &&&\t\t※      1. 添加新联系人.      4. 修改信息.        ※& &&endl
       &&&\t\t※                                                ※& &&endl        &&&\t\t※      2. 删除联系人.        5. 查询联系人.      ※& &&endl        &&&\t\t※                                                ※& &&endl        &&&\t\t※      3. 显示所有联系人.    6. 关闭通迅录.      ※& &&endl
       &&&\t\t※                                                ※& &&endl        &&&\t\t★★★★★★★★★★★★★★★★★★★★★★★★★★& &&endl &&endl        &&&\t\t\t选择 :& ;            cin &&    fflush(stdin);        }//添加联系人void book::add_person(){    cout &&endl &&&根据下面提示输入新联系人信息& &&endl &&endl        &&&姓名 :& ;    cin &&    fflush(stdin);    cout &&&电话 : &;    cin &&    fflush(stdin);    cout &&&QQ   : &;    cin &&    fflush(stdin);    cout &&&邮编 : &;    cin &&    fflush(stdin);    cout &&&地址 : &;    cin &&    fflush(stdin);        save_new();        cout &&endl &&endl &&&新联系人信息已经保存好!!!!!& &&endl &&    system(&pause&);}//删除联系人void book::del_person(){    ofstream outData(&temp.txt&, ios::out);    ifstream inData(&pbook.txt&, ios::in);        if (!outData || !inData)    {        cout &&endl &&&对不起!!!!找不到文件!!!!& &&        system(&pause&);            }            cout &&endl &&&你要删除输入姓名或电话号 :&;    cin &&    string str1;    bool flag =            while (inData &&name &&number)    {        getline(inData, str);                if ((sign==name) || (sign==number))        {            cout &&endl &&&你想删除的联系人:& &&endl &&            cout &&str1 &&            cout &&setiosflags(ios::left) &&setw(17) &&name                &&& & &&number &&str &&            flag =                    }                outData &&setiosflags(ios::left) &&setw(17) &&name            &&& & &&number &&str &&    }        if (flag)    {        cout &&endl &&&对不起!!!联系人中没你找的人!!!!& &&endl &&    }    else    {        while (getline(inData, str))        {            outData &&str &&        }                outData.close();        inData.close();                ofstream out(&pbook.txt&, ios::out);        ifstream in(&temp.txt&, ios::in);                if (!out || !in)        {            cout &&endl &&&对不起不能打开文件!!!& &&endl &&            system(&pause&);                    }                while (getline(in, str))        {            out &&str &&        }                out.close();        in.close();        cout &&endl &&&这个人的信息已经从你的通迅录中删除!!!& &&endl &&    }        system(&pause&);    }//显示所有联系人void book::show_all(){    ifstream inData(&pbook.txt&,ios::in);            if (!inData)    {        cout &&endl &&&对不起!!!!没有找到文件!!!!!& &&        system(&pause&);            }        bool flag =            while (getline(inData, record))    {        if (flag)        {            cout &&endl &&&所有联系人信息如下: &&&        }        cout &&record &&        flag =    }        if (flag)    {        cout &&endl &&&你的通迅录中没有联系人!!!!!& &&endl &&    }    else    {        cout &&endl &&&所有联系人已经全部显示出来!!!!!& &&endl &&    }        system(&pause&);}//修改信息void book::alter(){    ifstream inData(&pbook.txt&, ios::in);        if (!inData)    {        cout &&endl &&&对不起不能打开文件!!!!!& &&endl &&        system(&pause&);            }            cout &&endl &&&请输入你想要修改的联系人的姓名或电话号码 :&;    cin &&    fflush(stdin);        string str1;    getline(inData, str1);        record *H =    record *p = H;    record *q = H;    bool flag =        while (inData &&p-& &&p-&object.number &&p-&object.qq        &&p-&object.post &&p-&object.address)    {        p-&next =        p = p-&        p-&prior =        q-&next =        q =    }    p-&next = NULL;        inData.close();        p = H;    while (p)    {        if ((p-&==sign) || (p-&object.number==sign))        {            if (flag)            {                cout &&endl &&&你想修改你联系人的信息如下: & &&endl &&                cout &&endl &&str1 &&                cout &&setiosflags(ios::left) &&setw(17)                    &&p-& &&& & &&setw(16) &&p-&object.number                    &&& & &&setw(18) &&p-&object.qq
                   &&& & &&setw(14) &&p-&object.post
                   &&& & &&setw(20) &&p-&object.address &&                flag =            }            cout &&endl &&&请根据下面提示修改信息 : & &&            cout &&&姓名  :& ;            cin &&p-&;            fflush(stdin);            cout &&&电话号:&;            cin &&p-&object.            fflush(stdin);            cout &&&QQ    :&;            cin &&p-&object.            fflush(stdin);            cout &&&邮编  :&;            cin &&p-&object.            fflush(stdin);            cout &&&地址  :&;            cin &&p-&object.            fflush(stdin);                    }                p = p-&    }        if (flag)    {        cout &&endl &&&你的通迅录中没有你找的联系人!!!!& &&endl &&        system(&pause&);            }    else    {        ofstream out(&pbook.txt&,ios::out);                if (!out)        {            cout &&endl &&&对不起!!!不能打开文件!!!!& &&            system(&pause&);                    }                out &&str1 &&        p = H-&        while (p)        {            out &&setiosflags(ios::left) &&setw(17) &&p-&
               &&& & &&setw(16) &&p-&object.number
               &&& & &&setw(18) &&p-&object.qq                &&& & &&setw(14) &&p-&object.post                &&& & &&setw(20) &&p-&object.address &&            p = p-&        }                out.close();        cout &&endl &&&信息已经修改完成!!!!& &&endl &&        system(&pause&);    }}//查询联系人void book::select(){    ifstream inData(&pbook.txt&,ios::in);        if (!inData)    {        cout &&endl &&&对不起!!!!文件找不到!!!!& &&        system(&pause&);            }            cout &&endl &&&输入你想查找的联系人的姓名或电话号码: &;    cin &&    fflush(stdin);        string str1;    bool flag =            while (inData &&name &&number)    {        getline(inData, str);                if ((name==sign) || (number==sign))        {            cout &&endl &&&你要查找的联系人是: & &&endl &&            cout &&str1 &&            cout &&setiosflags(ios::left) &&setw(17) &&name                &&number &&str &&            flag =                    }    }}void book::save_new(){    ofstream outData(&pbook.txt&, ios::app);    if (!outData)    {        cout &&endl &&&对不起!!!打开文件失败!!!!& &&endl &&        system(&pause&);            }
   outData && setiosflags(ios::left) && setw(17) && name        &&& & && setw(16) && number &&& &        && setw(18) && qq &&& &        && setw(14) && post &&& &        && setw(20) && address &&        outData.close();}enum power{ADD = '1', DEL = '2', SHOW = '3', Alter = '4', Select = '5', END = '6'};int main(){                while (choose = abj.inter_face())    {        switch (choose)        {        case ADD:            abj.add_person();////添加联系人                    case DEL:            abj.del_person();////删除联系人                    case SHOW:            abj.show_all();////显示所有联系人                    case Alter:            abj.alter();////修改信息                    case Select:            abj.select();////查询联系人                    case END:            cout &&endl &&&谢谢使用!!!!!& &&endl &&            exit(0);                    default:                    }    }    return 0;}
请登录后再发表评论!

我要回帖

更多关于 c语言程序设计 谭浩强 的文章

 

随机推荐