| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1136 人关注过本帖
标题:[求助]实验程序,十万火急
只看楼主 加入收藏
dsrh
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2004-12-13
收藏
 问题点数:0 回复次数:4 
[求助]实验程序,十万火急

我的qq:282539062

请教实验程序,周四前要交

实验一 使用数组

问题描述

根据老师给出的ArraySeqList基于模板的类的说明,编写主程序使用该抽象类。

实验目的

熟悉C++语言的基本编程,学习并理解模板类,掌握集成编译环境的基本使用。

基本要求

1 读懂给出的ArraySeqList抽象类。

2 编写主程序生成SeqList类的实例数组。

3 编写程序使用SeqList的各个成员函数,完成下述功能。

测试数据

1 向空表中依次添加数据12345678910,打印表中数据。

2 删除第36个数据,打印表中数据。

3 在第3和第6个位置后分别添加数据1112,打印表中数据。

4 在表中搜索值为713的数据,并打印该数据在表中的下标。

5 从表尾向表头方向依次删除数据,每删除一个数据打印一次表中数据,直到表空为止。

选作内容

以上的每一步都使用调试器跟踪正在处理的数据所处的内存地址,加深对数组和内存的相关关系的理解。


实验二 链表

问题描述

设计一个一元稀疏矩阵多项式简单计算器。(提示:用带表头节点的单链表存储多项式,多项式的项数存放在头节点。)

实验目的

掌握链表的使用(重点掌握指针的使用)。

基本要求

一元稀疏多项式简单计算器的基本功能是:

(1) 输入并建立多项式;

(2) 输出多项式,输出形式为整数序列:n,c1,e1,c2,e2,…,cn,en,其中n是多项式的项数,ciei分别是第i项的系数和指数,序列按指数降序排列;

(3) 多项式ab相加,建立多项式a+b

(4) 多项式ab相减,建立多项式a-b;

测试数据:

1(2x+5x3-3.1x11) + (7-5x8+11x9) = (-3.1x11+11x9+2x+7)

2(6x-3-x+4.4x2-1.2x9) – (-6x-3+5.4x2-x2+7.8x15) = (-7.8x15-1.2x9+12x-3-x)

3(1+x+x2+x3+x4+x5) + (-x3-x4) = (1+x+x2+x3)

4(x+x3) + (-x-x3) = 0

5(x+x100) + (x100+x200) = (x+2x100+x200)

6(x+x2+x3) + 0 = (x+x2+x3)

7)互换以上各组数据中的前后两个多项式

选作内容

(1) 计算多项式在x处的值

(2) 求多项式a的导数

(3) 多项式相乘


实验三 树(哈夫曼编/译码器)

问题描述

利用哈夫曼编码进行通信可以大大提高信道利用率,缩短信息传输时间,降低传输成本。但是,这要求在发送端通过一个编码系统对待传数据预先编码,在接收端将传来的数据进行译码。对于双工信道(即可以双向传输信息的信道),每端都需要一个完整的编/译码系统。试为这样的信息收发站写一个哈夫曼码的编/译码系统。

基本要求

一个完整的系统应具有以下功能:

1I:初始化(Initialization)。从终端读入字符集大小n,以及n个字符和n个权值,建立哈夫曼树,并将它存于文件hfmTree中。

2E:编码(Encoding)。利用已经建好的哈夫曼树(如不在内存,则从文件hfmTree中读入),对文件ToBeTran中的正文进行编码,然后将结果存入文件CodeFile中。

3D:译码(Decoding)。利用已经建好的哈夫曼树将文件CodeFile中的代码进行译码,结果存入文件TextFile中。

4P:打印代码文件(Print)。将文件CodeFile以紧凑格式显示在终端上,每行50个代码。同时将此字符形式的编码文件写入文件CodePrint中。

5T:显示哈夫曼树(Treeprinting)。将已经在内存中的哈夫曼树以直观的方式(树或凹入表形式)显示在终端上,同时将此字符形式的哈夫曼树写入文件TreePrint中。

测试数据

用下表给出的字符集和频度的实际统计数据建立哈夫曼树,并实现以下报文的编码和译码:“I LOVE DATA STRUCTURE, I LOVE PROGRAMING"

字符

A B C D E F G H I J K L M

频度

186 64 13 22 32 103 2l 15 47 57 1 5 32 20

字符

N O P Q R S T U V W X Y Z

频度

57 63 15 1 48 5l 80 23 8 18 1 16 l

实现提示

1)用户界面可以设计为“菜单”方式:显示上述功能符号,再加上“Q”选项,表示退出(Quit)。用户可以键入一个选择功能符。此功能执行完毕后再显示此菜单,直至某次用户选择了“Q”为止。

2)在程序的一次执行过程中,第一次执行IDC命令之后,哈夫曼树已经在内存了,不必再读入。每次执行中不一定执行I命令,因为文件hfmTree可能早已建好。

搜索更多相关主题的帖子: 实验程序 quot FONT Roman 
2004-12-13 23:11
wmbdwmb
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2004-12-13
收藏
得分:0 
你们老师给的类在哪????

我很笨,但我很坚韧
2004-12-14 13:28
dsrh
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2004-12-13
收藏
得分:0 
我把类发上去

我把老师给的类发上去了,我能和你连qq吗,我们周四就要呀


2004-12-14 23:27
dsrh
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2004-12-13
收藏
得分:0 
我把类发给你

array:

#include <iostream.h> #include <stdlib.h>

