首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj3,其中使用友元函数访问类的私有数据成员,求出两个数据成员的大于1的最小公因子。请编写友员函数FriFun,使其输出结果为: Common denominator is 2 要求:补充编制的内容写在“
请打开考生文件夹下的解决方案文件proj3,其中使用友元函数访问类的私有数据成员,求出两个数据成员的大于1的最小公因子。请编写友员函数FriFun,使其输出结果为: Common denominator is 2 要求:补充编制的内容写在“
admin
2019-04-24
22
问题
请打开考生文件夹下的解决方案文件proj3,其中使用友元函数访问类的私有数据成员,求出两个数据成员的大于1的最小公因子。请编写友员函数FriFun,使其输出结果为:
Common denominator is 2
要求:补充编制的内容写在“//*********333*********”与“//*********666*********”之间,不得修改程序的其他部分。
注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
//proj3.h
Class FriFunClass
{
int a,b;
public:
FriFunClass(int i,int j){a=i;b=j;}
friend int FriFun(FriFun-Class x); //友元函数
};
void writeToFile(const char*),
//proj3.cpp
#include
using namespace std;
#include "prj3.h"
int FriFun(FriFunclass X)
(
//********333********
//由于函数FriFun()是类FriFunClass的友元函数,所以它可以直接访问a和b
//********666********
}
int main()
{
FriFunclass n(10,2 0);
if(FriFun(n))
cout<<"Common denominator is" <
else cout<<"NO common de
nominator.\n";
writeToFile(" ");
return 0;
}
选项
答案
int min=x.a
解析
主要考查考生对友元函数的掌握情况,友元函数可以访问类的私有数据成员,题目要求函数求出两个数据成员的大于1的最小公因子,从2开始往上算,因此要同时可以被两个私有成员整除,这里用取余符号完成,取余为0即为整除。
转载请注明原文地址:https://kaotiyun.com/show/DOAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列有关函数重载的叙述中,错误的是()
以下程序运行后的输出结果是()。#include<iostream.h>voidmain(){charaft="abbcabbcabbc";inti=0,j=0,k=0;while(a[i
不改变关系表中的属性个数但能减少元组个数的是______。
有如下程序:#include<iostream>usingnamespacestd;{TestClass(){cout<<"BB";fun()}voidfun(){cout<<"Bf";}};c
在下面的类定义中,错误的语句是()。classSample{public:Sample(intval)://①~Sample();//②private:int
下列是重载乘法运算的函数原型声明,其中错误的是
在下列枚举符号中,用来表示“相对于当前位置”文件定位方式的是
下列字符串中不能作为C++标识符使用的是
随机试题
以下电气设备中,属于防火重点设备的有()。
各种悬吊灯具离地面的距离不应小于()。
英国国家标准(),日本国家标准(),美国国家标准()。
通过把多项式分解因式,把函数f(x)=ln(1+X一2x2)展开为x的幂级数,并给出收敛域.
治疗小儿衣原体肺炎首选的抗生素是()。
房地产权属档案是权属管理活动中形成的历史记录,不但具有专业性、动态性、法律性,还具有()。
管线共沟敷设时,不符合规定的是()。
下列说法中对税务机关职权表述正确的是( )。
商业银行有效的战略风险管理应当确保其长期战略、短期目标、()和可利用资源紧密联系在一起。
天地悠悠悬秤杆,百姓芸芸秤砣心。严纲纪、正作风是一场大手术,唯有___________才能___________。填入画横线部分最恰当的一项是()。
最新回复
(
0
)