您的位置:首页 > 其它

2016/10/25

2016-10-25 23:14 197 查看
1631-5 黄加勉 <2016.10.25> 【连续第24天总结】

A.今日任务
1.继承(100%)
2.隐藏(100%)

B.具体内容
1.在类的继承过程中,如果派生类定义了和基类名字一样的数据成员或成员函数,
 那么继承的基类的数据成员或成员函数就被隐藏
2.访问派生类成员函数直接调用即可,访问基类成员函数要加(基类名)::
3.隐藏的函数不可以和派生类函数重载
4.在网上看到了蛇形数组和‘之’字型数组,就试了一下:

附蛇形数组代码:

#include <iostream>

using namespace std;

#define x 20

void print(int arr[x][x])

{
int val = 0;
int a=0, b=x, c=0, d=x-2;
while(1)
{
for (int i = a; i < b; i++)
{
val++;
arr[a][i] = val;
}
for (int j = a + 1; j < b; j++)
{
val++;
arr[j][b - 1] = val;
}
for (int k = d; k >= c; k--)
{
val++;
arr[d + 1][k] = val;
}
for (int m = d; m > c; m--)
{
val++;
arr[m][c] = val;
}
if (a == x/2) break;
a++;
b--;
d--;
c++;

cout << "        ";
for (int i = 0; i < x; i++)
{
printf("%5d", i+1);
}
printf("\n");
cout << "        ";
for (int i = 0; i < x; i++)
{
printf("%5c", '|');
}
cout << endl << endl;
for (int i = 0; i < x; i++)
{
cout << i + 1 << "——"<<'\t';
for (int j = 0; j < x; j++)
{
printf("%5d", arr[i][j]);
}
cout << endl << endl;;
}

}

int main()

{
int arr[x][x];
print(arr);
system("pause");
return 0;

}

‘之’字型数组代码:

#include <iostream>

using namespace std;

#define x 10

void print();

int main()

{
print();
system("pause");
return 0;

}

void print()

{
int arr[x][x];
int val = 0;
for (int m = 0; m <= 2 * x - 1; m++)
{
int temp = 0;
if (m <= x - 1)
{
if (m % 2 == 1)
{
for (int j = m; j >= 0; j--)
{
val++;
arr[temp][j] = val;
temp++;
}
}
else
{
for (int j = m; j >= 0; j--)
{
val++;
arr[j][temp] = val;
temp++;
}
}
}
else if (m >= x)
{
int flag = m - x + 1;
if (m % 2 == 0)
{
for (int j = x - 1; j >= m - x + 1; j--)
{
val++;
arr[j][flag] = val;
flag++;
}
}
else
{
for (int j = x - 1; j >= m - x + 1; j--)
{
val++;
arr[flag][j] = val;
flag++;
}
}
}
}
for (int i = 0; i < x; i++)
{
for (int j = 0; j < x; j++)
{
if (arr[i][j] >= 0)
{
printf("%5d", arr[i][j]);
}
}
cout << endl << endl;
}

}

C.明日任务
1.isa
2.隐藏
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: