| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 669 人关注过本帖
标题:这个程序编译能通过,但是运行后,在D盘建立的TXT文档是空的。没有预期输入 ...
只看楼主 加入收藏
yy21drd
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2011-11-2
结帖率:33.33%
收藏
已结贴  问题点数:5 回复次数:3 
这个程序编译能通过,但是运行后,在D盘建立的TXT文档是空的。没有预期输入的数据
如题,希望大家帮下忙;
#include <iostream>
#include <fstream>
#include <ostream>
using namespace std;
class cstudent
{
    private:
        int num;            //学号
        char name[3];        //姓名
        char sex;            //性别,男为M,女为F
        int age;            //年龄
        int mscore;            //数学成绩
        int cscore;            //计算机成绩
        int escore;            //英语成绩
        float ascore;        //平均成绩
        float all;            //总成绩
    public:
        void get();                        //从文件中读取学生信息
        void send();                    //向文件中输入学生信息
        void output1();                    //输出信息
        void fun();                        //计算平均成绩和总成绩
void input();                    //输入数据
        
};ofstream outfile;
ifstream infile;

void cstudent::fun()
{   
    all=mscore+cscore+escore;cout<<"总成绩:"<<all<<endl;
    ascore=all/3;cout<<"平均成绩:"<<ascore<<endl;
}

void cstudent::send()
{

    outfile<<"学号:";            outfile<<num;        outfile<<endl;
    outfile<<"姓名:";            outfile<<name;        outfile<<endl;
    outfile<<"性别:";            outfile<<sex;        outfile<<endl;
    outfile<<"年龄:";            outfile<<age;        outfile<<endl;
    outfile<<"数学成绩:";        outfile<<mscore;    outfile<<endl;
    outfile<<"计算机成绩:";        outfile<<cscore;    outfile<<endl;
    outfile<<"英语成绩:";        outfile<<escore;    outfile<<endl;
    outfile<<endl;
}

void cstudent::output1()
{
    cout<<"学号:";            cout<<num;        cout<<endl;
    cout<<"姓名:";            cout<<name;    cout<<endl;
    cout<<"性别:";            cout<<sex;        cout<<endl;
    cout<<"年龄:";            cout<<age;        cout<<endl;
    cout<<"数学成绩:";            cout<<mscore;    cout<<endl;
    cout<<"计算机成绩:";            cout<<cscore;    cout<<endl;
    cout<<"英语成绩:";            cout<<escore;    cout<<endl;
}



void cstudent::input()
{
    cout<<"学号:";            cin>>num;        
    cout<<"姓名:";            cin>>name;   
    cout<<"性别:";            cin>>sex;        
    cout<<"年龄:";            cin>>age;        
    cout<<"数学成绩:";            cin>>mscore;   
    cout<<"计算机成绩:";            cin>>cscore;   
    cout<<"英语成绩:";            cin>>escore;   
}




void main()
{   
    cstudent a[2];
    ofstream outfile("D:\\学生信息.txt",ios::out);
        for (int i=0;i<2;i++)
            {
            a[i].input();
            a[i].send();
            cout<<endl;
            }
    outfile.close();
    ifstream infile("D:\\学生信息.txt",ios::in);
        for (i=0;i<2;i++)
        {
            cout<<"No."<<i+1<<endl;
            a[i].output1();
            a[i].fun();
            cout<<endl;
        }

}
搜索更多相关主题的帖子: 英语成绩 姓名 计算机 include private 
2011-11-03 15:09
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
呵呵
2011-11-03 15:20
yy21drd
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2011-11-2
收藏
得分:0 
晕啊,你笑什么呢?帮忙搞定啊
2011-11-03 15:31
lz1091914999
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:四川
等 级:贵宾
威 望:37
帖 子:2011
专家分:5959
注 册:2010-11-1
收藏
得分:5 
程序代码:
void main()
{   
    cstudent a[2];
    //ofstream outfile("D:\\学生信息.txt",ios::out);
      outfile.open("D:\\学生信息.txt",ios::out);
        for (int i=0;i<2;i++)
            {
            a[i].input();
            a[i].send();
            cout<<endl;
            }
    outfile.close();
   // ifstream infile("D:\\学生信息.txt",ios::in);
      infile.open("D:\\学生信息.txt",ios::in);
        for (i=0;i<2;i++)
        {
            cout<<"No."<<i+1<<endl;
            a[i].output1();
            a[i].fun();
            cout<<endl;
        }

}
这蛋疼的代码。

[ 本帖最后由 lz1091914999 于 2011-11-3 15:53 编辑 ]

My life is brilliant
2011-11-03 15:48
快速回复:这个程序编译能通过,但是运行后,在D盘建立的TXT文档是空的。没有预期 ...
数据加载中...
 
   



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

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