100分!来吧...前几天20分没人回答????分数这么重要?

jinjunweiruan 2008-06-29 07:46:49
//:co4:CLib.cpp{0}
// Implementation of example C-like library
// Declare structure and functions:
#include "CLib.h"
#include <cstdlib>
#include <iostream>
#include <cassert>
using namespace std;
using namespace std;
//Quantity of elements to add
// when increasing storage:
const int increment=100;

void initialize(CStash* s,int sz){
s->size=sz;
s->quantity=0;
s->storage=0;
s->next=0;
}
int add(CStash* s,const void* element){
if(s->next >= s->quantity)//Enough space left?
inflate(s,increment);
//Copy element into storage,
// starting at next empty space:
int startBytes=s->next * s->size;
unsigned char* e=(unsigned char*)element;
for (int i=0;i <s->size;i++)
s->storage[starBytes +i]=e[i];
s->next++;
return (s->next-1);//Index number
}

void* fetch(CStash* s,int index) {
//Check index boundaries:
assert(0 <=index);
if(index >=s->next)
return 0;//To indicate the end
//Produce pointer to desired element:
return &(s->storage[index * s->size]);
}

int count(CStash* s){
return s->next; //Elements in increase){
assert(increase >0);
int newQuantity=s->quantity+increase;
int newBytes =newQuantity * s->size;
int oldBytes =s->quantity * s->size;
unsigned char* b=new unsigned char[newBytes];
for (int i=0;i <oldBytes;i++)
b[i]=s->storage[i];//Copy old new memory
s->storage=b; //Point to new memory
s->quantity=newQuantity;
}

void cleanup(CStash* s){
if(s->storage !=0){
cout < <"freeing storage" < <endl;
delete[]s->storage;
}
system("pause");
}///:~
我刚学VC++。。
谢谢!!
...全文
290 33 打赏 收藏 转发到动态 举报
写回复
用AI写文章
33 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinjunweiruan 2008-07-01
  • 打赏
  • 举报
回复
.....C++PRIMER订了,,,,估计明天就可以到了,我也是因为实在看不下去才买C++P的
想2本结合着看
谢谢大师门的批评。。。。接受.......(福贵的表情)..
fuqd273 2008-07-01
  • 打赏
  • 举报
回复
楼主把书寄我吧,你拿着那书浪费了。
fuqd273 2008-07-01
  • 打赏
  • 举报
回复
来拜13楼、21楼的
jieao111 2008-07-01
  • 打赏
  • 举报
回复
这样的话,问一辈子也学不好的。换书吧
donwmufromdying 2008-07-01
  • 打赏
  • 举报
回复
不用给分,路过!还真有这么耐心的
lidongri 2008-07-01
  • 打赏
  • 举报
回复
[Quote=引用 24 楼 jinjunweiruan 的回复:]
13L的,你说的不是很好,你这样我也会说,但是看你辛苦,还是给点,
...
[/Quote]
----
LZ,还是谦虚点吧。。。
taodm 2008-07-01
  • 打赏
  • 举报
回复
换本《C++ Primer》第四版好好打基础吧。
andy_cai 2008-07-01
  • 打赏
  • 举报
回复
[Quote=引用 25 楼 matrixdwy 的回复:]
LZ我不知道你是在什么情况下看着本书的,我说的已经很清楚了
如果你老老实实从第三章开始看,并且结合这个例子后面的说明
看,你应该就能够了解这个CStash到底在讲什么。
总之,在你没有学会走之前,就不要去跑。你还是补习一下前面
两章再说,或者你可以直接跳过这个例子,看后面的内容,可能
后面的内容有助于你理解这个例子。因为这个例子只是让你一窥
CStash的全貌,具体怎样BRUCE会在后面给你讲清楚。
[/Quote]
同意
看不懂的可以先放放
留待以后回过头来看
把全书先过一遍
matrixdwy 2008-07-01
  • 打赏
  • 举报
回复
LZ我不知道你是在什么情况下看着本书的,我说的已经很清楚了
如果你老老实实从第三章开始看,并且结合这个例子后面的说明
看,你应该就能够了解这个CStash到底在讲什么。
总之,在你没有学会走之前,就不要去跑。你还是补习一下前面
两章再说,或者你可以直接跳过这个例子,看后面的内容,可能
后面的内容有助于你理解这个例子。因为这个例子只是让你一窥
CStash的全貌,具体怎样BRUCE会在后面给你讲清楚。
jinjunweiruan 2008-07-01
  • 打赏
  • 举报