#define DefaultSize 10 template < class Type> class Array { public: Array( int Size = DefaultSize ); Array( const Array <Type> &x ); ~Array() { destroy(); } Array<Type> &operator = ( const Array<Type> &A); Type & operator [] ( int i ); // Array<Type> operator Type * ()const { return elements; } int Length() const { return ArraySize; } void ReSize ( int sz); friend ostream& operator <<(ostream& , Array<Type>&); // void Print(); private: Type *elements; int ArraySize; void getArray(); void destroy(){delete[] elements;}; void copyFrom(const Array<Type> &x); } template <class Type> void Array<Type>::copyFrom(const Array<Type> &x) { int n= x.ArraySize; ArraySize=n; elements = new Type[x.ArraySize];

if ( elements == 0 ) { cerr << "Memory Allocation Error" << endl; ArraySize=0; return; } Type *srcptr = x.elements; Type *destptr = elements; while (n--) *destptr++ = * srcptr++ ; };

template <class Type> void Array<Type>::getArray() { elements = new Type[ArraySize]; if ( elements == 0 ) { cerr << "Memory Allocation Error" << endl; ArraySize=0; } }

template <class Type> void Array<Type>::Array (int sz) { if ( sz <= 0 ) { cerr << "Invalid Array Size" << endl; return; } ArraySize = sz; getArray(); }

template <class Type> void Array<Type>::Array ( const Array<Type> &x ) { copyFrom(x); }

template <class Type> Type& Array<Type>::operator[] (int i) { if ( i < 0 || i > ArraySize - 1 ) cerr << "Index out of Range" << endl; return elements[i]; }

template <class Type> void Array<Type>::ReSize( int sz ) {

if (( sz <= ArraySize )&&(sz>=0)) { Type *newarray = new Type[sz]; if (newarray == 0) { cerr << "Memory Allocation Error" << endl; return; } int n = ( sz <= ArraySize ) ? sz : ArraySize; Type *srcptr = elements; Type *destptr = newarray; while (n--) *destptr++ = *srcptr++ ; delete[] elements; elements = newarray; ArraySize = sz; } } template <class Type> Array<Type> & Array<Type>::operator = ( const Array<Type> &a) { destroy(); copyFrom(a); return *this; } template <class Type> ostream& operator <<(ostream& strm, Array<Type>& a) { Type *p=a.elements; strm<<"Len:"<<a.ArraySize<<endl; for (int i=0;i<a.ArraySize;i++,p++) { strm<<*p<<' '; } strm<<endl; return strm; } /* template <class Type> void Array<Type>::Print() { Type *p=elements; cout<<"Len:"<<ArraySize<<endl; for (int i=0;i<ArraySize;i++,p++) { cout<<*p<<' '; } cout<<endl; } */

seqlist:

#include <stdio.h> #include <assert.h> #define DefaultSize 100

template <class Type> class SeqList {

public: SeqList ( const int size = DefaultSize ); ~SeqList() { delete[] data; } int Length() const { return last + 1; } int Find( const Type & x ) const; int IsIn ( Type & x); int Insert ( Type & x, int i ); int Remove ( Type & x); int Next ( Type & x ); int Prior ( Type & x ); int IsEmpty()const { return last == -1; } int IsFull() const { return last == MaxSize - 1; } Type Get( int i ) { return i < 0 || i > last ? NULL:data[i]; } void Print(); private: Type *data; int MaxSize; int last; };

template < class Type > SeqList <Type>::SeqList( const int size ) { assert ( size >= 0 ); if ( size > 0 ) { MaxSize = size; last = -1; data = new Type[MaxSize]; } };

template < class Type > int SeqList <Type>::Find(const Type & x ) const { int i = 0; while ( i <= last && data[i] != x ) i++; if ( i > last ) return -1; else return i; }

template < class Type > int SeqList <Type>::IsIn( Type & x ) { int i = 0, found = 0; while ( i <= last && !found) if ( data[i] != x ) i++; else found = 1; return found; }

template < class Type > int SeqList <Type>::Insert( Type & x, int i ) { if ( i < 0 || i > last+1 || last == MaxSize - 1 ) return 0; else { last++; for ( int j = last; j > i; j-- ) data[j] = data[j-1]; data[i] = x; return 1; } }

template < class Type > int SeqList <Type>::Remove( Type & x ) { int i = Find(x); if ( i >= 0 ) { last--; for ( int j = i; j <= last; j++ ) data[j] = data[j+1]; return 1; } return 0; }

template < class Type > int SeqList <Type>::Next( Type & x ) { int i = Find(x); if ( i >= 0 && i < last ) return i+1; else return -1; }

template < class Type > int SeqList <Type>::Prior( Type & x ) { int i = Find(x); if ( i > 0 && i <= last ) return i-1; else return -1; }

template < class Type > void Union( SeqList <Type> & LA, SeqList <Type> & LB ) { int n = LA.Length(); int m = LB.Length(); for ( int i=0; i <= m; i++ ) { Type x = LB.Get(i); int k = LA.Find(x); if ( k == -1 ) { LA.Insert( x, n ); n++;} } }

template < class Type > void Intersection ( SeqList <Type> & LA, SeqList <Type> & LB ) { int n = LA.Length(); int m = LB.Length(); int i = 0; while ( i < n ) { Type x = LA.Get(i); int k = LB.Find(x); if ( k == -1 ) { LA.Remove(x); n--; } else i++; } }

template < class Type > void SeqList <Type>::Print() { if ( last == -1 ) cout << "It is empty" ; else for ( int i=0; i<=last; cout << " data[" << i++ << "] = " << data[i] ); cout << endl; }


2004-12-14 23:33
生姜
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2005-4-5
收藏
得分:0 
我的QQ:278674568

我可以给你答案!
2005-04-06 22:11
快速回复:[求助]实验程序,十万火急
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016123 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved