最新回答 / 么么哒的张先森
同学你好,我复制你的代码并运行了一下:发现了你所说的错误:(第二个)c->show()并没有按照期望打印出学号和班级名称,而是打印出了公民类的姓名、性别、年龄。事实上,c两次都是调用的公民类的show函数。<...图片...><...图片...>
2015-12-28
#include <iostream>
#include <stdlib.h>
using namespace std;
namespace myNum{ int x = 105; }
int main(){
bool isFlag = ture;
if(myNum::x % 2 == 0){
isFlag = false; }
else{
isFlag = ture; }
if(isFlag == 1){
cout <<"变量x是奇数"<<endl;}
else{
cout <<"变量x是偶数"<<endl;}
return 0;
}
#include <stdlib.h>
using namespace std;
namespace myNum{ int x = 105; }
int main(){
bool isFlag = ture;
if(myNum::x % 2 == 0){
isFlag = false; }
else{
isFlag = ture; }
if(isFlag == 1){
cout <<"变量x是奇数"<<endl;}
else{
cout <<"变量x是偶数"<<endl;}
return 0;
}
#include<stdlib.h>
#include<iostream>
namespace myNum
{
int x = 105;
}
using namespace myNum;
using namespace std;
int main()
{
if (x % 2 == 0)
{
cout << "偶数" << endl;
}
else
{
cout << "奇数" << endl;
}
return 0;
}
#include<iostream>
namespace myNum
{
int x = 105;
}
using namespace myNum;
using namespace std;
int main()
{
if (x % 2 == 0)
{
cout << "偶数" << endl;
}
else
{
cout << "奇数" << endl;
}
return 0;
}