| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 576 人关注过本帖
标题:[求助]运算符重载问题
取消只看楼主 加入收藏
xbw0114
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2007-8-8
收藏
 问题点数:0 回复次数:1 
[求助]运算符重载问题

#include <iostream.h>

class TriNum{

int a[100];

int n;

int p, q;

public:

TriNum(int n=0, int p=0, int q=0){ this->n = n; this->p = p; this->q = q;}//这里this->n = n; this->p = p; this->q = q代表什么呀?

void process();

void Print();

friend istream& operator>>(istream& istr, TriNum&);

};

istream& operator>>(istream& istr, TriNum& tri)//这里是什么意思为什么要这样定义?为什么要定义为友员函数呀

{

cout << "请输入求值范围(p, q):";

cin >> tri.p >> tri.q;

while( tri.p<100 || tri.q < 100 || tri.p>999 || tri.q > 999 || tri.p>tri.q )

{

cout << "请输入求值范围(p, q):";

cin >> tri.p >> tri.q;

}

return istr;//这里返回的是什么值?

}

void TriNum::Print()

{

cout << "个数:" << n;

cout << "满足条件的数有:" ;

for( int i=0; i<n; i++) cout << " " << a[i] ;

cout << endl;

}

void TriNum::process()

{

int s, t1, t2, t3;

for( int i=p; i<=q; i++)

{

s = i / 11;

t3 = i/100; t2 = (i % 100)/10; t1 = i % 10;

if( s == t3*t3 + t2*t2 + t1*t1 )

{

a[n] = i;

n++;

}

}

}

void main()

{

TriNum tri;

cin >> tri;

tri.process();

tri.Print();

}

搜索更多相关主题的帖子: 运算符 重载 
2007-10-03 22:20
xbw0114
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2007-8-8
收藏
得分:0 
帮帮忙呀~~~

勤奋造就未来
2007-10-04 10:11
快速回复:[求助]运算符重载问题
数据加载中...
 
   



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

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