所以我需要用这些函数制作代码。 checkMatrix必须是布尔值,getData必须通过1D数组。如何使用2D数组检查魔方?说明:编写一个程序,提示用户整数填充3 x 3二维数组 构建一个表。一旦输入数据,程序就会检查 看表是否形成了一个魔方。完成后让程序提示用户查看 如果他们想测试另一个方格并相应地循环回来。注意:您的解决方案应该 验证错误输入的程序输入。这意味着您的程序检查 查看输入的数据是数字,包括1和9,不重复 可以输入数据。提示:一维数组可用于保持其中的计数 数字已分配给魔方。 节目风格= 程序必须包含以下用于执行给定操作的函数 说明。使用给定的函数名称。必须将所有数据传递给所需的数据 按价值或参考的功能;不允许全局变量。 功能描述= main =此功能解释魔方方向,组织来电 其他功能,并报告最终结果。 getData =此函数获取并验证用户输入的9位数字以进行填充 3 x 3表。必须实现数组数据的传递。 checkMatrix = 该函数传递给用户输入的数组数据矩阵 确定它是否是魔术方阵列并返回布尔值 测试结果。
#include <iostream>
#include <windows.h>
using namespace std;
int checkMatrix()
int getData(input[9] );
//prototypes
int main()
{
char repeat;
//declaration of variables
do
{
system("cls");
//clear screen between calculations
cout << "**********************************************************" << endl;
cout << "** CSC 175 Program #6 by Morgan Kelly **" << endl;
cout << "** **" << endl;
cout << "** Enter a magic square sequence by assigning a value **" << endl;
cout << "** from 1 to 9 to each location of a 3 by 3 table. **" << endl; **" << endl;
cout << "**********************************************************" << endl;
//header
getData(input[9]);
//call getData function
cout << "*************" << endl;
cout << "*" << input[0] << " " << input[1] << " " input [2] << "*" << endl;
cout << "*" << input[3] << " " << input[4] << " " input [5] << "*" << endl;
cout << "*" << input[6] << " " << input[7] << " " input [8] << "*" << endl;
cout << "*************" << endl;
if checkMatrix()= true
cout << "This is a magic square!" << endl;
else
cout << "This is not a magic square!" <<endl;
cout << "Want to check another table? (y/n): ";
cin >> repeat;
} while (repeat == 'y' or repeat == 'Y');
//repeat program and be able to calculate another table
return 0;
}
int getData(input[9])
{
int input[9];
//declaration of 1 dimensional array
while (input[9] >0 and input[9]<10)
{
cout << "Enter row 1 and column 1: ";
cin >> input[0];
cout << endl;
cout << "Enter row 1 and column 2: ";
cin >> input[1];
cout << endl;
cout << "Enter row 1 and column 3: ";
cin >> input[2];
cout << endl;
cout << "Enter row 2 and column 1: ";
cin >> input[3];
cout << endl;
cout << "Enter row 2 and column 2: ";
cin >> input[4];
cout << endl;
cout << "Enter row 2 and column 3: ";
cin >> input[5];
cout << endl;
cout << "Enter row 3 and column 1: ";
cin >> input[6];
cout << endl;
cout << "Enter row 3 and column 2: ";
cin >> input[7];
cout << endl;
cout << "Enter row 3 and column 3: ";
cin >> input[8];
cout << endl;
}
if cin.fail()
cin.clear();
cin.sync();
cout << "INVALID INPUT - ";
//validates for input(numbers) that are between 1 and 9 only
//input numbers from user and validate
return input[9];
}
bool checkMatrix()
{
if array1[]=array2[]
{return true;}
else
{return false;}
}