C++ 新手编程=。=

来源:百度知道 编辑:UC知道 时间:2024/06/06 23:23:59
#include <iostream>
using namespace std;
class test{
int X;
public:
test(int a){X=a;
int GetX(){return X;}
};
void main(){
这行输入一条语句
test *p,a[2][3]={{1,2,3},{4,5,6}};
for ( 这里填入语句;i<=6,i++,p++){
if ((p-a[0])%3==0) cout<<endl;
cout<<p->GetX()<<" ";
}

如何完成程序,需要输入2条语句。
不明白P-a[0]是什么意思,P不是指针么?P的值应该是地址值吧?

程序就是为了把二维数组的所有元素打印出来,(p-a[0])%3==0的意思是每3个换行,p指向行数,填的的两句分别为:
int i;和i=1,p=a[i/3]
你的程序语法还有一些错无我帮你调了一下!~
你把它们导到工程里就能运行
#include <iostream>
using namespace std;
class test
{
int X;
public:
test(int a){X=a; }
int GetX(){return X;}
};

void main(){
//这行输入一条语句
int i;
test *p,a[2][3]={{1,2,3},{4,5,6}};
for (i=1,p=a[i/3];i<=6;i++,p++)
{
if ((p-a[0])%3==0) cout<<endl;
cout<<p->GetX()<<" ";
}
}

填什么语句取决于你的程序要完成什么样子的功能,而你没说
所以没法填

p是指针
a[0]是地址
p-a[0]就是指针的偏移量

void main()
{
    int i;
    test *p,a[2][3]={{1,2,3},{4,5,6}};
    for (p=a;i<=6,i++,p++)
    {
        if ((p-a[0])%3==0) cout<<endl;
    &n