| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 876 人关注过本帖, 1 人收藏
标题:急!!!这个程序当运行(4)查找时显示不出信息。希望有人帮帮忙...
只看楼主 加入收藏
smallpin
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-5-27
结帖率:0
收藏(1)
已结贴  问题点数:20 回复次数:8 
急!!!这个程序当运行(4)查找时显示不出信息。希望有人帮帮忙...
#include "iostream"
#include "string"
#define N 10000
using namespace std;
struct teacher
{
    char name[10];//教师姓名
    double num;//教师编号
    char gender[10];//教师性别
    char position[20];//教师职称
    int age;//教师年龄
    int gage;//工龄
    double salary;//各职称教师的薪水
    double jiangjin;//教师的年奖金
    char tele[20];//教师联系方式1电话号码
    char email[20];//教师联系方式2QQ
    char add[15];// 教师住址
   
};
teacher tea[N];
char user[]="xbjqcf";//用户名
char password[]="09080121719";//密码
//数据初始化
void cin1()
{
    strcpy(tea[0].name,0);
    tea[0].num=0;
    strcpy(tea[0].gender,0);
    strcpy(tea[0].position,0);
    tea[0].age=0;
    tea[0].gage=0;
    tea[0].salary=0;
    tea[0].jiangjin=0;
    strcpy(tea[0].tele,0);
    strcpy(tea[0].email,0);
    strcpy(tea[0].add,0);
}
void jiemian()
{
   cout<<"               ** *** **               "<<endl;
        cout<<"           ** *** *** *** **           "<<endl;
        cout<<"      *** *** *** *** *** *** ***      "<<endl;
        cout<<"      欢迎使用高校职工信息管理系统     "<<endl;
        cout<<"  **                               **  "<<endl;
        cout<<"**              菜单选项             **"<<endl;
        cout<<"*=====================================*"<<endl;
        cout<<"*              (1)添加职工            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (2)修改信息            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (3)删除信息            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (4)查找职工            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (5)所有职工            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (6)保存文件            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (0)退出程序            *"<<endl;
        cout<<"*=====================================*"<<endl;
}
//添加信息
void Add(int n)
{
//接受数据
    int i;
    if(n<=N)
    {
        
        for(i=1;i<=n;i++)
        {
            cout<<"请输入您的姓名(中间不能有空格): ";
            cin>>tea[i].name;
            cout<<"请输入您的编号:";
            cin>>tea[i].num;
            cout<<"请输入您的性别:";
            cin>>tea[i].gender;
            cout<<"请输入您的职务(只能用英文,且用小写):"<<endl;
            cout<<"校长(principal)"<<endl;
            cout<<"副校长(Vice President)"<<endl;
            cout<<"系主任(xizhuren)"<<endl;
            cout<<"辅导员(fudaoyuan)"<<endl;
            cin>>tea[i].position;
            cout<<"请输入您的年龄:";
            cin>>tea[i].age;
            cout<<"请输入您的工龄: ";
            cin>>tea[i].gage;
            cout<<"请输入您的工资: ";
            cin>>tea[i].salary;//tea[i].salary=Count_salary();
            cout<<"请输入您的奖金: ";
            cin>>tea[i].jiangjin;
            cout<<"请输入您的号码: ";
            cin>>tea[i].tele;
            cout<<"请输入您的邮箱号: ";
            cin>>tea[i].email;
            cout<< "请输入您的地址: ";
            cin>>tea[i].add;
            cout<<"保存成功!"<<endl;
    }
    }
}
//显示我们注册的所有职工的全部信息
void Displaytea(int n)
{
    int i;
    for(i=1;i<=n;i++)
    {
        cout<<tea[i].name<<endl;
        cout<<tea[i].num<<endl;
        cout<<tea[i].gender<<endl;
        cout<<tea[i].position<<endl;
        cout<<tea[i].age<<endl;
        cout<<tea[i].gage<<endl;
        cout<<tea[i].salary<<endl;
        cout<<tea[i].jiangjin<<endl;
        cout<<tea[i].tele<<endl;
        cout<<tea[i].email<<endl;
        cout<<tea[i].add<<endl;
    }
}
//查找职工
void search(int n)
{
    int i;
    double num;
    cout<<"请输入您要查找的编号: " ;
    cin>>num;
    for(i=1;i<=n;i++)
    {
        if(tea[i].num==num)
        {
            cout<<"姓名: ";
            cout<<tea[i].name<<endl;
            cout<<tea[i].num<<endl;
            cout<<tea[i].gender<<endl;
            cout<<tea[i].position<<endl;
            cout<<tea[i].age<<endl;
            cout<<tea[i].gage<<endl;
            cout<<tea[i].salary<<endl;
            cout<<tea[i].jiangjin<<endl;
            cout<<tea[i].tele<<endl;
            cout<<tea[i].email<<endl;
            cout<<tea[i].add<<endl;
        }
        break;
    }

}
//主函数
int main()
{
       char user1[15];
    char password1[15];
    int M=3;//输入次数
    cout<<"请输入本程序的用户名:"<<endl;
    while(M>0)
    {
        cin>>user1;
        if(!strcmp(user,user1))//若输入与用户名相同
        {
            cout<<"用户名正确!"<<endl;
            M=3;//防止输入密码时flag不为3
            break;
        }
        else
        {
            cout<<"用户名错误,您还有"<<--M<<"次输入机会!"<<endl;
        }
    }
    if(M<0)
    {
        cout<<"对不起,您输入三次错误,本程序将自动退出!"<<endl;
        return (-1);//中断跳出
    }
    cout<<"请输入本程序的密码:"<<endl;
    while(M>0)
    {
        cin>>password1;
        if(!strcmp(password,password1))//若输入的密码与密码相同
        {
            cout<<"恭喜您,登陆成功!"<<endl;
            break;
        }
        else
        {
            cout<<"您输入的密码错误,您还有"<<--M<<"次输入机会!"<<endl;
        }
    }
    if(M)
    {
        cout<<"谢谢使用本程序----高校职工信息管理系统!"<<endl;
        cout<<"本程序由09 计师本2班 许碧君 丘程芳  编写"<<endl;
        cout<<endl<<endl<<endl;
    }
    else
    {
        cout<<"对不起,您三次输错,本程序将自动退出!"<<endl;
        return (-1);//中断跳出
    }

    while(1)
    {
        int choice;

        jiemian();
        cout<<"请输入您要选择的菜单选项(请输入数字):";
        cin>>choice;
        switch(choice)
        {
        case 1:
            {
                 int n;
                 cout<<"请输入您想要添加的职工个数:";
                 cin>>n;
                Add(n);//注册职工
                break;
            }
        case 5:
            {
                int n;
                Displaytea(n);//全部显示
                break;
            }
        case 4:
            {
                int n;
                search(n);//查找
                break;
            }
        }
    //return 0;
}
}
搜索更多相关主题的帖子: 运行 
2010-05-27 15:46
最近不在
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:5
帖 子:204
专家分:842
注 册:2010-2-28
收藏
得分:4 
程序代码:
// Note:Your choice is C++ IDE
#include <iostream>

