云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 实验一

实验一

  • 62 次阅读
  • 3 次下载
  • 2026/4/28 3:47:15

数据结构实验指导书

计算机系数据结构实验报告(1)

姓名: 叶超 学号: 6103113037 专业班级: 计算机科学131班

实验目的:对C语言的复习,增强学生对结构体数组和指针的学习,尤以结构体的应用和指针的操作作为重点。

问题描述:

1、构造一个学生结构体数组,成员包括学号,姓名,四门成绩,以及平均成绩; 2、从键盘上输入学生的学号,姓名和四门成绩; 3、找出学生中考试没有通过的学生姓名并输出;找出考试在90分以上的学生并输出。 实验要求:

1、必须达到的最少程序行数为100行;

2、在实验过程中,分析算法的时间复杂度和空间复杂度进行分析。 定义结构: struct student {

char name[20];//name

float score[4];//all subjects' score char ID[20];//school ID float avesc;//average score }stu[20];

算法分析:本算法是通过设立学生的结构体,然后通过switch结构不断调用各函数达到对结构体的操作。其中主要是通过结构体指针来达到定位结构体的各项,然后将输入以及打印都独立为一个函数,要用的时候调用就好。对输出以及处理结构体的时候要用到循环,而是循环停下来一般注意道德是要用到null。 算法:

void printOver(struct student *p,struct student *q) {

for(;p

for(int i=0;i<4;i++) {

if(p->score[i]>=90) {

print(p); break; } } }

- 0 -

数据结构实验指导书

}

void printLow(struct student *p,struct student *q) {

for(;p

for(int i=0;i<4;i++) {

if(p->score[i]<90) {

print(p); break; } } } }

代码:

#include using namespace std; #include struct student {

char name[20];//name

float score[4];//all subjects' score char ID[20];//school ID float avesc;//average score }stu[20];

struct student *Per = stu,*FirP = stu;//the place of FirP never change,the first place void addScore(struct student *p);//the function to add score

void printScore(struct student *p,struct student *q);//print the scores of students; void printAll(struct student *p,struct student *q);//print the scores of all

void printOver(struct student *p,struct student *q);//print the part of scores that are over 90

void printLow(struct student *p,struct student *q);//print the part of scores that didn't pass

void print(struct student *p);

void cin_score(int i,struct student *p); void flag();//output the head of table

void aveScore(struct student *p,struct student *q); int main() {

loop: {

int sel;//sel is the selection of user

- 1 -

数据结构实验指导书

cout << \exit\

cin >> sel; switch(sel) {

case 1:

addScore(Per); Per++; break; case 2:

printScore(FirP,Per); break; case 3:

goto endUp; default:

cout << \ }

goto loop; } endUp: {

cout << \ } return 0; }

//to use the function request that p

//cin_score to ensure the strong of code cout << \ cin >> p->ID ;

cout << \ cin >> p->name ;

cout << \ cout << \ cin_score(0,p);

cout << \ cin_score(1,p);

cout << \ cin_score(2,p);

cout << \ cin_score(3,p); }

void printScore(struct student *p,struct student *q)

- 2 -

数据结构实验指导书

{

cout << \part of nopass\ char sel_2; cin >> sel_2; switch(sel_2) {

case 'A':

cout << \ flag();

printAll(p,q); break; case 'B':

cout << \ flag();

printOver(p,q); break; case 'C':

cout << \ flag();

printLow(p,q); break; default:

cout << \ } }

void printOver(struct student *p,struct student *q) {

for(;p

for(int i=0;i<4;i++) {

if(p->score[i]>=90) {

print(p); break; } } } }

void printLow(struct student *p,struct student *q) {

for(;p

- 3 -

搜索更多关于: 实验一 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

数据结构实验指导书 计算机系数据结构实验报告(1) 姓名: 叶超 学号: 6103113037 专业班级: 计算机科学131班 实验目的:对C语言的复习,增强学生对结构体数组和指针的学习,尤以结构体的应用和指针的操作作为重点。 问题描述: 1、构造一个学生结构体数组,成员包括学号,姓名,四门成绩,以及平均成绩; 2、从键盘上输入学生的学号,姓名和四门成绩; 3、找出学生中考试没有通过的学生姓名并输出;找出考试在90分以上的学生并输出。 实验要求: 1、必须达到的最少程序行数为100行; 2、在实验过程中,分析算法的时间复杂度和空间复杂度进行分析。 定义结构: struct student { c

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com