# include & lt; Iostream>
Using namespace STD.
The class NumPrint
{
Public:
NumPrint (int t=0) : tt (t) {};
Void printNum ();
Int getCompositeNum (int pmax);//to get qualified number
Void reversePrintNum ();
Private:
vector
Int tt;
};
Void NumPrint: : reversePrintNum ()
{the for (int I=(a.s considering () - 1; I>=0; I -)
cout
Void NumPrint: : printNum () {
for(int i=0; I<(a.s considering ()); I++)
cout
{int NumPrint: : getCompositeNum (int pmax)
Int number=6;
Int n=1;
int sum=0;
While (number<={pmax)
While (n & lt;=(number/2)) {
If (number % n==0) {
The sum +=n;
}
N++;
}
If (sum==number) {
Amy polumbo ush_back (number);
}
Number++;
Sum=0;
N=1;
}
return 0;
}
The class NewNumPrint: public NumPrint
{
Public:
NewNumPrint ();
Void printNum ();
};
NewNumPrint: : NewNumPrint () {
}
Void NewNumPrint: : printNum () {
This - & gt; GetCompositeNum (1000);
}
Int main (int arg c, char * argv [])
{
int a;
cin> a;
NumPrint X;
X.g etCompositeNum (a);
X.p rintNum ();
cout
return 0;
}
It can be normal output, but the teacher out the final X.r eversePrintNum (); Replaced by reversePrintNum (X), compile error,
[Error] 'reversePrintNum' was not declared in this scope, could you tell me how to solve
CodePudding user response:
ReversePrintNum (X) is to want to call a class member function, need to write outside the classCodePudding user response:
The teacher is want you to design classes, to carry on the division of duties,Assuming that two classes,
One is a Data type, dedicated to store Data,
One is NumPrint classes, from the name, he is only responsible for printing, he himself should not contain data,
Data object to NumPrint object,, NumPrint is responsible for the printing like this?
-- -- -- -- -- -- -- -- -- -- -- -- but the problem is, if he doesn't know the details of the Data object Data, how does he know what is positive, how is the reverse,
==========="
So this scene, need your teacher give you a clear requirements, what to do?
You clear what you said when the teacher assigned homework requirements?
=====
To consolidate what knowledge? The class? A function call? Polymorphism?