| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 265 人关注过本帖
标题:谁能帮我解决下面的代码,问题:我打开文件夹中的文件看不到我要输进去全部 ...
只看楼主 加入收藏
kkooo858
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-4-25
收藏
 问题点数:0 回复次数:0 
谁能帮我解决下面的代码,问题:我打开文件夹中的文件看不到我要输进去全部的数据,只看到一个。谁知道怎么用文件的输出吗?
#include<fstream.h>
#include <iostream.h>
#include <string.h>
#define N 10000

struct Company
{
    char name[10];
    double num;//编号
   
    char position[20];//职称
    int age;//年龄
    int gage;//工龄
    double salary;//各职的薪水
    double jiangjin;//年奖金
    char tele[20];//联系方式1电话号码
   
   
   
};
Company tea[N];
char user[]="3g";//用户名
char password[]="123";//密码
//数据初始化
void cin1()
{
    strcpy(tea[0].name,0);
    tea[0].num=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);


}
void jiemian()
{
   cout<<"               ** *** **               "<<endl;
        cout<<"           ** *** *** *** **           "<<endl;
        cout<<"      *** *** *** *** *** *** ***      "<<endl;
        cout<<"      欢迎使用高校职工信息管理系统     "<<endl;
        cout<<"  **                               **  "<<endl;
        cout<<"**              菜单选项             **"<<endl;
        cout<<"*=====================================*"<<endl;
        cout<<"*              (1)添加职工            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (2)查找职工            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (3)所有职工            *"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*-------------------------------------*"<<endl;
        cout<<"*              (0)退出程序            *"<<endl;
        cout<<"*=====================================*"<<endl;
}
//添加信息


void Add(int n)
{
//接受数据
    int i;
    char fliename[80];
    if(n<=N)
    {
        
        for(i=1;i<=n;i++)
        {
            ofstream ofs(" test.txt");
            
            cout<<"请输入您的姓名(中间不能有空格): ";
            cin>>tea[i].name;
            ofs<<tea[i].name<<'\n';
            
            cout<<"请输入您的编号:";
            cin>>tea[i].num;
            ofs<<tea[i].num<<'\n';
            cout<<"请输入您的职务(只能用英文,且用小写):"<<endl;
            cout<<"总裁(CEO)"<<endl;
            cout<<"副总裁(Deputy governor)"<<endl;
            cout<<"经理(Chief manager)"<<endl;
            cout<<"辅导员(fudaoyuan)"<<endl;
            cin>>tea[i].position;
            ofs<<tea[i].position<<'\n';
            cout<<"请输入您的年龄:";
            cin>>tea[i].age;
            ofs<<tea[i].age<<'\n';
            cout<<"请输入您的工龄: ";
            cin>>tea[i].gage;
            ofs<<tea[i].gage<<'\n';
            cout<<"请输入您的工资: ";
            cin>>tea[i].salary;//tea[i].salary=Count_salary();
            ofs<<tea[i].salary<<'\n';
            cout<<"请输入您的奖金: ";
            cin>>tea[i].jiangjin;
            ofs<<tea[i].jiangjin<<'\n';
            cout<<"请输入您的电话号码: ";
            cin>>tea[i].tele;
            ofs<<tea[i].tele<<'\n';
            
                    ofs.close();
               
            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].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;

    }
}
//查找职工
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].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;
   
        }
        break;
    }

}
//主函数
int main()
{
    char user1[15];
    char password1[15];
    int totalItems=0;
    int M=3;//输入次数

    cout<<"请输入本程序的用户名(3g):"<<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<<"请输入本程序的密码(123):"<<endl;
    while(M>0)
    {
        cin>>password1;
        if(!strcmp(password,password1))//若输入的密码与密码相同
        {
            cout<<"恭喜您,登陆成功!"<<endl;
            break;
        }
        else
        {
            cout<<"您输入的密码错误,您还有"<<--M<<"次输入机会!"<<endl;
        }
    }
    if(M)
    {
        cout<<"谢谢使用本程序----某500强公司的职工信息管理系统!"<<endl;
        cout<<"本程序由10 3G班 李奕  编写"<<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 3:
            {
//                int n;
                Displaytea(totalItems);//全部显示
                break;
            }
        case 2:
            {
//                int n;
                search(totalItems);//查找
                break;
            }
        case 0:
            break;

        }
//return o;
}
}
搜索更多相关主题的帖子: password position 联系方式 include 用户名 
2011-04-25 12:38
快速回复:谁能帮我解决下面的代码,问题:我打开文件夹中的文件看不到我要输进去 ...
数据加载中...
 
   



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

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