求一个关于结构体函数的程序

青梅煮酒 2009-04-10 11:54:41
某班期末考试科目有高等数学、英语、线性代数、程序设计,全班有n个同学,使用结构体表示学生的信息,包括学号、姓名、和各科成绩,编写函数实现如下功能:
(1)建立全班学生信息(表);
(2)按建表的顺序输出全部学生信息。

硬件:PC机
操作系统:
软件平台:Microsoft Visual C++ 6.0
本人菜鸟希望各位大侠帮忙!谢谢!
...全文
161 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
liliangbao 2009-04-11
  • 打赏
  • 举报
回复
UP LS
黄志义 2009-04-11
  • 打赏
  • 举报
回复
UP
[Quote=引用 2 楼 Nower 的回复:]
自己动手,丰衣足食!
[/Quote]
gxw145 2009-04-11
  • 打赏
  • 举报
回复
自己分析,自己动手啊,以后就会啦!!加油!!!
Nower 2009-04-11
  • 打赏
  • 举报
回复
自己动手,丰衣足食!
gao125210 2009-04-11
  • 打赏
  • 举报
回复
up
sky0801636 2009-04-11
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 mzlogin 的回复:]
给你写了个最简单的,
自己再改进下吧。
多看书多动手,
熟才能生巧。

C/C++ code
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;

struct Student
{
char Sno_[20];
char Sname_[20];
int mathGrade_;
int engGrade_;
int lineGrade_;
int progGrade_;
};

int main()
{
int n;
cout<<"请输入想录入信息的学生人数:";
cin>>n…
[/Quote]
======================================================================================================
正解,UP
benlei999 2009-04-11
  • 打赏
  • 举报
回复
为了练手还是自己写吧。c的,参考下
struct
{
}INFO

void WriteInfo(pTable *, int index, INFO *elem)
void ReadInfo(pTable *, int index)

main()
{
INFO **pTable = new INFO *[NUM]

while(...)
{
INFO *elem = new INFO;
ReadInfo(pTable, index ,elem)
}

while(...)
{
WriteInfo(pTable, index)
}

delete ...
}
mzlogin 2009-04-11
  • 打赏
  • 举报
回复
给你写了个最简单的,
自己再改进下吧。
多看书多动手,
熟才能生巧。

#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;

struct Student
{
char Sno_[20];
char Sname_[20];
int mathGrade_;
int engGrade_;
int lineGrade_;
int progGrade_;
};

int main()
{
int n;
cout<<"请输入想录入信息的学生人数:";
cin>>n;
vector<Student> Stu;
Student tmp;
for(int i=0;i!=n;++i)
{
cout<<"请输入第"<<i+1<<"个学生的学号:";
cin>>tmp.Sno_;
cout<<"请输入第"<<i+1<<"个学生的姓名:";
cin>>tmp.Sname_;
cout<<"请输入第"<<i+1<<"个学生的高数成绩:";
cin>>tmp.mathGrade_;
cout<<"请输入第"<<i+1<<"个学生的英语成绩:";
cin>>tmp.engGrade_;
cout<<"请输入第"<<i+1<<"个学生的线代成绩:";
cin>>tmp.lineGrade_;
cout<<"请输入第"<<i+1<<"个学生的程序成绩:";
cin>>tmp.progGrade_;

Stu.push_back(tmp);
}

cout<<"输入完毕!下面是全部学生信息:"<<endl;
cout<<setw(8)<<"学号"
<<setw(8)<<"姓名"
<<setw(8)<<"高数"
<<setw(8)<<"英语"
<<setw(8)<<"线代"
<<setw(8)<<"程序"<<endl;

for(vector<Student>::iterator iter=Stu.begin();iter!=Stu.end();++iter)
{
cout<<setw(8)<<iter->Sno_
<<setw(8)<<iter->Sname_
<<setw(8)<<iter->mathGrade_
<<setw(8)<<iter->engGrade_
<<setw(8)<<iter->lineGrade_
<<setw(8)<<iter->progGrade_<<endl;
}

return 0;
}
bao001001 2009-04-11
  • 打赏
  • 举报
回复

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


class Course{
static const string CourseName[5];

public:
static enum CourseId{NA,AM,EN,LA,PD};
typedef CourseId ID;

Course(){ courseId = NA;}
Course(Course::ID id){ courseId = id; }

friend ostream& operator<<(ostream &out,Course c){
return out << CourseName[c.courseId];
}

protected:
CourseId courseId;
};

const string Course::CourseName[5] = {"Not Available","Advanced math","English","Linear Algebra","Program Design"};

class Grade{
static const string GradeCode[];

public:
static enum GradeId{NA,F,CM,C,CP,BM,B,BP,AM,A,AP};
typedef GradeId ID;

Grade(){ gradeId = NA; }
Grade(Grade::ID id){ gradeId = id; }

friend ostream& operator<<(ostream &out,Grade g){
return out << GradeCode[g.gradeId];
}

protected:
GradeId gradeId;
};

const string Grade::GradeCode[]={"N/A","Fail","C-","C","C+","B-","B","B+","A-","A","A+"};

class StudentId{
static const string emptyId;
public:
StudentId(){ studentId = emptyId;}
StudentId(string id){
if(id.length() != 6) {
cerr << "Error: student id length\n";
exit(1);
}else{
for(int i=0; i<6; i++)
if(!isdigit(id[i])){
cerr << "Error: student id format\n";
exit(1);
}
}
studentId = id;
}

friend ostream& operator<<(ostream &out, StudentId id){
return cout << id.studentId;
}
protected:
string studentId;
};

const string StudentId::emptyId=" ";

class StudentInfor{

public:
StudentInfor():ID(),course(),grade(){
name = "";
}

StudentInfor(string I, string n, Course::ID c, Grade::ID g):ID(I),course(c),grade(g){
name = n;
}

friend ostream& operator<<(ostream &out, StudentInfor s){
return out << s.ID << '\t'<< s.name << '\t'<< s.course << '\t'<< s.grade << endl;
}

protected:
StudentId ID;
string name;
Course course;
Grade grade;
};

int main(int argc, char *argv[])
{
StudentInfor student[2]={StudentInfor("001001","machel jackson",Course::AM, Grade::AP),
StudentInfor("001002","williams sonoma",Course::EN,Grade::BM)};

cout << student[0];
cout << student[1];
}
xiaocha 2009-04-11
  • 打赏
  • 举报
回复
这么简单的东西, 都不自己动手, lz要等到什么时候才动手呀!
青梅煮酒 2009-04-11
  • 打赏
  • 举报
回复
非常谢谢指教!没有借口,只有自己是自己的救星!
青梅煮酒 2009-04-11
  • 打赏
  • 举报
回复
谢谢,我能!
hoomey 2009-04-11
  • 打赏
  • 举报
回复
看看书就会了,书上的代码稍微改下就OK啦
  • 打赏
  • 举报
回复
楼主,随便找来一个链表代码。
然后自己把结构改成你这里的学生结构体就可以了。
代码基本都不用改的。
ryfdizuo 2009-04-10
  • 打赏
  • 举报
回复
哇,又是这种问题
晕死.....

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