| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 840 人关注过本帖
标题:哪位高手来帮忙
只看楼主 加入收藏
lee7ng
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-1-4
收藏
 问题点数:0 回复次数:0 
哪位高手来帮忙
#include<iostream.h>
#include<iomanip.h>
#include<string.h>
#include<fstream.h>
#include<stdio.h>
#include<stdlib.h>

class student
{
    private:
        int sno;//学号
        char name[8];
        int java;
        int prog;
        public:
        student();
        ~student();
        void luru();//学生信息录入构造函数
        void shuchu();//学生信息输出构造函数
        void setsno(int temp);
        int getsno();
        char *getname();
        char *getspeciality();
        void change();//学生信息修改构造函数
        void read();
        void write();
        void  find();
};
student::student()
{}

student::~student()
{}

int student::getsno()  {return sno;}
char *student::getname()  {return name;}
void student::setsno(int temp)  {sno=temp;}
void student::luru()
{
ifstream tfile("max.txt",ios::binary|ios::nocreate);
tfile.close();
ofstream ofile("max.txt");
tfile.close();
cout<<"请输入学生信息"<<endl;
cout<<"学生学号"<<endl;
cin>>sno;
cout<<"学生姓名:"<<endl;
cin>>name;
cout<<"java成绩:"<<endl;
cin>>java;
cout<<"程序设计成绩:"<<endl;
cin>>prog;
}
//输出
void student::shuchu()
{
cout<<setw(6)<<sno<<setw(6)<<name<<setw(6)<<java<<setw(10)<<prog<<endl;
}
//修改信息
void student::change()
{
cout<<"请输入要修改学生的信息:"<<endl;
cout<<"学号是不是要改写(Y/N)"<<endl;
char ch;
cin>>ch;
if(ch=='Y'||ch=='y')
{
cout<<"请输入新学号"<<endl;
cin>>sno;
cout<<"请输入新姓名:"<<endl;
cin>>name;
}
cout<<"请输入新的java成绩:"<<endl;
cin>>java;
cout<<"请输入新的程序设计成绩:"<<endl;
cin>>prog;
cout<<"你刚刚输入的学生信息如下:"<<endl;
shuchu();
}
//查询
void   find()
{
int   i,sel;
int   founded=0;//是否查到
int   tol=0;//查询所得的人数
student   temp;
cout << "1.学号查询 " <<endl;
cout << "2.姓名查询 " <<endl;
cout << "3.按科目查询 " <<endl;
cout << "4.总分查询 " <<endl;
cout << "请输入进行查询的操作号: ";
cin>> sel;
switch   (sel)
{
case   1:   cout << "请输入学号: ";
cin>>temp.sno;
if(temp.sno==sno)
{
cout<<setw(5)<<sno;
cout<<setw(5)<<name;
cout<<setw(5)<<java;
cout<<setw(5)<<prog;
founded=1;
cout <<endl;
}
if(founded==0)   cout << "找不到该学生数据 " <<endl;
break;
case   2:   cout << "请输入姓名: ";
cin>> temp.name;
for(i=0;i <num;i++)
{
if(strcmp(temp.name,name)==0)
{
cout<<setw(5)<<sno;
cout<<setw(5)<<name;
cout<<setw(5)<<java;
cout<<setw(5)<<prog;
founded=1;
cout <<endl;
}
}
if(founded==0)   cout << "找不到该学生数据 " <<endl;
break;
case   3:cout << "请选择科目:1-java   2-程序设计 ";
cin>> sel;
if(sel==1)
{
cout << "请输入分数: ";
cin>> temp.java;
for(i=0;i <num;i++)
{
if(temp.java <=java)
{
cout<<setw(5)<<sno;
cout<<setw(5)<<name;
cout<<setw(5)<<java;
cout<<endl;
tol++;
}
}
cout << "总人数: " <<tol;
}
else   if(sel==2)
{
cout << "请输入分数: ";
cin>> temp.prog;
for(i=0;i <num;i++)
{
if(temp.prog <=prog)
{
cout<<setw(5)<<sno;
cout<<setw(5)<<name;
cout<<setw(5)<<prog;
cout<<endl;
tol++;
}
}
cout << "总人数: " <<tol;
}
else   cout << "输入错误! " <<endl;

break;
case   4:cout << "请输入总分: ";

cin>> temp.java;
for(i=0;i <num;i++)
{
if(temp.java <=prog+java)
{
cout<<setw(5)<<sno;
cout<<setw(5)<<name;
cout<<setw(5)<<java;
cout<<setw(5)<<prog;
cout<<endl;
tol++;
}
}
cout << "总人数: " <<tol;
break;
default:cout << "输入错误! " <<endl;
}
}