jiemian();   //这个不要写在while里,每次执行完,都弹出这个不爽。
//system("pause");   暂停
//system("cls");  确定后清屏
//jiemian();   调出帮助菜单
while(1)
    {
        int choice;
        cout<<"请输入您要选择的菜单选项(请输入数字):";
        cin>>choice;
        switch(choice)
        {
        case 1:
            {
                 int n;
                 cout<<"请输入您想要添加的职工个数:";
                 cin>>n;
                Add(n);//注册职工
                 break;
            }
           
        case 5:
            {
                //这里n应该为保存的人员长度。因此在某个地方,你需要写个全局变量用于保存数据长度
                Displaytea(n);//全部显示  
                break;      
            }
           
        case 4:
            {
               int n;
                cin>>n;  //漏了
                search(n);//查找
              break;
            }
             
        }
    //return 0;
    }

 //另外你的输出,和查找都显示信息,应提取一个基本信息函数
2010-05-27 18:34
hzh512
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:6
帖 子:234
专家分:1333
注 册:2009-6-5
收藏
得分:4 
程序需要一个变量,能记录你目前存储有多少人(totalItems)
#include "iostream"
#include "string"
#define N 10000
using namespace std;
struct teacher
{
    char name[10];//教师姓名
    double num;//教师编号
    char gender[10];//教师性别
    char position[20];//教师职称
    int age;//教师年龄
    int gage;//工龄
    double salary;//各职称教师的薪水
    double jiangjin;//教师的年奖金
    char tele[20];//教师联系方式1电话号码
    char email[20];//教师联系方式2QQ
    char add[15];// 教师住址
   
};
teacher tea[N];
char user[]="xbjqcf";//用户名
char password[]="09080121719";//密码
//数据初始化
void cin1()
{
    strcpy(tea[0].name,0);
    tea[0].num=0;
    strcpy(tea[0].gender,0);
    strcpy(tea[0].position,0);
    tea[0].age=0;
    tea[0].gage=0;
    tea[0].salary=0;
    tea[0].jiangjin=0;
    strcpy(tea[0].tele,0);
    strcpy(tea[0].email,0);
    strcpy(tea[0].add,0);
}
void jiemian()
{
   cout<<"               ** *** **               "<<endl;
        cout<<"           ** *** *** *** **           "<<endl;
        cout<<"      *** *** *** *** *** *** ***      "<<endl;
        cout<<"      欢迎使用高校职工信息管理系统     "<<endl;
        cout<<"  **                               **  "<<endl;
        cout<<"**              菜单选项             **"<<endl;
        cout<<"*=====================================*"<<endl;
        cout<<"*              (1)添加职工            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (2)修改信息            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (3)删除信息            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (4)查找职工            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (5)所有职工            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (6)保存文件            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (0)退出程序            *"<<endl;
        cout<<"*=====================================*"<<endl;
}
//添加信息
void Add(int n)
{
//接受数据
    int i;
    if(n<=N)
    {
        
        for(i=1;i<=n;i++)
        {
            cout<<"请输入您的姓名(中间不能有空格): ";
            cin>>tea[i].name;
            cout<<"请输入您的编号:";
            cin>>tea[i].num;
            cout<<"请输入您的性别:";
            cin>>tea[i].gender;
            cout<<"请输入您的职务(只能用英文,且用小写):"<<endl;
            cout<<"校长(principal)"<<endl;
            cout<<"副校长(Vice President)"<<endl;
            cout<<"系主任(xizhuren)"<<endl;
            cout<<"辅导员(fudaoyuan)"<<endl;
            cin>>tea[i].position;
            cout<<"请输入您的年龄:";
            cin>>tea[i].age;
            cout<<"请输入您的工龄: ";
            cin>>tea[i].gage;
            cout<<"请输入您的工资: ";
            cin>>tea[i].salary;//tea[i].salary=Count_salary();
            cout<<"请输入您的奖金: ";
            cin>>tea[i].jiangjin;
            cout<<"请输入您的号码: ";
            cin>>tea[i].tele;
            cout<<"请输入您的邮箱号: ";
            cin>>tea[i].email;
            cout<< "请输入您的地址: ";
            cin>>tea[i].add;
            cout<<"保存成功!"<<endl;
    }
    }
}
//显示我们注册的所有职工的全部信息
void Displaytea(int n)
{
    int i;
    for(i=1;i<=n;i++)
    {
        cout<<tea[i].name<<endl;
        cout<<tea[i].num<<endl;
        cout<<tea[i].gender<<endl;
        cout<<tea[i].position<<endl;
        cout<<tea[i].age<<endl;
        cout<<tea[i].gage<<endl;
        cout<<tea[i].salary<<endl;
        cout<<tea[i].jiangjin<<endl;
        cout<<tea[i].tele<<endl;
        cout<<tea[i].email<<endl;
        cout<<tea[i].add<<endl;
    }
}
//查找职工
void search(int n)
{
    int i;
    double num;
    cout<<"请输入您要查找的编号: " ;
    cin>>num;
    for(i=1;i<=n;i++)
    {
        if(tea[i].num==num)
        {
            cout<<"姓名: ";
            cout<<tea[i].name<<endl;
            cout<<tea[i].num<<endl;
            cout<<tea[i].gender<<endl;
            cout<<tea[i].position<<endl;
            cout<<tea[i].age<<endl;
            cout<<tea[i].gage<<endl;
            cout<<tea[i].salary<<endl;
            cout<<tea[i].jiangjin<<endl;
            cout<<tea[i].tele<<endl;
            cout<<tea[i].email<<endl;
            cout<<tea[i].add<<endl;
        }
        break;
    }

}
//主函数
int main()
{
    char user1[15];
    char password1[15];
    int totalItems=0;
    int M=3;//输入次数
    cout<<"请输入本程序的用户名:"<<endl;
    while(M>0)
    {
        cin>>user1;
        if(!strcmp(user,user1))//若输入与用户名相同
        {
            cout<<"用户名正确!"<<endl;
            M=3;//防止输入密码时flag不为3
            break;
        }
        else
        {
            cout<<"用户名错误,您还有"<<--M<<"次输入机会!"<<endl;
        }
    }
    if(M<0)
    {
        cout<<"对不起,您输入三次错误,本程序将自动退出!"<<endl;
        return (-1);//中断跳出
    }
    cout<<"请输入本程序的密码:"<<endl;
    while(M>0)
    {
        cin>>password1;
        if(!strcmp(password,password1))//若输入的密码与密码相同
        {
            cout<<"恭喜您,登陆成功!"<<endl;
            break;
        }
        else
        {
            cout<<"您输入的密码错误,您还有"<<--M<<"次输入机会!"<<endl;
        }
    }
    if(M)
    {
        cout<<"谢谢使用本程序----高校职工信息管理系统!"<<endl;
        cout<<"本程序由09 计师本2班 许碧君 丘程芳  编写"<<endl;
        cout<<endl<<endl<<endl;
    }
    else
    {
        cout<<"对不起,您三次输错,本程序将自动退出!"<<endl;
        return (-1);//中断跳出
    }

    while(1)
    {
        int choice;
        jiemian();
        cout<<"请输入您要选择的菜单选项(请输入数字):";
        cin>>choice;
        switch(choice)
        {
        case 1:
            {
                 int n;
                 cout<<"请输入您想要添加的职工个数:";
                 cin>>n;
                Add(n);//注册职工
                totalItems += n; // 删除时,要同步减
                break;
            }
        case 5:
            {
//                int n;
                Displaytea(totalItems);//全部显示
                break;
            }
        case 4:
            {
//                int n;
                search(totalItems);//查找
                break;
            }
        }
    //return 0;
}
}

