Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW2 #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

HW2 #135

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions SuperPrime_HW2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Nature {
bool isPrime() {
if(num == 1 || num == 0)
return false;
for(int i = 2; i <= (int)sqrt(num); i++)
for(int i = 2; i <= (int)num; i++)
{
if(num % i == 0)
return false;
Expand All @@ -34,7 +34,10 @@ class Nature {

return -1;
}
private:
show()
{
std::cout<<num;
}
};
class SuperPrime : public Nature {
private:
Expand All @@ -46,6 +49,16 @@ class SuperPrime : public Nature {
Nature nat(num);
return nat.isPrime();
}
bool isSuperPrime()
{
Nature nat1(num);
Nature nat2((num/100)+((num%100)/10)+(num%10));
Nature nat3((num/100)*((num%100)/10)*(num%10));
Nature nat4((num/100)*(num/100)+((num%100)/10)*((num%100)/10)+(num%10)*(num%10));
if(nat1.isPrime()&&nat2.isPrime()&&nat3.isPrime()&&nat4.isPrime())
return true;
else return false;
}
int compare(const SuperPrime &nat) {
if (num > nat.num)
return 1;
Expand Down Expand Up @@ -73,8 +86,8 @@ class Container {
std::cout << "Destroy SuperPrime " << std::endl;
}

SuperPrime max() {
std::vector<SuperPrime>::iterate it = natures.begin();
Nature max() {
std::vector<SuperPrime>::iterator it = natures.begin();
Nature max(0);
for(; it != natures.end(); it ++) {
if (max.compare(*it)) {
Expand All @@ -85,9 +98,9 @@ class Container {
}
};
int main() {
SuperPrime sp(10, 13);
Container sp(100,999);
Nature n = sp.max();
std::cout << "��󳬼�������" ;
std::cout<<"最大:";
n.show();

return 0;
Expand Down