回复
13L的,你说的不是很好,你这样我也会说,但是看你辛苦,还是给点,
17L的,方法说对了,整体的有了个概念,谢谢
21L的,谢谢了%%%
不过还是有点模糊……汗....
过2天看看有没高手了
没的话结...
  • 打赏
  • 举报
回复
支持4楼的大哥!佩服大哥!~之前的那个拜师贴^_^
jinjunweiruan 2008-06-29
  • 打赏
  • 举报
回复
见百度没人回答就放到这里来了。
代码还是自己打的……%
郁闷%%解释下吧
jinjunweiruan 2008-06-29
  • 打赏
  • 举报
回复
对…………要解释...郁闷,那个百度的就是我发的……%…………大家解释西啊啊…………
每行都解释西啊
matrixdwy 2008-06-29
  • 打赏
  • 举报
回复
Thinking in c++里面的STASH?
LZ是不明白STASH的原理还是啥?
K行天下 2008-06-29
  • 打赏
  • 举报
回复
原来是要注释代码阿:

太乙 2008-06-29
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 xgywd 的回复:]
我估计楼主自己都不知道问题,百度里有一个和这个帖子一模一样的。21日发的帖
这是链接http://zhidao.baidu.com/question/56504851.html
[/Quote]

汗~~~~这也行???

楼主有啥不明白的,写出来啊,
“给堆代码,做去吧!”
让别人咋做?没要求!
五号智能 2008-06-29
  • 打赏
  • 举报
回复
我估计楼主自己都不知道问题,百度里有一个和这个帖子一模一样的。21日发的帖
这是链接http://zhidao.baidu.com/question/56504851.html
bysdy 2008-06-29
  • 打赏
  • 举报
回复
哇,好强大啊~~~
[Quote=引用 21 楼 matrixdwy 的回复:]
C/C++ code
#include "CLib.h"
#include <cstdlib>
#include <iostream>
#include <cassert>
using namespace std;

//Quantity of elements to add
// when increasing storage:
const int increment=100;

void initialize(CStash* s,int sz) //初始化函数,接受一个CStash结构体指针
{ //以及存放的数据的字节长度
s->size=sz; …
[/Quote]
oo 2008-06-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 dewdrop12 的回复:]
是啊?放一堆代码那里,也不说是什么问题,那别人怎么帮忙解决呢:)
[/Quote]
五号智能 2008-06-29
  • 打赏
  • 举报
回复

#include "CLib.h"
#include <cstdlib>
#include <iostream>
#include <cassert>
using namespace std;
using namespace std;

//Quantity of elements to add
// when increasing storage:
const int increment=100;

void initialize(CStash* s,int sz)
{
s->size=sz;
s->quantity=0;
s->storage=0;
s->next=0;
}
int add(CStash* s,const void* element)
{
if(s->next >= s->quantity)//Enough space left?
inflate(s,increment);
//Copy element into storage,
// starting at next empty space:
int startBytes=s->next * s->size;
unsigned char* e=(unsigned char*)element;

for (int i=0;i <s->size;i++)
s->storage[starBytes +i]=e[i];

s->next++;
return (s->next-1);//Index number
}

void* fetch(CStash* s,int index)
{
//Check index boundaries:
assert(0 <=index);
if(index >=s->next)
return 0;//To indicate the end
//Produce pointer to desired element:
return &(s->storage[index * s->size]);
}

int count(CStash* s)
{
return s->next; //Elements in increase){
assert(increase >0);
int newQuantity=s->quantity+increase;
int newBytes =newQuantity * s->size;
int oldBytes =s->quantity * s->size;
unsigned char* b=new unsigned char[newBytes];
for (int i=0;i <oldBytes;i++)
b[i]=s->storage[i];//Copy old new memory
s->storage=b; //Point to new memory
s->quantity=newQuantity;
}

void cleanup(CStash* s)
{
if (s->storage !=0)
{
cout < <"freeing storage" < <endl;
delete[]s->storage;
}

system("pause");
}
加载更多回复(13)

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