//student 类的全局变量
student information;
void menu()
{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<<" 请选择所需功能:(序号) "<<endl;
cout<<" "<<endl;
}
void read()
{
ifstream afile("student.txt",ios::nocreate);
afile.read((char*)&information,sizeof information);
}
void write()
{
ofstream bfile("student.txt",ios::app);
bfile.write((char*)&information,sizeof information);
}
//录入信息
void input(void)
{
char ch;
information.luru();
write();
cout<<"你还要输入下一位学生的信息吗(Y/N)!"<<endl;
cin>>ch;
if(ch=='Y'||ch=='y')        
input();
}
void change()
{
int ch,p=0,l=0;
cout<<"请输入你要修改的学生的学号:"<<endl;
cin>>ch;
ifstream efile("student.txt",ios::nocreate);
while(efile.good())
{
efile.seekg(sizeof(information)*p);
if(efile.read((char *) &information,sizeof information))
{
if(ch==information.getsno())
{
information.shuchu();
ch=0;
information.change();
ofstream ffile("student.txt",ios::nocreate|ios::in);
ffile.seekp(sizeof(information)*p);
ffile.write((char *) &information,sizeof information);
ffile.close();
l++;
return;
}
}
p++;
}
efile.close();
if(l!=1)
cout<<"没有你所要修改的学生信息!"<<endl;
}
//删除函数
void shanchu()
{
int ch;
cout<<"请输入要删除的学生的学号:"<<endl;
cin>>ch;
ifstream out("student.txt",ios::nocreate);
ofstream in("student1.txt",ios::trunc);
while(out)
{ if(out.read((char*)&information,sizeof information))
if(ch!=information.getsno())
{
in.write((char*)&information,sizeof information);
}
}
in.close();
out.close();
ofstream gfile("student.txt",ios::trunc);
gfile.close();
ifstream ifile("student1.txt",ios::nocreate);
ofstream hfile("student.txt",ios::trunc);
while(ifile)
{
if(ifile.read((char*)&information,sizeof information))
hfile.write((char *)&information,sizeof information);
}
ifile.close();
hfile.close();
}
//输出函数
void output()
{
int i=0;
ifstream cfile("student.txt",ios::nocreate);
while(cfile)
{
if( cfile.read((char *)&information,sizeof information))
{
information.shuchu();
i++;
}
}
cout<<setw(6)<<"学号"<<setw(6)<<"姓名"<<setw(10)<<"java成绩"<<setw(15)<<"程序设计成绩"<<endl;
if(i!=0)
cout<<"一共有"<<i<<"个学生信息"<<endl;
else
cout<<"还没有输入学生信息"<<endl;
}
//选择菜单函数
void select()
{
int ch;
do{
cin>>ch;
switch(ch)
{
case 1:
output();
menu();
break;
case 2:
input();
menu();
break;
case 3:
shanchu();
menu();
break;
case 4:
change();
menu();
break;
case 5:
find();
menu();
case 6:
exit(6);
menu();
break;
default :
menu();
cout<<"输入无效≌请选择所需功能:(序号)"<<endl;
break;
}
}while(1);
}
void main()
{
menu();
select();
}
查询命令就是不对,哪位可以帮忙修改下,不胜感激~~
搜索更多相关主题的帖子: int void include student 
2008-01-04 12:46
快速回复:哪位高手来帮忙
数据加载中...
 
   



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

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