标题:[求助]一个简单的学生管理系统程序中顶层函数的实现出现了问题,可以帮个忙 ...
只看楼主
tangofan
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-5-20
 问题点数:0 回复次数:4 
[求助]一个简单的学生管理系统程序中顶层函数的实现出现了问题,可以帮个忙吗?

上个星期N倒霉呀(也不能这么说啦),被老师检查程序,看过我写的程序老师N失望,我也觉得N丢脸,可是我实在是搞不定这个程序,请大家帮帮忙。

程序的题目是这样的: 做一个学生管理系统,最少可以管里10个学生
功能有:可以输入学生的信息,可以增加学生,可以查询学生信息,可以改学生名字
要求:要自己建立一个学生,要有构造函数和析构函数,要用到数组

这是我写的程序:我的问题是:1、增加学生的函数add()不知道如何实现 2、输如学生信息的函数input()实现错误

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define N 4
class student
{
public:
string name;
long ID;
student(){name="unknown";ID=0;setage(0);setsex("unknown");setmajor("unknown");}
student(const string& n){name=n;ID=0;setage(0);setsex("unknown");setmajor("unknown");}//析构函数
string changename(string s){name=s;return name;} //修改名字
void setage(int n){age=n;} //设定年龄
int getage(){return age;}
void setsex(string x){sex=x;} //设定性别
string getsex(){return sex;}
void setmajor(string s){major=s;} //设定所学专业
string getmajor(){return major;}
void show(); //显示学生的信息
void showname(){cout<<"name is:"<<name<<'\n'<<'\n';} //show name
void showID(){cout<<"ID is:"<<ID<<'\n'<<'\n';} //show ID
void showsex(){cout<<"sex is:"<<sex<<'\n'<<'\n';} //show sex
private:
int age;
string sex;
string major;
};


void student::show() //show()的实现
{
cout<<setfill('-');
cout<<left<<setw(9)<<"name"<<name<<endl
<<setw(9)<<"age"<<getage()<<endl
<<setw(9)<<"ID"<<ID<<endl
<<setw(9)<<"sex"<<sex<<'\n'
<<setw(9)<<"major"<<major<<'\n'<<'\n'<<'\n';

}

/*void add();*/ //这个函数要怎么实现?要怎样用new()来实现呢?
void input();
int main()
{
student stu[N];
int i=0,j=0,k=0;

while(1){
cout<<"STUDENT'S MANAGEMENT SYSTEM\n"
<<"1 Input the students' informations\n2 Add a student\n3 Check a student's information\n4 Change a student's name\n\nPLEASE DO A CHOICE\n";

cin>>i;
switch(i)
{
/*case 1:input(); break;
case 2:add(); break;*/
case 3: cout<<"chose a student\n";
cin>>j;
if(j<N){stu[j].show();}
else cout<<"reelect a student,from 0 to N\n";
break;
case 4: cout<<"which student do you want to change?\n";
cin>>k;
if(k<N) {stu[k].changename("helo");stu[k].showname();} //这个也有问题,我固定将学生的名字改为hero了,其实应该可以改为任何一个名字的,帮帮忙
break;
default: cout<<"I'm sorry you are wrong\n\n";
}

}

return 1;
}

/*void input() //请帮我改改这个函数的实现,谢谢
{
student s[N];
string x,y,z; int p;long id;
cout<<left<<setw(9)<<"name"<<setw(9)<<"ID"<<setw(9)<<"age"<<setw(9)<<"sex"<<setw(9)<<"major"<<endl;
for(int i=0;i<N;i++)
{
cin>>setw(9)>>x>>setw(9)>>id>>setw(9)>>p>>setw(9)>>y>>setw(9)>>z;
s[i]->name=x;stu[i]->ID=id;s[i]->setage(p);s[i]->setsex(y);s[i]->setmajor(z);
s.show();
}

}*/

先谢了,我已经尽力自己改了,可是还是得请各位帮忙。

[此贴子已经被作者于2007-6-1 10:59:32编辑过]

搜索更多相关主题的帖子: 系统程序 函数 顶层 学生 
2007-06-01 10:58
tangofan
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-5-20
得分:0 
还有,我退不出while循环

狂热tango!
2007-06-01 11:24
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
得分:0 

#include<iostream>
#include<string>
#include<iomanip>
#include <list>
using namespace std;

