C++读程题: 1. #include<iostream> Using namespace std; Class N{ private: int A;

作者&投稿:实肯 (若有异议请与网页底部的电邮联系)
修改程序 #include<iostream> using namespace std; class base { private: int m; public: base(i~

我说一下我的看法:
一、在derived(int a,int b):b(a)这一构造函数应该改为derived(int a,int b):base(a);
二、在class derived:private base这一句中,将base定义为了私有成员,所以派生类derived的对象无法访问base的成员函数。
所以我将这一句改为class derived :public base
然后下边的调用改成了obj.base::show();
附代码
#includeusing namespace std;class base{private:int m;public:base(int a) :m(a) {}void show() const{cout << "m:" << m << endl;}};class derived :public base{int n;public:derived(int a, int b) :base(a){n = b;}};void main(){derived obj(10, 18);obj.base::show();}

运行结果为99=3*3*112.
num修改为100之后,运行结果是100=2*2*5*5
num修改为999之后,运行结果是999=3*3*3*37
上面这段代码的功能是进行质因数分解。
该算法已经是质因数算法中最优的了,不存在效率低下的问题,没有办法进行改善了。
代码中带有***注释的代码行可以改进,
else if (num % k != 0)里面的num %k 运算多余,在if里面已经运算过了,直接写成else即可。
请采纳,谢谢。

你自己先改改,我运行了一下好多都是基本常识错误,什么大小写,少分号什么的简单的错误,自己上机都能改出来加油



上机实现!。。


伊春市18055439905: c++ 一道读程序写结果的题 -
伏晓鹅掌: 1、运行结果:this Cat weights0.9 this Cat weights0.822、你的程序代码预处理引用不够规范.c++代码建议将预处理include写成下面的格式:#include <iostream> using namespace std;

伊春市18055439905: 第一题怎么做,用c++程序做,#include<stdio.h>的形式不要用具体数字,我要用程序任 -
伏晓鹅掌: #include <stdio.h> using namespace std; int main() { double a,b,c; cout<<"请输入a和b的值:"; cin>>a>>b; c=a+b; cout<<"a+b="<<c<<endl; return 0; }#include <stdio.h> using namespace std; int main() { double a,b; cout<<"请输入a和b的值...

伊春市18055439905: c++读程序写运行结果 -
伏晓鹅掌: 1. 运行结果如下:Con A copy_init Con A copy_init Con A10 Des A Des A Des A2. 代码中的语法错误如下: TC cl[2]; // 这里定义的cl,下面用的是c1,要修改统一 c1[0]=TC(1,2,3,4,5); // TC的构造函数只有4个参数,你传了5个,我把最后一个...

伊春市18055439905: c++读程序写结果 -
伏晓鹅掌: #include using namespace std; void main() { int a,b,c,d; cout>a>>b>>c>>d; cout

伊春市18055439905: 求助:3道C++的编程题~!~!~!~!~!!!!! -
伏晓鹅掌: //第一题#include void main() { int a,b,c; for(a=1;a for(b=0;b for(c=1;c if(100*(a+c)+10*(b+b)+a+c==1333) cout}//第二题#include #include int sushu(int n) { for(int i=2;i if(n%i==0) return 0; return 1; } void main() { int n; cout cin>>n; if(n%2!=0||n cout else ...

伊春市18055439905: 求C++大神解答问题!读程序~~快要考试了..求大神帮忙丫~~ -
伏晓鹅掌: 第一题:Value: 10, Constructed!Value: 10, Copy Constructed!Value: 20, Copy Constructed!Value: 20, Destructed!Value: 20, Destructed!Value: 10, Destructed!分析:本题主要考察构造函数和析构函数的特点,以及函数参数传递的特点.先分析...

伊春市18055439905: C语言程序阅读题 -
伏晓鹅掌: 1.result = 32.min is 53.20,104.2,3,5.10,206.4 17.r=15

伊春市18055439905: 满分200分求C语言编程,简单题 -
伏晓鹅掌: 第一题: #include "stdio.h" main() { int i,j,k; for(i=0;i...

伊春市18055439905: VC++编程题
伏晓鹅掌: 第一题: #include<iostream.h> #include<math.h> int isprime(int n); void main() { cout<<"1-100的所有素数是:"<<endl; for(int i=2;i<=100;i++) { if(isprime(i)==1) cout<<i<<endl; } } int isprime(int n) { for(int i=2;i<=sqrt(n);i++) if(n%i==0) return 0; ...

伊春市18055439905: 【C++]两个程序题看不懂 -
伏晓鹅掌: 第一题 改为可读点,解释 void f(int); void main( ){ f(257); } void f(int n){ //1、 257 大于 16 if(n>16){ f(n/16);// 递归了一下 //2、 257/16 = 16 ......1 则为 16(其实这样看计算规则的)进入f(16) //3、 cout } cout}//最终结果就是 输出 01第二题 void ...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网