网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
01月08日漏签0天
c++吧 关注:648,854贴子:2,117,851
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 2回复贴,共1页
<<返回c++吧
>0< 加载中...

求大神帮我查下这段程序哪里有问题!!

  • 只看楼主
  • 收藏

  • 回复
  • Yy梦殇瀑布
  • ,
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<cstdio>
#include<cstring>
#include "main.h"
#include "Operate.h"
#include "Find.h"
#define STUDENT 50000
using namespace std;
int tot=0;
vector<Student> stu;
void read_file()
{
FILE*fp = fopen("student.txt","r");
while(fscanf(fp,"%s",stu[tot+1].name)!=EOF)
{
++tot;
fscanf(fp,"%lld",&stu[tot].snum);
fscanf(fp,"%lf",&stu[tot].total_score);
fscanf(fp,"%d",&stu[tot].num);
for(int i=1;i<=stu[tot].num;++i)
{
fscanf(fp,"%s",stu[tot].lecture[i].l_name);
fscanf(fp,"%lf",&stu[tot].lecture[i].score);
}
stu[tot].flag=1;
}
fclose(fp);
}
void add(Student a)
{
int i,j;
++tot;
for(i=0;i<strlen(a.name);++i)
stu[tot].name[i]=a.name[i];
stu[tot].num=a.num;
stu[tot].snum=a.snum;
stu[tot].total_score=a.total_score;
for(i=1;i<=a.num;++i)
for(j=0;j<strlen(a.lecture[i].l_name);++j) stu[tot].lecture[i].l_name[j]=a.lecture[i].l_name[j];
}
void input_student()
{
int i;
Student a;
char ch;
while(1)
{
++tot;
system("cls");
printf("\n\n");
printf("\t\t学生成绩管理系统->录入学生信息\n\n\n");
printf("\n\t\t请输入学生学号:\n");
printf("\t\t");
scanf("%lld",&a.snum);
printf("\n\t\t请输入学生姓名:\n");
printf("\t\t");
scanf("%s",a.name);
printf("\n\t\t请输入学生已选课程数目:\n");
printf("\t\t");
scanf("%d",&a.num);
a.total_score=0;
for(i=1;i<=a.num;++i)
{
printf("\n\t\t请输入学生所选第%d门课程名称:\n",i);
printf("\t\t");
scanf("%s",a.lecture[i].l_name);
printf("\n\t\t请输入学生所选第%d门课程成绩:\n",i);
printf("\t\t");
scanf("%lf",&a.lecture[i].score);
a.total_score+=a.lecture[i].score;
}
add(a);
printf("\n\n\t\t");
printf("是否继续输入其他学生的信息(Y/N)");
cout<<"OK"<<endl;
while(1)
{
ch=getchar();
if(strchr("YyNn",ch)!=NULL) break;
}
if(ch=='n'||ch=='N') break;
}
}
为什么我的add函数里面stu[i]赋值的地方总是出错



  • Yy梦殇瀑布
  • ,
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
二楼附上main.h
#ifndef MAIN_H
#define MAIN_H
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<cstdio>
#include<cstring>
using namespace std;
void welcome();
void display();
void read_file();
void write_file();
void input_student();
struct Lecture
{
char l_name[50];
double score;
};
struct Student
{
int num,flag;
char name[50];
long long snum;
Lecture lecture[50];
double total_score;
};
void add(Student a);
extern int tot;
extern vector<Student> stu;
#endif



2026-01-08 04:02:29
广告
不感兴趣
开通SVIP免广告
  • Yy梦殇瀑布
  • ,
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 2回复贴,共1页
<<返回c++吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示