| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 457 人关注过本帖
标题:大家看看这个程序,为什么运行了,却加载不到学生的信息
只看楼主 加入收藏
mhg1314
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-9-2
结帖率:100%
收藏
 问题点数:0 回复次数:1 
大家看看这个程序,为什么运行了,却加载不到学生的信息
#include "stdafx.h"

#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
using namespace std;
class Class;
class Student{
 string Name;//学生姓名
 string ID;//学生学号
 string Number;//学生序号
public:
   string GetName();
   string GetNumber();
      string GetID();
   friend class Class;
};
string Student::GetID()
{
 return ID;
}
string Student::GetName()
{
 return Name;
}
string Student::GetNumber()
{
 return Number;
}
class System
{
public:
 void menu();
};
class Class{
 Student *student;
 int number;
public:
 Class(string);
 ~Class(){delete []student;};
 int GetNumber();
 friend void System::menu();
};


void System::menu()
{string temp;
cout<<"请输入学生名单文件(*.txt)的全路径:";
cin>>temp;

Class cls(temp);
char tmp,tp;

 do{
cout<<"Enter 1 or 0<1抽取,0退出,其它无效>:";
cin>>tmp;

 }while(tmp!='1');
int NUM;

while(1){
      NUM=rand()%41+1;
      cout<<"被抽中的是:"<<endl;
      cout<<"学生序号:"<<cls.student[NUM].GetNumber()<<endl;
      cout<<"学生学号:"<<cls.student[NUM].GetID()<<endl;
      cout<<"学生姓名:"<<cls.student[NUM].GetName()<<endl;
do{
  cout<<"Enter 1 or 0<1为继续抽取,0为退出,其它无效>:";
  cin>>tp;
  
}while(tp!='1');

   }
}
Class::Class(string temp)
{
 string tmp;
 number=0;
 char *p=new char[100];
 while(1)
  {
   ifstream File;
   File.open(temp.c_str());
       if(File)
       {
        cout<<"文件打开成功......"<<endl;
        while(!File.eof())
        {File.getline(p,100);number++;}
        cout<<number<<endl;
        student=new Student[number];
          File.seekg(0, ios_base::beg);
        for(int i=0;i<number;i++){
         File>>tmp;
         student[i].Number=tmp;
         File>>tmp;
道道道.zip (997 Bytes)

         student[i].ID=tmp;
         File>>tmp;
         student[i].Name=tmp;     
        }
    File.close();
    break;
   }
   else
   {
    cout<<"警告:不能打开该文件!"<<endl;
    File.close();
   }
   
  }
  cout<<"已经初始化....."<<endl;
  cout<<"该班学生人数为:"<<number<<"人"<<endl;
}
int Class::GetNumber()
{
 return number;
}
int main()
{
 System sys;
 sys.menu();
 return 0;
}


附测试文件一个(只供测试,不得用作其他用途)     我测试了,随机数没问题
搜索更多相关主题的帖子: 加载 学生 运行 
2010-09-03 13:29
快速回复:大家看看这个程序,为什么运行了,却加载不到学生的信息
数据加载中...
 
   



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

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