class Student
{
int age;
string sex;
string major;
string name;
long ID;
public:
Student(long id=0,string n=\"unknow\",int a=0,string s=\"unknown\",string m=\"unknown\")
:ID(id),name(n),age(a),sex(s),major(m)
{
}
bool operator==(const Student& s)
{
return ID==s.ID;
}
long getID()
{
return ID;
}
string setName(string s)
{
return name=s;
}
string getName()
{
return name;
}
int setAge(int n)
{
return age=n;
}
int getAge()
{
return age;
}
string setSex(string x)
{
return sex=x;
}
string getSex()
{
return sex;
}
string setMajor(string s)
{
return major=s;
}
string getmajor()
{
return major;
}
void showname()
{
cout<<\"name is:\"<<name<<'\n'<<'\n';
}
void showID()
{
cout<<\"ID is:\"<<ID<<'\n'<<'\n';
}
void showsex()
{
cout<<\"sex is:\"<<sex<<'\n'<<'\n';
}
void show(); //显示学生的信息
};
void Student::show() //show()的实现
{
cout<<setfill('-')<<left
<<setw(9)<<\"name\"<<name<<endl
<<setw(9)<<\"age\"<<age<<endl
<<setw(9)<<\"ID\"<<ID<<endl
<<setw(9)<<\"sex\"<<sex<<endl
<<setw(9)<<\"major\"<<major<<endl<<endl<<endl;

}

class SMS
{
typedef list<Student>::iterator LSI;
list<Student> m_stuList;
Student* addInput()
{
string x,y,z;
int a;
long id;
cout<<left<<setw(9)<<\"name\"<<setw(9)
<<\"ID\"<<setw(9)<<\"age\"<<setw(9)
<<\"sex\"<<setw(9)<<\"major\"<<endl;
cin>>x>>id>>a>>y>>z;
return new Student(id,x,a,y,z);
}
long idInput(string str)
{
long id;
cout<<str;
cin>>id;
return id;
}
public:
int GetCount()
{
return m_stuList.size();
}
int Add(const Student &s)
{
m_stuList.unique();
m_stuList.push_back(s);
}
int Add()
{
Student *p=addInput();
Add(*p);
delete p;
}
bool Delete(long id)
{
if(GetCount()==0)
{
cout<<\"\n! There Is Not Any Student's Infomation In The Student Manager System(SMS) !\n\n\n\";
return false;
}
for(LSI iter=m_stuList.begin();iter!=m_stuList.end();iter++)
{
if(iter->getID()==id)
{
m_stuList.erase(iter);
return true;
}
}
cout<<\"Not Found This Student!\"<<endl;
return false;
}
void DeleteX()
{
if(GetCount()==0)
{
cout<<\"\n! There Is Not Any Student's Infomation In The Student Manager System(SMS) !\n\n\n\";
return;
}
while(!Delete(idInput(\"input the ID of the student which is going to be delete: \"))){}
}
bool ChangeName(long id)
{
if(GetCount()==0)
{
cout<<\"\n! There Is Not Any Student's Infomation In The Student Manager System(SMS) !\n\n\n\";
return false;
}
for(LSI iter=m_stuList.begin();iter!=m_stuList.end();iter++)
{
if(iter->getID()==id)
{
cout<<\"input a name to instead of the student's now: \";
string name;
cin>>name;
iter->setName(name);
iter->show();
return true;
}
}
cout<<\"Not Found This Student!\"<<endl;
return false;
}
void ChangeNameX()
{
if(GetCount()==0)
{
cout<<\"\n! There Is Not Any Student's Infomation In The Student Manager System(SMS) !\n\n\n\";
return;
}
while(!ChangeName(idInput(\"input the ID of the student whose name is going to be changed: \"))){}
}
bool Show(long id)
{
if(GetCount()==0)
{
cout<<\"\n! There Is Not Any Student's Infomation In The Student Manager System(SMS) !\n\n\n\";
return false;
}
for(LSI iter=m_stuList.begin();iter!=m_stuList.end();iter++)
{
if(iter->getID()==id)
{
iter->show();
return true;
}
}
cout<<\"Not Found This Student!\"<<endl;
return false;
}
void ShowX()
{
if(GetCount()==0)
{
cout<<\"\n! There Is Not Any Student's Infomation In The Student Manager System(SMS) !\n\n\n\";
return;
}
while(!Show(idInput(\"input the ID of the student which is being checked: \"))){}
}
void showAll()
{
if(GetCount()==0)
{
cout<<\"\n! There Is Not Any Student's Infomation In The Student Manager System(SMS) !\n\n\n\";
return;
}
for(LSI iter=m_stuList.begin();iter!=m_stuList.end();iter++)
{
iter->show();
}
}
static void Menu()
{
cout<<\"STUDENT'S MANAGEMENT SYSTEM\n\"
<<\"1 Add a student\n\"
<<\"2 Delete a student\n\"
<<\"3 Check a student's information\n\"
<<\"4 Change a student's name\n\"
<<\"5 Show All Of These Student's Infomation\n\"
<<\"6 Exit From The Student Manager System(SMS)\n\n\"
<<\"PLEASE DO A CHOICE\n\";
}
};

void main()
{
SMS sms;
int i=0;
while(1)
{
SMS::Menu();
cin>>i;
switch(i)
{
break;
case 1:sms.Add(); break;
case 2:sms.DeleteX();break;
case 3:sms.ShowX();break;
case 4:sms.ChangeNameX();break;
case 5:sms.showAll();break;
case 6:exit(1);
default: cout<<\"I'm sorry you are wrong\n\n\";
}
}
}

[此贴子已经被作者于2007-6-1 13:10:28编辑过]


[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2007-06-01 13:08
tangofan
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-5-20
得分:0 
谢谢谢谢,我还得研究下,一下看不懂。
谢啦,我们隔壁学校呀。没准可以请你吃饭呢(不要太当真啦!)

狂热tango!
2007-06-05 08:46
little_stone
Rank: 1
等 级:新手上路
威 望:1
帖 子:163
专家分:0
注 册:2007-5-29
得分:0 
学习下.

2007-06-05 09:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-144018-1-1.html




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

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