编程=用几种语言在某个或几个平台上通过抽象思维运用一系列算法来解决现实中问题的手段
2010-05-27 18:42
smallpin
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-5-27
收藏
得分:0 
回复 2楼 最近不在
谢谢你的意见!
2010-05-27 20:08
smallpin
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-5-27
收藏
得分:0 
回复 3楼 hzh512
非常感谢!能够实现查询了,接下我还要自己去完成。
2010-05-27 20:19
风随风
Rank: 1
等 级:新手上路
帖 子:2
专家分:4
注 册:2009-10-18
收藏
得分:4 
//查找职工
void search(int n)
{
    int i;
    double num;
    cout<<"请输入您要查找的编号: " ;
    cin>>num;
    for(i=1;i<=n;i++)
    {
        if(tea[i].num==num)
        {
            cout<<"姓名: ";
            cout<<tea[i].name<<endl;
            cout<<tea[i].num<<endl;
            cout<<tea[i].gender<<endl;
            cout<<tea[i].position<<endl;
            cout<<tea[i].age<<endl;
            cout<<tea[i].gage<<endl;
            cout<<tea[i].salary<<endl;
            cout<<tea[i].jiangjin<<endl;
            cout<<tea[i].tele<<endl;
            cout<<tea[i].email<<endl;
            cout<<tea[i].add<<endl;
            break;    //break 不是要写在这吗  怎么都没发现??  在if外面的话 循环一次就退出了
        }
    }

}
2010-05-27 22:04
南国利剑
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:29
帖 子:1165
专家分:3536
注 册:2010-4-12
收藏
得分:4 
两位同事都来了。
说的不错!
顶!

南国利剑
2010-05-27 23:48
code_guy
Rank: 2
等 级:论坛游民
帖 子:28
专家分:33
注 册:2010-5-26
收藏
得分:4 
我晕  很少见这样写程序的啊
2010-05-28 20:02
smallpin
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-5-27
收藏
得分:0 
回复 8楼 code_guy
新手嘛!学的不是很深~~~~~~~
2010-05-28 23:13
快速回复:急!!!这个程序当运行(4)查找时显示不出信息。希望有人帮帮忙...
数据加载中...
 
   



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

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