新手,求找出错误!C++
2012-03-26 01:17
330 查看
①定义一个Point结构体如下,用来表示显示屏上的点
struct Point
{
int x;
int y;
};
② 定义一个函数print,其返回值为void,只有一个引用参数,是对类型为Point的变量(点)的引用。该函数以(x,y)的形式,打印通过引用传递过来的点。
③ 定义一个带有默认实参的函数shiftDown,其返回值为void。它有两个参数,其中第二个参数带有默认实参。
参数1:引用参数,是对类型为Point的变量(点)的引用。
参数2: 整数y,表示将参数1引用的点向下移动的偏移量,
其默认实参为5。
④ 定义一个主函数如下。
int main()
{
structPoint p;
p.x= 10;
p.y= 19;
print(p); // 打印(10, 19);
shiftDown(p); // 省略默认实参,向下移动5.
print(p); // 打印(10, 24);
shiftDown(p,10); // 给定实参值,向下移动10.
print(p); // 打印(10, 34);
}
这是一个实验题目,我是刚学习C++。所以不会写,在此求助,希望帮我解决。谢谢!!!!
#include<iostream>
using namespace std;
struct point
{
int x;
int y;
};
void print(struct point*p);
void shiftDown(struct point*p,int n);
int main()
{
int a,b,n;
struct point*p;
cout<<"Plase input the coordinate(x, y)of the point:";
cin>>a>>b;
(*p).x = a;
(*p).y = b;
print(p);
shiftDown(p);
print(p);
cout<<"Plase input move distance:";
cin>>n;
shiftDown(p, n);
print(p);
}
void print(struct point*p)
{
int a,b;
a=(*p).x;
b=(*p).y;
cout<<"The point's coordinate is ("<<a<<", "<<b<<")"<<endl;
}
void shiftDown(struct point*p,int n=5)
{
int b,c;
b=(*p).y;
c=b+n;
(*p).y=c;
}
struct Point
{
int x;
int y;
};
② 定义一个函数print,其返回值为void,只有一个引用参数,是对类型为Point的变量(点)的引用。该函数以(x,y)的形式,打印通过引用传递过来的点。
③ 定义一个带有默认实参的函数shiftDown,其返回值为void。它有两个参数,其中第二个参数带有默认实参。
参数1:引用参数,是对类型为Point的变量(点)的引用。
参数2: 整数y,表示将参数1引用的点向下移动的偏移量,
其默认实参为5。
④ 定义一个主函数如下。
int main()
{
structPoint p;
p.x= 10;
p.y= 19;
print(p); // 打印(10, 19);
shiftDown(p); // 省略默认实参,向下移动5.
print(p); // 打印(10, 24);
shiftDown(p,10); // 给定实参值,向下移动10.
print(p); // 打印(10, 34);
}
这是一个实验题目,我是刚学习C++。所以不会写,在此求助,希望帮我解决。谢谢!!!!
#include<iostream>
using namespace std;
struct point
{
int x;
int y;
};
void print(struct point*p);
void shiftDown(struct point*p,int n);
int main()
{
int a,b,n;
struct point*p;
cout<<"Plase input the coordinate(x, y)of the point:";
cin>>a>>b;
(*p).x = a;
(*p).y = b;
print(p);
shiftDown(p);
print(p);
cout<<"Plase input move distance:";
cin>>n;
shiftDown(p, n);
print(p);
}
void print(struct point*p)
{
int a,b;
a=(*p).x;
b=(*p).y;
cout<<"The point's coordinate is ("<<a<<", "<<b<<")"<<endl;
}
void shiftDown(struct point*p,int n=5)
{
int b,c;
b=(*p).y;
c=b+n;
(*p).y=c;
}
相关文章推荐
- C/C++编程新手错误语录
- 经验汇编之C/C++编程新手错误语录
- C/C++编程新手错误语录(续二)
- C/C++编程新手错误语录(4)
- C/C++编程新手错误语录
- C++中新手容易范的错误
- C/C++编程新手错误语录
- c++新手容易犯的几个错误
- C++面试题之找出下面的所有错误
- C/C++编程新手错误语录
- C/C++编程新手错误语录(1)
- C/C++编程新手错误分析
- C/C++编程新手错误语录(2)
- C/C++编程新手错误语录
- C/C++编程新手错误分析
- C/C++编程新手错误语录(3)
- C/C++编程新手错误语录
- C/C++编程新手错误语录
- C/C++编程新手错误语录
- C/C++编程新手错误语录