您的位置:首页 > 编程语言 > C语言/C++

新手,求找出错误!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 distance input c++ c