注册 登录
编程论坛 C++教室

声明一个一维数组对象

zxl20081024 发布于 2008-04-29 19:23, 2247 次点击
声明并实现一个类CArray表示一个一维数组对象。该对象具有的行为:(1)获得指定下标的数组元素;(2)设置指定下标的数组元素;(3)输出所有元素的值。(4)其他你认为具备的行为。
高手来帮忙做啊,我不会啊~~~
谢谢了,嘿嘿~~
11 回复
#2
newyj2008-04-29 21:10
新手不知道对不对
class CArray{
  public:
    CArray(const std::string& str){a[]=str;};
    CArray(const CArray& var){a[]=var.a;};
    ~CArray(){};
    void getstr()const{cout<<a;};
    int getvalue()const{return sizeof a/sizeof a[0];};
    const char getnumber(const int m)const{return a[m];};
  private:
    char a[];  
}
#3
sunkaidong2008-04-29 21:21
你看看string类吧
#4
newyj2008-04-29 21:27
那里不对能否指出来啊
谢谢了
#5
sunkaidong2008-04-29 21:29
我是让楼主看看..你的进步很快了..呵呵,不是说你
#6
newyj2008-04-29 21:54
写代码的时候总不是很自信
代码肯定有不足之处
不知道写的对不对
#7
sunkaidong2008-04-29 22:05
那就写写啊..呵呵,实在不行,看看java里面的数组模板也好...
#8
newyj2008-04-29 22:07
java里面的数组模板 不知道在C++里面有没有用
#9
sunkaidong2008-04-29 22:11
c++里面也有...
CArray Class Members
Construction

CArray Constructs an empty array.


Attributes

GetSize Gets the number of elements in this array.
GetUpperBound Returns the largest valid index.
SetSize Sets the number of elements to be contained in this array.


Operations

FreeExtra Frees all unused memory above the current upper bound.
RemoveAll Removes all the elements from this array.


Element Access

GetAt Returns the value at a given index.
SetAt Sets the value for a given index; array not allowed to grow.
ElementAt Returns a temporary reference to the element pointer within the array.
GetData Allows access to elements in the array. Can be NULL.


Growing the Array

SetAtGrow Sets the value for a given index; grows the array if necessary.
Add Adds an element to the end of the array; grows the array if necessary.
Append Appends another array to the array; grows the array if necessary
Copy Copies another array to the array; grows the array if necessary.


Insertion/Removal

InsertAt Inserts an element (or all the elements in another array) at a specified index.
RemoveAt Removes an element at a specific index.


Operators

operator [] Sets or gets the element at the specified index.


CArray Overview |  Base Class Members |  Hierarchy Chart
#10
newyj2008-04-29 22:14
不好意思 看不懂
#11
sunkaidong2008-04-29 22:29
也就是几个函数原形..都是msdn上的
#12
newyj2008-04-29 22:35
哦 需要看的东西还有很多
1