首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

点列表编译异常了

2012-03-24 
点列表编译错误了。求助//PointlList.hconstintmaxListSize10classPoint{public:Point(floatx00,floaty0

点列表编译错误了。求助
//PointlList.h
const   int   maxListSize=10;

class   Point
{
public:
Point(float   x0=0,float   y0=0)
{
x=x0;y=y0;
}
float   x,y;
};

class   PointList()
{
public:
PointList();

        void   append(Point   newPoint);
void   clear();
       
bool   isEmpty()   const;
bool   isFull()   const;
       
void   gotoBeginning();
void   gotoEnd();
bool   gotoNext;
bool   gotoPrior();
Point   getCursor()   const;

void   printPoint(Point   a);
void   showStructure()   const;

private:
int   size,cursor;//cursor   is   the   index   of   a   point   array
        Point   points[maxListSize];
};  
//PointList.cpp
#include <iostream>
#include   "PointList.h "

using   namespace   std;

PointList::PointList()
{
points[maxListSize];
cursor=null;
size=0;
}

void   PointList::append(Point   newPoint)
{
if(size <=maxListSize)
{
if(cursor==null)
{
points[0]=newPoint;
cursor=0;
}
                else   {        
points[cursor+1]=newPoint;
cursor++;
}
size++;
}else
cout < < "The   list   is   too   fullto   add   a   new   point. " < <endl;
}

void   PointList::clear()
{
int   i=0;
while(i=0;i <cursor+1;i++)
{
points[i].x=null;
points[i].y=null;
}
size=0;
curse=null;
}

bool   PointList::isEmpty()   const
{
return   size==0;
}

bool   PointList::isFull()   const
{
return   size==maxListSize;
}

void   PointList::gotoBeginning()
{
cursor=0;
}

void   PointList::gotoEnd()
{
cursor=size-1;
}

bool   PointList::gotoNext()
{
if((cursor!=size-1)&&(size!=0))
{
cursor=cursor++;
return   true;
}
else   return   false;
}

bool   PointList::gotoPrior()
{
if((cursor!=0)&&(size!=0))
{
cursor--;
return   true
}else   return   false;
}

Point   PointList::getCursor()   const
{
return   points[curse];
}

void   PointList::printPoint(Point   a)
{
cout < < "( " < <a.x < < ", " < <b.x < < ") " < <endl;
}

void   PointList::showStructure()   const
{
if(size==0)
cout < < "Empty   list. " < <endl;
else{
int   i=0;
while(i=0;i <size;i++)
{
printPoint(points[i]);
}
}
}

大致有三类错误:
1.PointList   is   not   a   class  
2.modifiers   are   not   allowed   on   nonemember   function
3.missing   ;   before{
都是莫名奇怪的错误。
谢谢大牛,不胜感激~

------解决方案--------------------


语法问题很多,


.h
----------

const int maxListSize = 10;

class Point
{
public:
Point(float x0=0,float y0=0)
{
x=x0;y=y0;
}
float x,y;
};

class PointList
{
public:
PointList();

void append(Point newPoint);
void clear();
bool isEmpty() const;
bool isFull() const;
void gotoBeginning();
void gotoEnd();
// function
bool gotoNext();
bool gotoPrior();
Point getCursor() const;
void printPoint(Point a);
// 修改了size的值,不能声明为cosnt函数
void showStructure();
private:
int size;
int cursor;//cursor is the index of a point array
Point points[maxListSize];
};


.cpp
---------------

#include <iostream>
using namespace std;

PointList::PointList()
{
points[maxListSize];
cursor= 0; //null也和NULL不同
size=0;
}

void PointList::append(Point newPoint)
{
if(size <= maxListSize)
{
if(cursor == 0)
{
points[0]=newPoint;
cursor=0;
}
else {
points[cursor+1]=newPoint;
cursor++;
}
size++;
}else
cout < < "The list is too fullto add a new point. " < <endl;
}

void PointList::clear()
{
int i=0;
// while ??
for(i = 0; i < cursor+1; i++)
{
points[i].x = 0;
points[i].y = 0;
}
size = 0;
cursor = 0;
}

bool PointList::isEmpty() const
{
return size==0;
}

bool PointList::isFull() const
{
return size==maxListSize;
}

void PointList::gotoBeginning()
{
cursor=0;
}

void PointList::gotoEnd()
{
cursor=size-1;
}

bool PointList::gotoNext()
{
if((cursor!=size-1)&&(size!=0))
{
cursor=cursor++;
return true;
}
else
return false;
}

bool PointList::gotoPrior()
{
if((cursor!=0)&&(size!=0))
{
cursor--;
// 少了;
return true;
}
else
return false;
}

Point PointList::getCursor() const
{
// curse?
return points[cursor];
}

void PointList::printPoint(Point a)
{
// b?
cout < < "( " < <a.x < < ", " < <a.y < < ") " < <endl;
}

void PointList::showStructure()
{
// modify size
if(size == 0)
cout < < "Empty list! " < <endl;
else
{
int i = 0;
// 看下while的用法
for(i = 0;i < size; i++)
{
printPoint(points[i]);
}
}
}

热点排行