第18周报告2:二维数组(失败)


实验目的:学会二维数组的操作
实验内容:二维数组的操作

* 程序头部注释开始
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:                            
* 作    者:           董宝文               
* 完成日期:  2011 年 12 月 23 日
* 版 本 号:        

* 对任务及求解方法的描述部分
* 输入描述:由程序产生随机数作为初始值
* 问题描述:……
* 程序输出:……
* 程序头部的注释结束

#include  <iostream>
#include <time.h>
using namespace std;
void setdata(int a[8][8]);  //设置随机数
void out(int a[8][8]);  //输出数组
void outDiagonal(int a[8][8]);  //输出对角线元素的值
void mine(int a[8][8],int x, int y);  //按"扫雷"游戏的规则输出相邻格子
void change(int a[8][8]);     //按要求改变数值
int main()
{
 int a[8][8],x,y;
 setdata(a);
 out(a); 
 cout<<endl<<"输出对角线的数值"<<endl;
 outDiagonal(a);
 cout<<endl<<"输入一个位置:";
 cin>>x>>y;
 while(x < 0 || x > 7 || y < 0 || y > 7)
 {
  cout << "请重新输入"<<endl;
  cin>>x>>y;
 }
 mine(a,x,y);
 cout<<"改变后的数值"<<endl;
 change(a);
 out(a);
 cout<<endl;
 return 0;
}
void setdata(int a[8][8])
{
 int i,j;
 srand(time(NULL));//需要用当前时间作"种子",以便每次运行取得的序列不同
 for(i=0;i<8;i++)
  for(j=0;j<8;j++)
   a[i][j]=rand()P+1;
  return;
}
void out(int a[8][8])
{
 int n = 0;
 for(int i = 0; i <= 7; i++)
  for(int j = 0; j <= 7; j++)
  {
   if(n % 8 == 0)
   {
    cout<<endl;
    n = 0;
   }
   cout<<a[i][j]<<'\t';
   n++;
  }
  
}

void outDiagonal(int a[8][8])
{
 cout << "左上右下"<<endl;
 for(int i = 0; i <= 7; i++)
 {
  cout<<a[i][i]<<" ";
 }
 cout<<endl;
 cout<<"右上左下"<<endl;
 for(i = 0; i <= 7; i++)
 {
  cout<<a[i][7-i]<<" ";
  
 }
}
void mine(int array[8][8],int x, int y)
{
 int a,b,c,d,sum=0,m,n;
 if(x == 0 && y == 0)
 {
  a = x,b = y,c = x + 1,d = y + 1;
 }
 else if(x == 0 && y != 0)
 {
  a = x,b = y - 1,c = x + 1,d = y + 1;
 }
 else if(x == 0 && y == 7)
 {
  a = x,b = y - 1,c = x + 1,d = y;
 }
 else if(x != 0 && y == 7)
 {
  a= x - 1,b = y -1,c = x + 1,d = y;
 }
 else if(x == 7 && y == 7)
 {
  a = x - 1,b = y - 1,c = x,d = y;
 }
 else if(x == 7 && y != 7)
 {
  a = x - 1,b = y - 1,c = x,d = y + 1;
 }
 else if(x == 7 && y == 0)
 {
  a = x - 1,b = y,c = x,d = y + 1;
 }
 else if(x != 7 && y == 0)
 {
  a = x - 1,b = y,c = x + 1,d = y + 1;
 }
 else
 {
   a = x - 1,b = y - 1,c = x + 1,d = y + 1;
 }
 for(m = a; m <= c; m++)
  for(n = b; n <= d; n++)
  {
   if(m == x && n == y)
   {
    continue;
   }
   cout<<array[m][n]<<" ";
   sum = sum +array[m][n];
  }
  cout<<endl<<"sum="<<sum<<endl;
}
void change(int a[8][8])
{
 int i,j;
 for(i = 1; i <= 7; i++)
  for(j = 0; j <= 7; j++)
  {
   if(j == 7)
    a[i][j] = a[i - 1][j] + a[i - 1][0];
   else
    a[i][j] = a[i - 1][j] + a[i - 1][j + 1];
  }
}


 

第18周报告2:二维数组(三点失败版)

第18周报告2:二维数组(三点失败版) 

第18周报告2:二维数组(三点失败版)



经验积累:
三点失败版......还望阅读的朋友们不要当场凌乱,然后再很无奈的挤出一声:“你赢了...”........

其实刚输入中间的数成功以后我还是挺兴奋的....

上机感言:就像贺老师说的...这程序可以用更短的来处理...所以      再改吧....


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值