C++错误,求高手帮忙改一下 PS:能运行,但是结果不正确,共两个题

[复制链接]
查看11 | 回复5 | 2012-3-15 18:50:04 | 显示全部楼层 |阅读模式
一、int total,stu1,stu2,stu3,t;Student student1;...stu1=retotal();//你的total在这里是个局部变量,没有人给他赋值,不能直接使用的!!下同Student student2;...stu2=retotal();Student student3;...stu3=retotal(); 二、void charRange::showRange(){int i;//同样没有赋值就直接使用,当然没有意义了!!for(i=0;i'A'&&a<'D'...
回复

使用道具 举报

千问 | 2012-3-15 18:50:04 | 显示全部楼层
#include using namespace std;//1.排序排不出来,出现莫名其妙的数class Student{public:int English,computer,total;void getscore();void display();int retotal(){...
回复

使用道具 举报

千问 | 2012-3-15 18:50:04 | 显示全部楼层
第一题的int total,stu1,stu2,stu3,t;Student student1;student1.getscore();student1.display();stu1=total;toatl可没有赋值的啊,应该在哪里给它值吧? 第二题show 的时候没有循环啊你是想10存储完,然后依次输...
回复

使用道具 举报

千问 | 2012-3-15 18:50:04 | 显示全部楼层
先说第一个问题stu1=total;这个total是你主函数里面定义的total,他不属于对象student1。正确的调用时将student类中的total定义为公有,stu1=student1.total;同理后面两个也要改。第二题i没有赋值,a指向未知区域。你是想10存储完,然后依次输出right或者wrong的吧?如楼上的...
回复

使用道具 举报

千问 | 2012-3-15 18:50:04 | 显示全部楼层
第一个程序在mian()函数里声明的int total没有赋值,一个没有值的变量然后在赋给另外一个变量? #include using namespace std;class Student{private:int English, computer, total;public:void getscore();...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行